Skip to content

Instantly share code, notes, and snippets.

@kechan
Last active September 27, 2017 20:26
Show Gist options
  • Save kechan/7b72d6b4ebb3cf7a3a4d827c288cd731 to your computer and use it in GitHub Desktop.
Save kechan/7b72d6b4ebb3cf7a3a4d827c288cd731 to your computer and use it in GitHub Desktop.
CoreData in Playground
// Paste this in Playground
import CoreData
let url = Bundle.main.url(forResource: "HikingApp", withExtension: "momd")
let model = NSManagedObjectModel(contentsOf: url!)
let container = NSPersistentContainer(name: "HikingApp")
let context = container.viewContext
class Trip: NSManagedObject {
}
extension Trip {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Trip> {
return NSFetchRequest<Trip>(entityName: "Trip")
}
@NSManaged public var endLocation: String?
@NSManaged public var endOdoReading: Double
@NSManaged public var endOdoReading2: Double
@NSManaged public var endTime: NSDate?
@NSManaged public var endTime2: NSDate?
@NSManaged public var isRoundTrip: Bool
@NSManaged public var name: String?
@NSManaged public var startLocation: String?
@NSManaged public var startOdoReading: Double
@NSManaged public var startOdoReading2: Double
@NSManaged public var startTime: NSDate?
@NSManaged public var startTime2: NSDate?
}
let trip = Trip(context: context)
trip.name = "Smoky Mountain at Tennessee"
try? context.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment