Reputation: 300
I am working on an iOS app which is going to handle many documents of about 40-80k each in a core data datastore. For ease of data input, I put together a simple cocoa app that saves the contents of an NSTextView control to a transformable field in the store.
I'm then opening the saved store in my iOS app and having problems. When I try to use a UITextView control to access the fetched results from that field in the data store, the displayed text is a hex dump. I'm guessing that the NSTextView in the cocoa app is saving RTF text to the field, and the UITextView is expecting to get plain text.
I'm using a simple Master-Detail project for iPad right now to try and get at the data. Here's the code for loading up data from the data store:
self.detailDescriptionLabel.text = [[self.detailItem valueForKey:@"name"] description];
self.detailTextView.text = [[self.detailItem valueForKey:@"text"] description];
When I run the app and look at the results, here's what I get as the content of the detailTextView
:
<7b5c7274 66315c61 6e73695c 616e7369 63706731 3235325c 636f636f 61727466 31313338 5c636f63 6f617375 62727466 3437300a 7b5c666f 6e747462 6c5c6630 5c667377 6973735c 66636861 72736574 30204865 6c766574 6963613b 7d0a7b5c 636f6c6f 7274626c 3b5c7265 64323535 5c677265 656e3235 355c626c 75653235 353b7d0a 5c706172 645c7478 3536305c 74783131 32305c74 78313638 305c7478 32323430 5c747832 3830305c 74783333 36305c74 78333932 305c7478 34343830 5c747835 3034305c 74783536 30305c74 78363136 305c7478 36373230 5c706172 6469726e 61747572 616c0a0a 5c66305c 66733234 205c6366 30205468 69732069 73207468 6520776f 726b696e 6720636f 70792e7d>
I've tried using an NSAttributedString
to get the data, but the initWithRTFD:documentAttributes:
method doesn't appear to be available in iOS.
I honestly don't care about it being RTF. I just want to get text back out.
Upvotes: 0
Views: 454
Reputation: 57188
You don't want to use the description
method; this converts the NSData returned as your text
key into the form you see as a hex dump. (If you want the actual content as a string, you can use something like [NSString initWithData:encoding:]
to get the data back into a string.)
But you probably don't want to convert to a string, since I don't think UITextView can display RTF data. (At least not in iOS 5). Instead, you could at least view the data in a UIWebView by passing the raw NSData to - [UIWebView loadData:MIMEType:textEncodingName:baseURL:]
.
Upvotes: 1