Post

Replies

Boosts

Views

Activity

CNSaveRequest.addMember(_:to:) CNContactStore.execute(_:) The operation couldn’t be completed. (CNErrorDomain error 2.)
I am getting an error adding a contact to a group. I wonder if there are restrictions I am overlooking. Does the contact have to be in the container that the group belongs to? Can the contact be a member of more than one group or more than one container?How do I figure out what the error means? The documentation for CNErrorDomain doesn't give any details. Isn't there a resource that tells me what error 2 means for CNErrorDomain?Here is my code: let saveRequest = CNSaveRequest() saveRequest.addMember(contact, from: utiGroup.cnGroup) do { try contactStore.execute(saveRequest) } catch { print("!!!!! Warning\n", error.localizedDescription) }Here is the output in the debug window: !!!!! Warning The operation couldn’t be completed. (CNErrorDomain error 2.)
0
0
347
Apr ’20
Why are not all records being saved in a CKModifyRecordsOperation to save in CloudKit in iOS?
I have this code that saves records into CloudKit in iOS in an iPhone 8 Simulator, but not all records are there when I check the database after the save code succeeds in saving 688 records whether 'maxNumberOfRecordsToModify' equal 50 or 400. I am sure I did everything correctly. let privateDatabase = CKContainer.default().privateCloudDatabase let maxNumberOfRecordsToModify = 400 func save(_ records: [CKRecord]) { if iCloudAvailable() { if records.count > maxNumberOfRecordsToModify { let sliceOfRecords = Array(records[0 ..< maxNumberOfRecordsToModify]) let leftOverRecords = Array(records[maxNumberOfRecordsToModify ... records.count - 1]) let operation = CKModifyRecordsOperation(recordsToSave: sliceOfRecords, recordIDsToDelete: nil) operation.savePolicy = CKModifyRecordsOperation.RecordSavePolicy.allKeys operation.qualityOfService = QualityOfService.userInitiated operation.modifyRecordsCompletionBlock = { savedRecords, deletedRecordIDs, error in if error == nil { print("Batch saved records!") save(leftOverRecords) } else { if let err = error as? CKError, let time = err.retryAfterSeconds { print(err) DispatchQueue.main.asyncAfter(deadline: .now() + time) { save(sliceOfRecords) } } else { print(error!) } } } privateDatabase.add(operation) } else { let operation = CKModifyRecordsOperation(recordsToSave: records, recordIDsToDelete: nil) operation.savePolicy = CKModifyRecordsOperation.RecordSavePolicy.allKeys operation.qualityOfService = QualityOfService.userInitiated operation.modifyRecordsCompletionBlock = { savedRecords, deletedRecordIDs, error in if error == nil { print("Batch saved records!") printNumberOfRecords() } else { if let err = error as? CKError, let time = err.retryAfterSeconds { print(err) DispatchQueue.main.asyncAfter(deadline: .now() + time) { save(records) } } else { print(error!) } } } privateDatabase.add(operation) } } } func printNumberOfRecords() { let predicate = NSPredicate(value: true) let query = CKQuery(recordType: DatabaseNameStrings.recordTypeAffirmation, predicate: predicate) privateDatabase.perform(query, inZoneWith: nil) { (records: [CKRecord]?, error: Error?) in if error != nil { print(error as Any) } else { if let records = records { print("Number of records in CloudKit=", records.count) } } } }Here is the debug window output: Batch saved records! Batch saved records! Number of records in CloudKit= 32
12
0
1.6k
Apr ’20
NSCoding error messages using NSKeyedUnarchiver.unarchivedObject(ofClass:from:)
I get a code-time yellow warning message in Xcode that says:'unarchiveObject(with:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error: instead... when I use the following code:let oldUbiquityIdentityToken = NSKeyedUnarchiver .unarchiveObject(with: oldDataUbiquityIdentityToken!)When I change to unarchivedObject(ofClass:from:) I get 2 code-time red error messages before I even fill in the arguments:'NSCoding' cannot be used as a type conforming to protocol 'NSCoding' because 'NSCoding' has static requirementsStatic method 'unarchivedObject(ofClass:from:)' requires that 'NSCoding' inherit from 'NSObject'Here is the code afterwards before I fill in the parameters:let oldUbiquityIdentityToken = NSKeyedUnarchiver.unarchivedObject(ofClass: NSCoding.Protocol, from: Data)Why am I getting these error messages?
6
0
3.6k
Apr ’20
can't delete
I have code to batch delete records from the private database in CloudKit, but it's not working. (I also noticed that the records I saved are not remaining.)It looks like some of the records that the code is supposed to delete is actually deleted, but some are not. When I run the code again, there exists records still, but about one less the number as before.I think the most important thing about this problem is that IT OCCURS WHEN I USE AN APPLE ID THAT IS NOT MY DEVELOPER ACCOUNT.Here is my code: class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let splitViewController = window!.rootViewController as! UISplitViewController let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem splitViewController.delegate = self deleteRecords() return true } } let privateDatabase = CKContainer.default().privateCloudDatabase func deleteRecords() { print("deleteRecords()") let predicate = NSPredicate(value: true) let query = CKQuery(recordType: DatabaseNameStrings.recordTypeAffirmation, predicate: predicate) privateDatabase.perform(query, inZoneWith: nil) { (records: [CKRecord]?, error: Error?) in if error != nil { print(error as Any) } else { if let records = records { print("records.count=", records.count) let recordIDsToDelete = records.map { $0.recordID } print("recordIDsToDelete:") print(recordIDsToDelete) let operation = CKModifyRecordsOperation(recordsToSave: nil, recordIDsToDelete: recordIDsToDelete) operation.modifyRecordsCompletionBlock = { savedRecords, deletedRecordIDs, error in if error == nil { print("Batch delete records!") print("number of records deleted:", deletedRecordIDs?.count as Any) printNumberOfRecords() } else { print(error as Any) } } privateDatabase.add(operation) } } } } func printNumberOfRecords() { let predicate = NSPredicate(value: true) let query = CKQuery(recordType: DatabaseNameStrings.recordTypeAffirmation, predicate: predicate) privateDatabase.perform(query, inZoneWith: nil) { (records: [CKRecord]?, error: Error?) in if error != nil { print(error as Any) } else { if let records = records { print("Number of records in CloudKit=", records.count) } } } }Here is the output in the debug window from the first run of the code:deleteRecords()records.count= 93recordIDsToDelete:[<CKRecordID: 0x280bbcb00; recordName=B33A3F23-23D3-44C6-AEBC-86DD718DBB62, zoneID=_defaultZone:__defaultOwner__>, ...]Batch delete records!number of records deleted: Optional(93)Number of records in CloudKit= 67Here is the output in the debug window from the second run of the code:deleteRecords()records.count= 92recordIDsToDelete:[<CKRecordID: 0x280080d00; recordName=BBA5B236-A036-4AC9-82E1-165D3B003E23, zoneID=_defaultZone:__defaultOwner__>, ...]Batch delete records!number of records deleted: Optional(92)Number of records in CloudKit= 52
6
0
665
Apr ’20
One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName.
I am getting an error:One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName.I haven't even saved any data to Core Data yet.The property that has type Transformable, 'notificationIdentifiers', is of type NSObject in my NSManagedObject subclass. Why is the error saying it is unset or set to NSKeyedUnarchiveFromDataTransformerName?I also get the warning:CoreData: warning: Property 'notificationIdentifiers' on Entity 'Affirmation' is using nil or an insecure NSValueTransformer. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead.Here is my NSManagedObject subclass:extension Affirmation { @nonobjc public class func fetchRequest() -> NSFetchRequest<Affirmation> { return NSFetchRequest<Affirmation>(entityName: "Affirmation") } @NSManaged public var body: String @NSManaged public var count: Int64 @NSManaged public var days: NSData @NSManaged public var frequency: Int64 @NSManaged public var notificationIdentifiers: NSObject @NSManaged public var recordName: String? @NSManaged public var time: NSDate @NSManaged public var timestamp: NSDate @NSManaged public var title: String }When I change that property to be of type NSSecureUnarchiveFromData in my NSManagedObject subclass, I get an error saying:Use of undeclared type 'NSSecureUnarchiveFromData'I did a search on Google and I get no results telling me which library framework Use of undeclared type 'NSSecureUnarchiveFromData' belongs to.I don't think I am understanding exactly what this message is saying.Here is my entire debug window:2020-04-09 14:43:34.107774-0500 Affirmations[3922:921109] [error] fault: One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using "NSSecureUnarchiveFromData" when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.CoreData: fault: One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using "NSSecureUnarchiveFromData" when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.2020-04-09 14:43:34.108286-0500 Affirmations[3922:921109] [error] CoreData: One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using "NSSecureUnarchiveFromData" when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.CoreData: warning: Property 'notificationIdentifiers' on Entity 'Affirmation' is using nil or an insecure NSValueTransformer. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead.
2
0
2.9k
Apr ’20
Could not locate device support files.
I have the latest Xcode and the latest iOS on my iPhone 8.Why am I getting this message when I run my project on my iPhone 8?Could not locate device support files.This iPhone 8 (Model ...) is running iOS 13.4 (...), which may not be supported by this version of Xcode. An updated version of Xcode may be found on the App Store or at developer.apple.com.
3
0
2.2k
Apr ’20