core-data

CoreData - Duplicate existing object

久未见 提交于 2020-01-31 05:58:12
问题 Hi would like to duplicate an object from my core data db. Right now I'm using movement2 = [NSEntityDescription insertNewObjectForEntityForName:@"Movement" inManagedObjectContext:self.managedObjectContext]; movement2.name = movement.name; movement2.value = movement.value; movement2.date = movement.date; ... and it works. but... Is there any way to copy all the values of movement to movement2 , in one line of code? 回答1: NSManagedObject, unlike NSObject, provides an API to iterate over its

How to save and fetch in xmppGroupCoreDataStorageObject?

纵饮孤独 提交于 2020-01-30 09:32:06
问题 Using xmpp-messenger-ios , I have created the group and set its configuration and adds the users into it, then I wants to add the group into the xmppGroupCoreDataStorageObject storage to list it into the OpenChatViewController table view. How I am saving the Group Data into xmppGroupCoreDataStorageObject: public class func addUserInCoreData(jid:String, users: Set<NSObject>) { let moc = OneRoster.sharedInstance.managedObjectContext_roster() as NSManagedObjectContext? let entity =

Core data: Managing employee contracts in a many-to-many relationship?

此生再无相见时 提交于 2020-01-30 03:55:30
问题 I am mapping an idea for a relationship using Core Data. I have an Employer entity who has a many-to-many relationship with Employees . Basically, an employee can work for multiple employers, and an employer can have multiple employees. The problem I'm facing is, I'm not sure how to manage the contracts between employees and employers. As an employee can work for either 1 or many employers, they would naturally have a contract for each employer they work for (complete with salary, duration)

Saving an array with core data Swift 3?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-29 05:36:08
问题 I'm trying to save an array within Core Data as a property. allImages is going to be assigned to a [String]. I've seen some people say to make it transformable. What is the proper solution to saving this into core data? 回答1: how do I get reference to them so I can change the transformable to [String] This is actually a good point because the answer I linked too assumed that you were creating your own NSManagedObject subclasses. It's worth emphasizing that creating/maintaining your own

coredata - fetch one attribute into an array

拟墨画扇 提交于 2020-01-29 04:40:17
问题 Aim: I would like to fetch the value of one attribute (from an entity) from the database (core data) into an array. Example Entity Name = Employees Attribute = employeeID I just want all the employeeIDs populated into an array / set. Question Given below is my implementation, I just feel it is kind of a round about way, I would like to know if there is a better way to do this. Code NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Employees"]; fetchRequest.resultType

Cocoa error 256 core data

纵然是瞬间 提交于 2020-01-28 06:46:59
问题 I have error "Cocoa error 256" when I try to save data. How to fix it? And what problem? 回答1: According to the help reference in Xcode: NSFileReadUnknownError Read error, reason unknown Available in Mac OS X v10.4 and later. Declared in FoundationErrors.h. Sadly, that's probably not too helpful, though it is an unknown -read- error. 回答2: If its a core data error there is probably an actual error object somewhere near where the error occurs. If you dump the error objects userInfo dictionary,

Cocoa error 256 core data

自闭症网瘾萝莉.ら 提交于 2020-01-28 06:43:55
问题 I have error "Cocoa error 256" when I try to save data. How to fix it? And what problem? 回答1: According to the help reference in Xcode: NSFileReadUnknownError Read error, reason unknown Available in Mac OS X v10.4 and later. Declared in FoundationErrors.h. Sadly, that's probably not too helpful, though it is an unknown -read- error. 回答2: If its a core data error there is probably an actual error object somewhere near where the error occurs. If you dump the error objects userInfo dictionary,

Cocoa error 256 core data

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-28 06:42:13
问题 I have error "Cocoa error 256" when I try to save data. How to fix it? And what problem? 回答1: According to the help reference in Xcode: NSFileReadUnknownError Read error, reason unknown Available in Mac OS X v10.4 and later. Declared in FoundationErrors.h. Sadly, that's probably not too helpful, though it is an unknown -read- error. 回答2: If its a core data error there is probably an actual error object somewhere near where the error occurs. If you dump the error objects userInfo dictionary,

NSFetchedResultsController and getting the grouping right

廉价感情. 提交于 2020-01-25 22:52:49
问题 I have the following problem. I have a UITableview that is powered by an NSFetchedResultsController. It should display let's say a projects, folders and files. There is no bigger hierarchy than that. So a project has several folders and those have several files. Now my table view should display those files, grouped by folders. So i thought my fetch requests' predicate would simply be: [NSPredicate predicateWithFormat:@"folder.project = %@", self.project]; I would then use MagicalRecord to

iOS Magical record import from array

流过昼夜 提交于 2020-01-25 20:27:18
问题 Hi I'm making a synchronise function that update database when receive JSON response from server. I want the import only take place if there are different data (new record or update existing record) (To increase performance) (Using coredata and magicalRecord ) Here is my JSON parser method - (void)updateWithApiRepresentation:(NSDictionary *)json { self.title = json[@"Name"]; self.serverIdValue = [json[@"Id"] integerValue]; self.year = json[@"Year of Release"]; self.month = json[@"Month of