Post not yet marked as solved
CloudKit Limitations:
Mirroring a Core Data Store with CloudKit | Apple Developer Documentation
Determine If Your App Is Eligible for Core Data with CloudKit
Apps adopting Core Data can use Core Data with CloudKit as long as the persistent store is an NSSQLiteStoreType store, and the data model is compatible with CloudKit limitations. For example, CloudKit does not support unique constraints, undefined attributes, or required relationships.
I removed all Binding related, changed the Float(daysLeft / totalDays) to Float(dayLeft) / Float(totalDays) and just called the calculatePercentageLeft function directly from the ProgressBar view.
Post not yet marked as solved
Not really a lot of data, about 10-50 objects with 10 properties each. So you think the most appropriate thing to do is use the local container if sync is off and switch to cloudKit container if it's on? My main struggle is not knowing how to structure my code in a way that I can turn On/Off sync on runtime from other views to test it and see if it will work.
Post not yet marked as solved
I solved it by changing Always Embed Swift Standard Libraries from Yes to No. for the Watch App.
Thank you for the clarification.
FYI - I accidentally marked my previous response as the correct answer and I don't see a way of changing it, I need to mark your last comment as the correct answer.
Here is the code I'm using...
Connection to the Private Database
let privateDatabase = CKContainer.default().database(with: .private)
Reading records
`privateDatabase.perform(query, inZoneWith:nil){( results , error) in ... }
Writing Records
privateDatabase.save(ckRecord){ (record, error) in ...}
What I ultimately need to know is whether I need to check if the user is logged in or not when accessing the database to avoid redundant code/checks.
Thanks
Post not yet marked as solved
Here is the code to save a record in a custom zone.func addRecordToCustomZone() {
let ckRecordZoneID = CKRecordZone(zoneName: "CustomZoneName")
let ckRecordID = CKRecord.ID(zoneID: ckRecordZoneID.zoneID)
let aRecord = CKRecord(recordType: "Cars", recordID: ckRecordID)// Cars is the data Type
aRecord["carMake"] = "Porche" // carMake is a field in the Cars Type.
aRecord["carModel"] = "Carrera" // carModel is a field in the Cars Type.
privateDatabase.save(aRecord, completionHandler: { (record, error) -> Void in
if let error = error {
print(error)
}
else {
print("record saved successfully")
}
})
}Please note that you also have the option of adding your own record name if you like by specifying it in the `CKRecord.ID` as follow.let ckRecordID = CKRecord.ID(recordName: "SomeUniqueName", zoneID: ckRecordZoneID.zoneID)
Post not yet marked as solved
W T F, how long does it take to freaking approve something and why does this need to be approved???
Apparently the name of your `CustomZone` record changes when it gets added to the Shared Database so, you first need to retrieve all custom zones from the shared database.I found the answer thanks to the following two threads.https://stackoverflow.com/questions/40603657/cloudkit-sharinghttps://stackoverflow.com/questions/56163096/unable-to-fetch-records-in-a-sharedclouddatabase-custom-zone-using-cloudkit##CODE: @IBAction func readSharedRecords(_ sender: Any) {
let sharedData = CKContainer.default().sharedCloudDatabase
sharedData.fetchAllRecordZones { (recordZone, error) in
if error != nil {
print(error?.localizedDescription ?? "Error")
}
if let recordZones = recordZone {
for i in 0..<recordzones.count{
// find the zone you want to query
if recordZones[i].zoneID.zoneName == "ListsZone"{
self.sharedRecords(zID: recordZones[i].zoneID)
}
}
}
}
}
func sharedRecords(zID: CKRecordZone.ID){
let privateDatabase = CKContainer.init(identifier: "iCloud.com.mySite.lists").database(with: .shared)
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Items", predicate: predicate)
privateDatabase.perform(query, inZoneWith: zID){( results , error) in
guard error == nil else{
print("Error: \(String(describing: error?.localizedDescription))")
return
}
if let itemsFromResults = results{
print("Items: \(itemsFromResults)")
}
}
}
Post not yet marked as solved
Yes, line 46 executes the deleteRow() method. try! realm.write is the Realm syntax to be able to perform changes to the database. I'm deleting results[0] when a button is tapped just to test and make sure it wasn't the swipe delete causing the error. Deleting results[0] should indeed remove the first item and refresh the List but it's not doing it, that's mainly my issue. It does work when adding new items to Realm.For instance, if I add a new dog object the List immediately updates. try! realm.write{
realm.add(dog)
}The error points to the appDelegate.swift file (Thread 1: signal SIGABRT).Thanks!
Oh, it does throw a compilation error when you picked the asset directly in the interface builder in the attributes inspector? If that's the case It's all I need.
Thank you for the informaiton. I noticed that the app, OptionPosition+ provides the Terms of Use and the Privacy Policy in both, the device and online, is this really a requirement? I was under the impresion that one was enough.