Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-03-2011, 09:44 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 1
jadalsalim is on a distinguished road
Default Objective c: writeToFile is not writing to the file

Well I am experiencing a problem and I've been struggling with it for few days. Here it is: when trying to write to an xml file (placed in the xcode project which I am developing) using writeToFile, writing doesn't work and I can see nothing in the xml file although the bool value which is returned from writeToFile is being evaluated to true !! In addition, the file bytes are zero. So, I would really appreciate if anyone can help me out with that. Below is part of the code which I wrote:

//writing to a file NSString *file_path = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"xml"]; NSString *hello_world = @"Hello World!!\n"; NSFileManager *filemgr;

filemgr = [NSFileManager defaultManager];

//entering the first condition so I assured that the file do exists if ([filemgr fileExistsAtPath:file_path] == YES) NSLog (@"File exists"); else NSLog (@"File not found");

BOOL ok = [hello_world writeToFileath atomically:YES encoding:NSUnicodeStringEncoding error:nil];

//Not entering this condition so I am assuming that writing process is successful but when I open the file I can't find the string hello world and file size shows 0 bytes
if(!ok)
{
NSLog(@"Unable to write to the file");
}

I also tried this alternative, but unfortunately it didn't work too.

NSString *hello_world = @"Hello World!!\n";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *directory = [paths objectAtIndex:0]; NSString *fileName = @"sample.xml";
NSString *filePath = [directory stringByAppendingPathComponent:fileName]; NSLog(@"%@",filePath);
BOOL ok = [hello_world writeToFile:filePath atomically:YES encoding:NSASCIIStringEncoding error:nil];
if(!ok)
{ NSLog(@"Unable to write to the file");
}
jadalsalim is offline   Reply With Quote
Reply

Bookmarks

Tags
objecive c

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 475
13 members and 462 guests
AlanFloyd, AppsBlogger, David-T, HemiMG, iAppDeveloper, imac74, Jaxen66, lovoyl, mutantskin, Paul Slocum, tiendung2992, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,684
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, tiendung2992
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0