Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 29, 2013, 10:07 AM   #1
mehdies
macrumors member
 
Join Date: Jun 2012
Read file contents and store in string

Could you explain me how read a txt file and store contents in string variable in coreFoundation?
mehdies is offline   0 Reply With Quote
Old Apr 29, 2013, 10:29 AM   #2
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by mehdies View Post
Could you explain me how read a txt file and store contents in string variable in coreFoundation?
Why not in Cocoa?
gnasher729 is offline   0 Reply With Quote
Old Apr 29, 2013, 10:40 AM   #3
PatrickCocoa
macrumors 6502a
 
Join Date: Dec 2008
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.
__________________
iMac 21.5", 3.06GHz, 4 GB, 2 TB HD.
iPod Touch 3G.
PatrickCocoa is offline   1 Reply With Quote
Old Apr 29, 2013, 02:37 PM   #4
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
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.
ArtOfWarfare is offline   1 Reply With Quote
Old Apr 29, 2013, 11:59 PM   #5
mehdies
Thread Starter
macrumors member
 
Join Date: Jun 2012
Quote:
Originally Posted by gnasher729 View Post
Why not in Cocoa?
I have a .cpp source code with I/O Kit and CoreFoundaton used in it.can i use Foundation?
mehdies is offline   0 Reply With Quote
Old Apr 30, 2013, 06:59 AM   #6
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by mehdies View Post
I have a .cpp source code with I/O Kit and CoreFoundaton used in it.can i use Foundation?
You can change it from .cpp to .mm and mix C++ and Objective-C.
gnasher729 is offline   1 Reply With Quote
Old Apr 30, 2013, 09:34 AM   #7
subsonix
macrumors 68040
 
Join Date: Feb 2008
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.
subsonix is offline   1 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
File list to Excel - Exporting folder contents! giorgtrig Mac Applications and Mac App Store 2 Oct 6, 2014 10:30 AM
File Path String Editing Tool? willcapellaro Mac Programming 11 Feb 4, 2014 01:58 AM
iTunes cannot read the contents of this phone 0xyMoron iOS 6 2 Sep 28, 2013 02:35 AM
File rename based on file contents--possible? Brutalbrutus Mac Basics and Help 2 Jul 17, 2012 05:57 AM
iTunes cannot read contents of my iPhone 4S! Help! guspasho iPhone Tips, Help and Troubleshooting 0 Jun 13, 2012 06:33 PM

Forum Jump

All times are GMT -5. The time now is 05:26 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC