Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 808727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:36:35+00:00 2026-05-15T00:36:35+00:00

I have a problem with a NSData writeToFile. I have implemented the code below

  • 0

I have a problem with a NSData writeToFile.
I have implemented the code below but i have an anomaly.
When i run my program on the simulator, the new file is created and the informations are stored; when i build the app in my device , the file isn’t created.
The debug don’t give me any error but don/t save anything.
Can you help me?
Thanks so much and sorry for my english.

-(void)saveXML:(NSString*)name:(float)x:(float)y:(float)z{

    NSMutableData *data = [NSMutableData data];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver setOutputFormat:NSPropertyListXMLFormat_v1_0];
    [archiver encodeFloat:x forKey:@"x"];
    [archiver encodeFloat:y forKey:@"y"];
    [archiver encodeFloat:z forKey:@"z"];
    [archiver encodeObject:name forKey:@"name"];
    [archiver finishEncoding];
    BOOL result = [data writeToFile:@"XML Position" atomically:YES];
    if(result)
        [self   updateTextView:@"success"];
    [archiver release];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:36:36+00:00Added an answer on May 15, 2026 at 12:36 am

    You can’t write to the current working directory in the iPhone because you are running in a sandbox. Also, you should check the value of result. If it is ever NO, then your write failed. Instead, you have to find the documents directory and write your files there:

    -(void)saveXML:(NSString*)name:(float)x:(float)y:(float)z{
    
        NSMutableData *data = [NSMutableData data];
        NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
        [archiver setOutputFormat:NSPropertyListXMLFormat_v1_0];
        [archiver encodeFloat:x forKey:@"x"];
        [archiver encodeFloat:y forKey:@"y"];
        [archiver encodeFloat:z forKey:@"z"];
        [archiver encodeObject:name forKey:@"name"];
        [archiver finishEncoding];
        NSString* filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"XML Position"];
        BOOL result = [data writeToFile:filePath atomically:YES];
        if(result)
            [self   updateTextView:@"success"];
        [archiver release];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with this code right here: - (void)fetchedData:(NSData *)responseData { //parse
I have a problem with my code. I want to create a XML file
I have a problem with the splitviewcontroller. I have the code below and when
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have problem with TableView its empty. In (.h) file: @interface TableViewController : UITableViewController{
im new with objective-c. I have problem with memory leaking when developing iphone app.
I have a problem. My proget create a xml file. In the iPhone this
I have problem with this code, it's working on debug environment. On the instruments
I have a problem with my code that for the life of me I
I have a problem converting a File Blob comming from a Webservice to an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.