nsvaluetransformer

Use Swift's Date with CoreData

心已入冬 提交于 2020-04-08 09:16:26
问题 I have a lot of date fields in my database model. CoreData allows to use NSDate or TimeInterval to save dates depending on "Use Scalar Type" option. However both these options are bad for me since I want to use dates as Date objects. Since NSDate is not implicitly convertible to Date I have to cast/convert values to Date or to implement a lot of custom setters/getters in my NSManagedObject classes. I have tried to use ValueTransformer but it does not work with non-@objc classes like Date . So

Use Swift's Date with CoreData

↘锁芯ラ 提交于 2020-04-08 09:15:33
问题 I have a lot of date fields in my database model. CoreData allows to use NSDate or TimeInterval to save dates depending on "Use Scalar Type" option. However both these options are bad for me since I want to use dates as Date objects. Since NSDate is not implicitly convertible to Date I have to cast/convert values to Date or to implement a lot of custom setters/getters in my NSManagedObject classes. I have tried to use ValueTransformer but it does not work with non-@objc classes like Date . So

Core Data not automatically calling value transformer when getting / setting attribute directly in code

风流意气都作罢 提交于 2020-01-04 09:46:46
问题 If I understand correctly, the idea behind Core Data transformable attributes is: implement an NSValueTransformer subclass with returns [NSData class] in +transformedValueClass along with its implementation for transformation register the transformer in +load or +initialize set an entity's attribute as transformable set a name for your transformer (the name you used to register it) in the xcode model editor for the attribute. At this point, I'd expect that accessing or setting the attribute

Core Data not automatically calling value transformer when getting / setting attribute directly in code

佐手、 提交于 2020-01-04 09:42:13
问题 If I understand correctly, the idea behind Core Data transformable attributes is: implement an NSValueTransformer subclass with returns [NSData class] in +transformedValueClass along with its implementation for transformation register the transformer in +load or +initialize set an entity's attribute as transformable set a name for your transformer (the name you used to register it) in the xcode model editor for the attribute. At this point, I'd expect that accessing or setting the attribute

Extremely Odd Crash When saving a transformable NSAttributedString into Core Data

偶尔善良 提交于 2020-01-03 05:15:30
问题 I have a project using Core Data. It has a Note object which has one transformable attribute called content. I am storing an NSAttributedString into this property. The property saves fine for the first save, but when I try to create a second note object, the app crashes. Here is the code I use to save: - (IBAction)save:(id)sender { Note* newNote = [NSEntityDescription insertNewObjectForEntityForName:@"Note" inManagedObjectContext:[self managedObjectContext]]; NSAttributedString* string = [

Using an NSValueTransformer to set values of an NSManagedObject instance

孤街醉人 提交于 2019-12-23 19:31:44
问题 I am using a custom NSValueTransformer to store color information in my Core Data store. The transformation between Transformable data and a UIColor instance works great once the color data is in the store already (ie once the app has been run and quit once already). However when I first run the app and am loading in these values (from a text file) they "stuck" as NSCFStrings. In this line of code "attributes" is a dictionary has keys which are NSManagedObject attribute names and values that

Trouble with Core Data Transformable Attributes for Images

假装没事ソ 提交于 2019-12-23 03:06:20
问题 I am stuck on what is supposed to be a very simple thing to do: have a Core Data Entity store / display (through bindings) an image assigned as a transformable attribute. I've read many related posts on the Stack (e.g., see here and here), but am still having trouble with it, after having developed sample code and researched other articles (e.g., see here as well as here). This is related to my earlier question, which I still have not resolved. I created a simple doc-based Core Data App to

iOS Core Data encryption using NSValueTransformer

孤街浪徒 提交于 2019-12-21 20:37:54
问题 I'm experimenting with encrypting data with Core Data and CommonCrypto. I am trying to use a NSValueTransformer to lazily encrypt and decrypt. However when I'm now trying save the encrypted data to the persistent store coordinator, it fails. Every time im trying to save my data to the database, it gives me: -[__NSCFString bytes]: unrecognized selector sent to instance I'm sure it's some sort of database and NSManagedObject mismatch, but I can't figure it out. I feel it's probably rather

Saving custom class into Coredata

眉间皱痕 提交于 2019-12-21 05:14:17
问题 Hi i have used attribute type transformable and i have followed the procedure of archiving in one of the Forum . But it says CoreData: warning: no NSValueTransformer with class name 'SurveyResults' was found for attribute 'survey' on entity 'SurveyData' 2013-04-30 09:44:16.022 TestReachability[11641:c07] -[SurveyApplication encodeWithCoder:]: unrecognized selector sent to instance 0x845cb00 2013-04-30 09:44:16.023 TestReachability[11641:c07] * Terminating app due to uncaught exception

RestKit valueTransformer not being called

流过昼夜 提交于 2019-12-10 20:03:54
问题 I am using RestKit to talk to my JSON endpoints. The endpoint returns a UNIX timestamp in 'number of milliseconds'. But RestKit's default transformer assumes that it is 'number of seconds' and I get a wrong value in NSDate. So I looked around, and found that I need to use a custom valueTransformer to tell RestKit how to transform my timestamp. Here's the code I have. + (RKBlockValueTransformer*) timeIntervalInMillisecondsSince1970TwoWayTransformer { return [RKBlockValueTransformer