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?
 

PatrickCocoa

macrumors 6502a
Dec 2, 2008
751
149
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.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,558
6,058
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.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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.