What can I do with an Transformable attribute type in Core Data on the iPhone?

Transformable attributes are useful for storing nonstandard object types within Core Data. For example, I provide code in this answer that lets you store UIImages as an attribute within Core Data. The image data is converted to and from an NSData instance that contains the image’s PNG representation. This is all handled transparently for you … Read more

Is there a way to instantiate a NSManagedObject without inserting it?

For what it’s worth, Marcus Zarra seems to be promoting the nil context approach, claiming that it’s expensive to create a new context. For more details, see this answer to a similar question. Update I’m currently using the nil context approach and have encountered something that might be of interest to others. To create a … Read more

What does Apple mean when they say that a NSManagedObjectContext is owned by the thread or queue that created it?

The NSManagedObjectContext and any managed objects associated with it should be pinned to a single actor (thread, serialized queue, NSOperationQueue with max concurrency = 1). This pattern is called thread confinement or isolation. There isn’t a great phrase for (thread || serialized queue || NSOperationQueue with max concurrency = 1) so the documentation goes on … Read more

How do you update a CoreData entry that has already been saved in Swift?

Since batchupdate is more useful in larger chunks of data, I think this is a more subtle approach. func saveLoginData(accessToken: String, userName: String) { var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate) var context: NSManagedObjectContext = appDel.managedObjectContext! var fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: “LoginData”) fetchRequest.predicate = NSPredicate(format: “userName = %@”, userName) if let fetchResults = appDel.managedObjectContext!.executeFetchRequest(fetchRequest, error: nil) … Read more

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