I use the screen size for some SwiftUI view layouts to adapt to various screen sizes. I have found that for some devices, such as the iPhone 13 mini, the screen size returned from UIScreen.main.bounds differs from the preview device and the simulator. Is this expected behavior?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am trying to setup my CloudKit schema from CoreData using the NSPersistentCloudKitContainer but getting an error when calling
try container.initializeCloudKitSchema()
The error:
Error Domain=NSCocoaErrorDomain Code=134060 "A Core Data error occurred." UserInfo={encounteredErrors=(
"Error Domain=NSCocoaErrorDomain Code=134406 \"Request '07443E71-32AC-4E63-A163-AAF940FE1AD6' was aborted because the mirroring delegate never successfully initialized due to error: <CKError 0x60000078b9c0: \"Missing Entitlement\" (8); \"Trying to initialize a container without an application ID\">\" UserInfo={NSLocalizedFailureReason=Request '07443E71-32AC-4E63-A163-AAF940FE1AD6' was aborted because the mirroring delegate never successfully initialized due to error: <CKError 0x60000078b9c0: \"Missing Entitlement\" (8); \"Trying to initialize a container without an application ID\">}"
)}
My container is iCloud.<my bundle id>, and is reflected in the Entitlement file.
I'm working on implementing file moving with NSFileCoordinator. I'm using the slightly newer asynchronous API with the NSFileAccessIntents. My question is, how do I go about notifying the coordinator about the item move? Should I simply create a new instance in the asynchronous block? Or does it need to be the same coordinator instance?
let writeQueue = OperationQueue()
public func saveAndMove(data: String, to newURL: URL) {
let oldURL = presentedItemURL!
let sourceIntent = NSFileAccessIntent.writingIntent(with: oldURL, options: .forMoving)
let destinationIntent = NSFileAccessIntent.writingIntent(with: newURL, options: .forReplacing)
let coordinator = NSFileCoordinator()
coordinator.coordinate(with: [sourceIntent, destinationIntent], queue: writeQueue) { error in
if let error {
return
}
do {
// ERROR: Can't access NSFileCoordinator because it is not Sendable (Swift 6)
coordinator.item(at: oldURL, willMoveTo: newURL)
try FileManager.default.moveItem(at: oldURL, to: newURL)
coordinator.item(at: oldURL, didMoveTo: newURL)
} catch {
print("Failed to move to \(newURL)")
}
}
}
Topic:
App & System Services
SubTopic:
Processes & Concurrency
Tags:
Files and Storage
Swift
iCloud Drive
Concurrency
Testing Environment: iOS 18.4.1 / macOS 15.4.1
I am working on an iOS project that aims to utilize the user's iCloud Drive documents directory to save a specific directory-based file structure. Essentially, the app would create a root directory where the user chooses in iCloud Drive, then it would populate user generated files in various levels of nested directories.
I have been attempting to use NSMetadataQuery with various predicates and search scopes but haven't been able to get it to directly monitor changes to files or directories that are not in the root directory.
Instead, it only monitors files or directories in the root directory, and any changes in a subdirectory are considered an update to the direct children of the root directory.
Example
iCloud Drive Documents (Not app's ubiquity container)
User Created Root Directory (Being monitored)
File A
Directory A
File B
An insertion or deletion within Directory A would only return a notification with userInfo containing data for NSMetadataQueryUpdateChangedItemsKey relating to Directory A, and not the file or directory itself that was inserted or deleted. (Query results array also only contain the direct children.)
I have tried all combinations of these search scopes and predicates with no luck:
query.searchScopes = [
rootDirectoryURL,
NSMetadataQueryUbiquitousDocumentsScope,
NSMetadataQueryAccessibleUbiquitousExternalDocumentsScope,
]
NSPredicate(value: true)
NSPredicate(format: "%K LIKE '*.md'", NSMetadataItemFSNameKey)
NSPredicate(format: "%K BEGINSWITH %@", NSMetadataItemPathKey, url.path(percentEncoded: false))
I do see these warnings in the console upon starting my query:
[CRIT] UNREACHABLE: failed to get container URL for com.apple.CloudDocs
[ERROR] couldn't fetch remote operation IDs: NSError: Cocoa 257 "The file couldn’t be opened because you don’t have permission to view it."
"Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)""
But I am not sure what to make of that, since it does act normally for finding updates in the root directory.
Hopefully this isn't a limitation of the API, as the only alternative I could think of would be to have multiple queries running for each nested directory that I needed updates for.
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags:
Files and Storage
iCloud Drive
Foundation