Skip to content

Instantly share code, notes, and snippets.

@Lancewer
Created January 11, 2018 08:57
Show Gist options
  • Save Lancewer/2232101a89a33bd226b62d3c9cad88c9 to your computer and use it in GitHub Desktop.
Save Lancewer/2232101a89a33bd226b62d3c9cad88c9 to your computer and use it in GitHub Desktop.
[GetManagedObjectID] get managedObjectID created by CoreData #CoreData #iOS #ID #swift #ObjectID
shows how to get all managedID from a entiry preserved by CoreData
let itemIDsFetchRequest = NSFetchRequest<NSManagedObjectID>(entityName: "ClothItem")
itemIDsFetchRequest.resultType = .managedObjectIDResultType
do {
let ids = try managedContext!.fetch(itemIDsFetchRequest)
print(ids.first!.uriRepresentation().absoluteString)
}catch let error as NSError {
print("Fetch item failed:\(error), \(error.userInfo)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment