Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mehdies

macrumors member
Original poster
Jun 10, 2012
41
0
Could you explain me how read a txt file and store contents in string variable in coreFoundation?
 
Core Foundation

I don't understand the Core Foundation part of the question. But in Cocoa, it's:
Code:
NSString *myWonderfulString = [NSString stringWithContentsOfFile:[NSBundle mainBundle] pathForResource:@"MyAwesomeFile" ofType:@"plist"]];

if your file is a plist that's part of the application's bundle.
 
CFStringRef and NSString* have a "toll free bridge" meaning changing from one to the other involves nothing more than a cast.

Just use the method PatrickCocoa suggested above and cast to a CFStringRef to store the contents in Core Foundation.
 
Note that it can be done with CoreFoundation, it's just more work and more error prone. Have you looked at Apple's CFString reference? If so what exactly is it you are having problems with, there are a handful of functions for converting a buffer to a CFString depending on encoding and other things.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.