Jeena
Jeena

Reputation: 2222

Core Data how to change NSNumber to NSString?

I am using Core Data for my app and I have a model Reservation and there I have a facebook_event_id which at first I had as a Integer 64 but the problem is that this is perhaps to short and I would like it to change to NSString (I get it as JSON string from Facebook anyway).

I have done the following for now:

When I tested it to change between Integer 16 and 64 everything worked fine but when I try to change from Integer 64 and String it gives me an error:

Can't find or automatically infer mapping model for migration

So I added a new mapping model and there I wanted to fix it in ReservationRoReservation | facebook_event_id | $source.facebook_event_id

I think one should do something with $source.facebook_event_id to get it converted but I have no idea what to write in the to get it to work. One should not use plain Objective-C there but a NSExpression, but nowhere there it explains how to convert a NSNumber to a NSString.

Upvotes: 2

Views: 1196

Answers (2)

Dan Jackson
Dan Jackson

Reputation: 451

I think you want:

FUNCTION($source.facebook_event_id, "stringValue")

Which will take the NSNumber currently in your facebook_event_id property, and send the stringValue message to it.

Upvotes: 6

Owen Hartnett
Owen Hartnett

Reputation: 5935

How about:

NSString *convertedString = [NSNumber stringValue];

Upvotes: 1

Related Questions