Liss is More feed 2024年10月23日
A Weird CloudKit Issue
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Callsheet是一款类似于IMDB的应用程序,允许用户创建多个收藏列表。作者在开发多列表功能时遇到了CloudKit索引问题,导致无法正确查询收藏项目。作者详细描述了问题出现的原因,并分析了问题产生的根源,最终通过删除现有数据并重新添加解决了问题。文章提醒开发者在使用CloudKit添加索引时,需要确保在添加索引之前,已经添加了需要索引的数据。

👨‍💻 在开发Callsheet的多列表功能时,作者添加了新的记录类型FavoriteList和一个新的字段,用于存储收藏项目的父列表。

🤔 然而,在添加索引后,作者发现无法通过代码查询到特定列表的收藏项目,尽管在CloudKit Developer Dashboard中可以正常查看数据。

💡 通过与其他开发者的交流,作者发现问题可能在于索引没有正确地索引现有数据。

🆘 最终,作者通过删除现有数据并重新添加解决了问题,并建议开发者在使用CloudKit添加索引时,确保在添加索引之前已经添加了需要索引的数据。

⚠️ 作者在文章末尾还提到了Apple的反馈编号FB15563372,希望Apple能够对此问题进行修复。

Callsheet — my app that’s like IMDB but for people with taste —uses iCloud for several things, notably, storing your “pinned items”. Internally,I call pinned items “favorites”, so in this post I’ll refer to them interchangably.Regardless, today, there’s only one list of pinned items.

My most-requested feature is to add support for multiple lists. Generally, sopeople can have things like To Watch, Watching, and Did Watch. Naturally,your particular needs may differ, but this request is common… and constant.

Due mostly to life obligations (all is well), but also my fear of how much workthis will be, I’ve been kicking this can down the road for a while now. (Seealso: compliance to Swift 6’s strict concurrency). This week, I’vestarted to really dig in.

Today I hit a wall, and I’m too tired and exasperated to do a long and involvedwrite-up with pictures and stuff. The short-short version is:

Make sure you add indexes before adding data that you need to query thatrelies on those indexes; if you don’t, they may not work as expected.

When tackling multiple lists of pins, the first thing I did was to add anew record type (“table”, sorta-kinda) called FavoriteList, which is peerto the pre-existing Favorite. Then I added a new field (“column”,sorta-kinda) to Favorite that contains a CKRecord.Referenceto the favorite/pin’s parent list.

Once I got the schema updated in development, I started writing code. Thanksto some genuinely (and uncharacteristically for Apple) helpful sample code,I was able to put something together quickly. However, it didn’t work. Thanksto some genuinely (and uncharacteristically for Apple) helpful error messaging,I quickly realized I needed to add an index to Favorite; specifically forthis new reference field I added.

I added the compulsory indexes, and then went back to writing code.

Quickly, I was flummoxed; things still weren’t working. Now, for a differentreason: in trying to get favorites that are part of a given list, I was comingup short. No matter what I tried, no records were being returned. When I lookedat the records in the iCloud Developer Dashboard, it appeared everything wasgood. I could click from the field in Favorite and it would load the listin FavoriteList. But whenever I tried to query using my code, it wouldn’twork. I would come up with no records.

In chatting with some incredibly kind folks on Slack, one of them asked meto try to replicate the query I was doing in code on the Developer Dashboard.I got the same empty results. This was a critical tip, because it led me tobelieve that my own code was not — for once — the issue.

After a couple hours of this, and in desperation, I deleted all my existingFavorite and added new ones. I tried my queries again, and they worked nosweat. Both on the dashboard and in my code.

Thinking about this some more, and in chatting with the good samaritans onSlack, we all came to the same conclusion: the index probably didn’t properly…uh… index… whatever data was already there before the index was created.

So, if you’re ever in a situation where you’re getting wonky results (or noresults at all) from a new field in CloudKit, consider whether the data you’veadded was done so before or after you added the corresponding index.

Apple folks, FB15563372.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Callsheet CloudKit 索引 数据库 开发
相关文章