TAG: Swift

Software and more

Navigation

CoreData CRUD methods in Swift 2.0

With Swift 2.0, Apple introduced a protocol oriented way of programming. I want to use this to create a protocol that adds CRUD functionality to CoreData models without the need for all the type casting. import Foundation import CoreData protocol CoreDataCRUD { } extension CoreDataCRUD where Self : NSManagedObject { static func create() -> Self { return NSEntityDescription.insertNewObjectForEntityForName(Utility.classNameAsString(self), inManagedObjectContext: sharedCoreDataManager.context()) as! Self } static func findById(id: String) throws -> Self? { let fetchRequest = NSFetchRequest(…

Swift CoreData: generate swift NSManagedObjects

This is a follow up to my previous post about Xcode6 and CoreData. If you set the class in your xcdatamodel to <MyAppName>.User and create the NSManagedObjects from the entities, Xcode6 does not generate the correct .swift model files. It parses the class <MyAppName>.User only to the . and creates a single <MyAppName>.swift file. For now the only fix i have is to rename the class to User,…

Swift CoreData: Unable to load class named...

CoreData: warning: Unable to load class named 'User' for entity 'User'. Class not found, using default NSManagedObject instead. If you get this error, but you are sure that there should exist an entity 'User', it is most likely that you forgot to set the correct class in the xcdatamodel. It should look like this: <MyAppName>.User Follow up: Generating the .swift model files Source: https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/…