0

I have a weird issue. I have a UTF-8 encoded json which is converted to models via RestKit.

When I view the contents of my model I get a nice string with special chars with phrases like "los kaartje €17,50 (o.a. te koop" (notice the €-sign)

Now when I save the value in a NSString like this:

NSString *placeholder = self.event.description;

My string suddenly becomes los kaartje ?17,50 (o.a. te koop (notice the €-sign being gone).

I can't figure out why. The only thing I noticed is that self.event.description is a __NSCFString * instead of a NSString *

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Daan Olislagers
  • 3,253
  • 2
  • 17
  • 35
  • __NSCFString is a (private) subclass of the NSString class cluster, that is not the problem. How is self.event created from the JSON data? – Martin R May 06 '14 at 17:55
  • Using RestKit's objectmapping. – Daan Olislagers May 06 '14 at 17:56
  • In the two cases how are you viewing the contents of your string? – CRD May 06 '14 at 18:04
  • Using the debugger, both times. It's even the same line of code. – Daan Olislagers May 06 '14 at 18:05
  • Instead of using `description` you probably better use methods such as `stringWithFormat` to create a string from the object. E.g. `[NSString stringWithFormat:@"%@ %@", self.event.item, self.item.price]` – Martin R May 06 '14 at 18:14
  • I've tried, it doesn't work...But `description` is not a object, nor is it the the description of the object, it is just a property (type `NSString *`) of the event object. – Daan Olislagers May 06 '14 at 18:20
  • @DaanOlislagers: What kind of object is `self.event`? – Martin R May 06 '14 at 18:23
  • It is a custom Event class. Nothing special, just a few NSString's and a few methods. – Daan Olislagers May 06 '14 at 18:30
  • I found it! How could I be so dumb. description had a custom getter method. Which did this: `return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];`.. So no UTF-8. Thanks anyway! – Daan Olislagers May 06 '14 at 18:32
  • Remark: `description` is an `NSObject` method and meant to return a a string that represents the contents of the object. You can override that in a subclass, but using `description` for a single attribute of your class might be confusing for other people that have to work with your code. – Martin R May 06 '14 at 18:44

0 Answers0