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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:02:03+00:00 2026-06-05T01:02:03+00:00

I am trying to run some sample code and am having trouble creating and

  • 0

I am trying to run some sample code and am having trouble creating and saving to a file.

Here is my code:

-(IBAction) example
{
    NSFileManager *fm = [[NSFileManager alloc] init];
    NSURL *docsurl = [fm URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask  appropriateForURL:nil create:YES error:nil];
    myfolder = [docsurl URLByAppendingPathComponent:@"MyFolder"];
    NSError * err = nil;
    BOOL ok = [fm createDirectoryAtURL:myfolder withIntermediateDirectories:YES attributes:nil error:&err];
    ok = [label.text writeToURL:myfolder atomically:YES encoding:NSUTF8StringEncoding error:nil];       
}

-(IBAction) load
{
    label2.text = [[NSString alloc] initWithContentsOfURL:myfolder
    encoding:NSUTF8StringEncoding error:nil];
}

I want it to save the first label’s text to the file when I push the first button. When I push the second button, I want it to read what is in the file and make the second label text that. However when I push the second button, the second label just goes blank.
Any suggestions?

  • 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-06-05T01:02:07+00:00Added an answer on June 5, 2026 at 1:02 am

    I suggest actually using those NSError objects. I also suggest using the default NSFileManager.

    -(IBAction) example
    {
        NSFileManager *fm = [NSFileManager defaultManager];
        NSError *error;
        NSURL *docsurl = [fm URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask  appropriateForURL:nil create:YES error:&error];
        myfolder = [docsurl URLByAppendingPathComponent:@"MyFolder"];
        NSError * err = nil;
    
        if ([fm createDirectoryAtURL:myfolder withIntermediateDirectories:YES attributes:nil error:&err]) {
            if ([label.text writeToURL:myfolder atomically:YES encoding:NSUTF8StringEncoding error:&err]) {
    
            }
            else {
                NSLog(@"%@", err);
            }
        }
        else {
            NSLog(@"%@", err);
        }
    
    
    }
    
    -(IBAction) load
    {
        NSError *err;
        if ([[NSString alloc] initWithContentsOfURL:myfolder
        encoding:NSUTF8StringEncoding error:&err]) {
            label2.text = [[NSString alloc] initWithContentsOfURL:myfolder
        encoding:NSUTF8StringEncoding error:nil];
        }
        else {
            NSLog(@"%@", err);
        }
    }
    

    This code will not work as is, but it will print out whatever errors you are encountering which should help you solve the problem.

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

Sidebar

Related Questions

I am trying to run some of the sample example code from CGAL as
I am newbie with JPA. I'm trying to run some sample code using JPA
I'm having some trouble with this code. I am trying to write a function
I am trying to run some sample code from the book Accelerated C++ (A.
Ultimately I am trying to run some code which depends on the value (or
I am trying to run some Scala code on my OSX machine and keep
I'm a student, and I'm trying to write and run some test code for
I'm having some trouble installing and configuring qt on my vista laptop. I'm trying
I'm having some trouble with NHibernate, while trying to remove an object describing a
I'm having a really strange problem. I'm trying to download some file and store.

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.