nsentitydescription

How to create unique identifier for an entity in iphone core data

99封情书 提交于 2020-01-24 00:45:10
问题 I am new to core data and iphone programming so dont mind my silly qn. I couldn't figure out how to mark a attribute as a primary key in the xcdatamodel file or may be outside. I looked around and found some people saying that it is not possible. I am getting identifier for every object that i am getting, i would need to store that object through core data and i might need to use that identifier in my web service to retrieve additional data. How do i keep the primary key of an entity equal to

CoreData getting attribute type - how to determine if it is a primitive

醉酒当歌 提交于 2020-01-05 09:36:19
问题 I'm trying to get all the attributes for an entity and then determine their type - I know I can do something on this line: if(![[thisAttribute attributeValueClassName] isKindOfClass:[NSString class]]) { but how do I check for a BOOL, Float or Integer? Here's my code so far: //get the attributes for this entity - we need to parse the dictionary of data we want to store and convert its contents from NSStrings to whatever type the entity requires NSEntityDescription* entity =

Core Data NSPredicate filter by entity class?

梦想与她 提交于 2020-01-03 09:12:11
问题 How would I create an NSPredicate to filter by entity of class Contact ? The solution to NSPredicate check for kind of object class crashes: [NSPredicate predicateWithFormat:@"person.class == %@", [Contact class]]; *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath person.class not found in entity <NSSQLEntity User id=12>' Background I have the Core Data entities User (app user) & Contact (address book contact), both children of Person (abstract

Swift: Unacceptable type of value for attribute when creating new NSEntity

佐手、 提交于 2019-12-25 01:09:06
问题 I have a Core Data entity set up with the following attributes: resellerNo:Int resellerName:String I have setup an NSManagedObject as follows: class Reseller: NSManagedObject { @NSManaged var resellerNo: Int @NSManaged var resellerName: String } If I try to run this method: func createNewReseller(resellerName: String) { let context = app.managedObjectContext let resellerEntity = NSEntityDescription.entityForName("Resellers", inManagedObjectContext: context) let newReseller = Reseller(entity:

How to insert new data to entity in Swift3?

删除回忆录丶 提交于 2019-12-21 09:17:10
问题 In swift previously, I was able to use a code like this to add new data to my "TestEntity" in my data model. NSManagedObject was created for my "TestEntity" and I was able to set its attributes with the "dot" syntax At the end, I would save the context let entity=NSEntityDescription.insertNewObject(forEntityName: "TestEntity", into: context) as! TestEntity entity.testAttribute="test value" context.save() This code does not work in Swift3. When I run it, i get the following runtime error:

How to add attributes to an existing Core Data entity (object) programmatically?

元气小坏坏 提交于 2019-12-13 02:23:53
问题 I would like to add attributes programmatically to an entity during runtime of my app. Is this something you would recommend doing or can this lead to issues? How would I need to combine NSAttributeDescription and NSEntityDescription ? I am familiar with creating models using Xcode, but did not do it using NSEntityDescription yet. 回答1: It's theoretically possible, but doesn't appear very practical. You can modify the NSManagedObjectModel programmatically, as well as NSEntityDescription . Note

NSFetchedResultsController multiple entities for UITableView

泪湿孤枕 提交于 2019-12-06 04:17:37
问题 I have two entities one called Post and one called User. Post<<---->User is the relationship in core data. I am using a NSFetchedResultsController to fetch all Post records in my core data stack and then displaying them in a UITableView. Each cell has an image and that image corresponds to a User.profilePicture. Upon initializing I do not download the profile picture from the server, I only download when it scrolls past that cell (lazy load). Once I download it I save the downloaded image to

How to check if a relationship has been established - Core Data

ⅰ亾dé卋堺 提交于 2019-12-06 03:15:35
How would you check if a relationship has been established when adding data to core data? Currently I have a TO MANY relationship between two of my entities. I am attempting to create a detail view but am struggling and i'm not sure if its due to a relationship not being established or if my issue is with passing the data over to the new view controller. I am adding the the data to the core data entities using the following code. Does this look right when establishing a relationship between the two? ExcerciseInfo *info = [_fetchedResultsController objectAtIndexPath:indexPath]; NSManagedObject

NSFetchedResultsController multiple entities for UITableView

非 Y 不嫁゛ 提交于 2019-12-04 11:20:46
I have two entities one called Post and one called User. Post<<---->User is the relationship in core data. I am using a NSFetchedResultsController to fetch all Post records in my core data stack and then displaying them in a UITableView. Each cell has an image and that image corresponds to a User.profilePicture. Upon initializing I do not download the profile picture from the server, I only download when it scrolls past that cell (lazy load). Once I download it I save the downloaded image to the corresponding User.profilePicture in the core data stack. Is there a way for

How to insert new data to entity in Swift3?

与世无争的帅哥 提交于 2019-12-04 02:43:35
In swift previously, I was able to use a code like this to add new data to my "TestEntity" in my data model. NSManagedObject was created for my "TestEntity" and I was able to set its attributes with the "dot" syntax At the end, I would save the context let entity=NSEntityDescription.insertNewObject(forEntityName: "TestEntity", into: context) as! TestEntity entity.testAttribute="test value" context.save() This code does not work in Swift3. When I run it, i get the following runtime error: Could not cast value of type 'NSManagedObject_TestEntity_' (0x175306b0) to 'testCoreData.TestEntity'