I need to know the current date to query CloudKit data with it, like:
let predicate = NSPredicate(format: "publishedAt <= %@", currentDateAndTime)
I don't need high precision, even +/- a few minutes is fine, but I can't rely on device's time since the user can manually change it.
Researching this myself I see that the most reliable method is to get the date from the server.
There are NTP servers, but accessing them requires additional libraries which adds complexity. TrueTime (last updated 6 years ago) and Kronos (updated like once a year) seem outdated, given how much Swift has changed in the past years.
I can make an HTTP request to a website like Google or Apple and read the current time from its headers. But I don't know if this method is reliable.
I know I can create a dummy record in CloudKit, update it, and read its modificationDate. But it feels hacky.
Maybe there is another way to fetch the current date directly from CloudKit?
It feels like it should be easy and there is a straightforward solution, but I just can't find it.
Post
Replies
Boosts
Views
Activity
Hi,
I've been using Core Data + CloudKit via NSPersistentCloudKitContainer for several years now. Back then I just created my Core Data AND CloudKit fields by hand.
Now the time has come for a little lightweight migration to a new Core Data model, let's say I just needed to add one String attribute.
So I've done the Core Data local migration as usual, then added this to container code:
try? persistentContainer.initializeCloudKitSchema(options: NSPersistentCloudKitContainerSchemaInitializationOptions())
Run. And everything worked great. but…
Now I've noticed that CloudKit created new CKAsset fields for each String attribute that I had in Core Data (about 5 new CKAsset fields). Is this normal!? Why?
! Is it safe to deploy these changes to prod?
ty.
ChatGPT said: "This field is used internally by CloudKit to handle large string values. If the string value is small enough, it is stored in the normal String field, but if it exceeds the size limit (about 1KB), the string is automatically stored as a CKAsset."
In my iPad app, I have a view that is displayed in .fullScreenCover. And while it's a pretty basic view (a few stacks, some SF Symbols, and long text), the scrolling is sometimes laggy. Like I can see the stutter on my iPad Pro.
Since it's WWDC, maybe someone can point me to a tutorial, or the tool, or the steps I can take to tackle this laggy scrolling?
Or maybe .fullScreenCovers aren't supposed to be long and be scrolled?
Thanks in advance!
When using PencilKit and the default PKCanvasView, we get a pop-up menu with options like 'Select All | Insert Space' when we long tap on the canvas.
What is the proper way to remove this menu completely?
Thank you for your help.
For a bit of context, I store binary files of about 50KB in my Core Data. I noticed that enabling the "Allows External Storage" option doesn't seem to make any difference.
Additionally, how does this setting work with CloudKit when using NSPersistentCloudKitContainer?
Does this setting affect how the data is loaded into memory when accessed in Core Data in the app?
Thank you very much!
How can I keep the fetchLimit constant even when new data is inserted?
To replicate this, you can create a new Project in Xcode and check "Use Core Data". I use this code to apply fetchLimit:
struct MyView: View {
@FetchRequest private var items: FetchedResults<Item>
init() {
let request: NSFetchRequest<Item> = Item.fetchRequest()
request.fetchLimit = 3
_items = FetchRequest(fetchRequest: request)
}
This code works. For example I have 10 Items and when I open the app - only 3 are displayed! But when I add a new Item on the fly - @FetchRequest just adds it to the View and now it displays 4 Items!?
How can I make @FetchRequest keep updating the View reactively, but respect the fetchLimit to always show the latest 3 Items only?