How to write a BOOL predicate in Core Data?

From Predicate Programming Guide: You specify and test for equality of Boolean values as illustrated in the following examples: NSPredicate *newPredicate = [NSPredicate predicateWithFormat:@”anAttribute == %@”, [NSNumber numberWithBool:aBool]]; NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@”anAttribute == YES”]; You can also check out the Predicate Format String Syntax.

How to apply the type to a NSFetchRequest instance?

let request: NSFetchRequest<NSFetchRequestResult> = Level.fetchRequest() or let request: NSFetchRequest<Level> = Level.fetchRequest() depending which version you want. You have to specify the generic type because otherwise the method call is ambiguous. The first version is defined for NSManagedObject, the second version is generated automatically for every object using an extension, e.g: extension Level { @nonobjc class … Read more

Sqlite File Location Core Data

I managed to locate the sqlite file, and its in this path now: Library/Developer/CoreSimulator/Devices/(numbers and letters)/data/Containers/Data/Application/(numbers and letters)/Documents/ (numbers and letters) stands for a folder that would be unique to your app/computer, but would look like this: 779AE2245-F8W2-57A9-8C6D-98643B1CF01A I was able to find it by going into appDelegate.m, scrolling down to the – (NSURL *)applicationDocumentsDirectory … Read more

Best way to implement Enums with Core Data

You’ll have to create custom accessors if you want to restrict the values to an enum. So, first you’d declare an enum, like so: typedef enum { kPaymentFrequencyOneOff = 0, kPaymentFrequencyYearly = 1, kPaymentFrequencyMonthly = 2, kPaymentFrequencyWeekly = 3 } PaymentFrequency; Then, declare getters and setters for your property. It’s a bad idea to override … Read more

Coredata Error “data: “

This is expected behaviour, core data won’t return full objects until you need to access the persistent values of the objects. Each of your returned objects will be a ‘fault’ until this point. You can force the fetch request to return full objects using [request setReturnsObjectsAsFaults:NO], but in most cases what you have will be … Read more

Best Practice – NSError domains and codes for your own project/app

I personally use a reverse-DNS style domain. For example: NSError * myInternalError = [NSError errorWithDomain:@”com.davedelong.myproject” code:42 userInfo:someUserInfo]; The third part of the domain (@”myproject”) is just used to differentiate the errors from this project (“My Project”) from errors in another project (“My Other Project” => com.davedelong.myotherproject). It’s a simple way to ensure that I’m not … Read more

Using Core Data, iCloud and CloudKit for syncing and backup and how it works together

It’s like this: Core Data on its own, is completely local and does not automatically work with any of Apple’s cloud services. Core Data with iCloud enabled turns on syncing via iCloud. Any changes you save in Core Data are propagated to the cloud, and any changes made in the cloud are automatically downloaded. The … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)