Why can't I read the content of foo.rtf? I've already put it in Xcode bundle. fileRoot still contains null.
NSString* filePath = @"foo";
NSString* fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:@"rtf"];
NSLog(@"File root contains %@", fileRoot);
@TheAmateurProgrammer, Thank you for the diagram. I just added foo.rtf into the bundle resources. The result for fileRoot is still null. What step am I still missing?
Target's "Copy Bundle Resources" in Build Phases now contains foo.rtf. (I can't insert picture as I'm still a newbie).
(I will add the content reading after I can get fileRoot to point correctly).
You added the file, but is it really copied to your application bundle?
Make sure your rtf file is copied into your resource.
Secondly, you're only getting the path of the rtf, and not the contents of the rtf.
NSString *fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:@"rtf"];
NSString *contents = [[[NSAttributedString alloc] initWithRTF:[NSData dataWithContentsOfFile:fileRoot] documentAttributes:NULL] string];
That will get the contents of the rtf.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With