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 6887249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:51:43+00:00 2026-05-27T05:51:43+00:00

I have an info dictionary that contains user data. Currently, it is written to

  • 0

I have an info dictionary that contains user data. Currently, it is written to an xml file in the same directory as the app. However, I’m pretty certain cocoa allows me to write this xml file into the application bundle or some Resources directory within the app.

Can someone teach me how to do this?

  • 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-27T05:51:44+00:00Added an answer on May 27, 2026 at 5:51 am

    You would want to use NSFileManager to createFileAtPath:contents:attributes: in the NSDocumentDirectory (relative to your bundle this is /Documents) with the NSData of your xml file.
    Something like this:

    NSString *myFileName = @"SOMEFILE.xml";
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    // This will give the absolute path of the Documents directory for your App
    NSString *docsDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    
    // This will join the Documents directory path and the file name to make a single absolute path (exactly like os.path.join, if you python)
    NSString *xmlWritePath = [docsDirPath stringByAppendingPathComponent:myFileName];
    
    // Replace this next line with something to turn your XML into an NSData
    NSData *xmlData = [[NSData alloc] initWithContentsOfURL:@"http://someurl.com/mydoc.xml"];
    
    // Write the file at xmlWritePath and put xmlData in the file.
    BOOL created = [fileManager createFileAtPath:xmlWritePath contents:xmlData attributes:nil];
    if (created) {
        NSLog(@"File created successfully!");
    } else {
        NSLog(@"File creation FAILED!");
    }
    
    // Only necessary if you are NOT using ARC and you alloc'd the NSData above:
    [xmlData release], xmlData = nil;
    

    Some references:

    NSFileManager Reference Docs
    NSData Reference Docs


    Edit

    In response to your comments, this would be typical usage of NSUserDefaults to save serializable data between App runs:

    // Some data that you would want to replace with your own XML / Dict / Array / etc
    NSMutableDictionary *nodeDict1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"object1", @"key1", nil];
    NSMutableDictionary *nodeDict2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"object2", @"key2", nil];
    NSArray *nodes = [NSArray arrayWithObjects:nodeDict1, nodeDict2, nil];
    
    // Save the object in standardUserDefaults
    [[NSUserDefaults standardUserDefaults] setObject:nodes forKey:@"XMLNODELIST"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    

    To retrieve a saved value (next time the App is launched, or from another part of the App, etc):

    NSArray *xmlNodeList = [[NSUserDefaults standardUserDefaults] arrayForKey:@"XMLNODELIST"];
    

    NSUserDefaults Reference Docs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dictionary object that I am pulling data out of. The field
I have file which contains some data, like this 2011-01-02 100100 1 2011-01-02 100200
I have a function that updates data in a cache (implemented as a dictionary).
I've got my autocomplete plugin working perfectly... except I have certain info that I
datetime.datetime.utcnow() Why does this datetime not have any timezone info given that it is
I have a base class for some kind of user controls, and in that
I have had an app rejected by Apple stating that I need to implement
I am building an app that uses a UPC data base API. I am
I have static class that holds some info public static class SampleDataCache { private
I have text file as follows: HEADER INFO Last1, First1 Movie1 (1991) random stuff

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.