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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:59:18+00:00 2026-05-28T04:59:18+00:00

Here is some code that I’m trying to make save some UITextView text. When

  • 0

Here is some code that I’m trying to make save some UITextView text. When I run it and change the text and click the save button it works but when I take it from the multitasking bar it and open it back up, it crashes. Whats wrong?

- (NSString *)saveFilePath
{
    NSLog(@"saveFilePath");

    NSArray *path =
    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    return [[path objectAtIndex:0] stringByAppendingPathComponent:@"savefile.plist"];

}

(The save file.plist is on my project file)
view did load

- (void)viewDidLoad
{
NSString *myPath = [self saveFilePath];

    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath];

    if (fileExists)
    {
        NSLog(@"file Exsists");

        NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath];
        notesTextView.text = [values objectAtIndex:0];
    }

}

Save data button:

NSArray *values = [[NSArray alloc] initWithObjects:notesTextView.text, nil];
    [values writeToFile:[self saveFilePath] atomically:YES];

Any help appreciated.

  • 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-28T04:59:18+00:00Added an answer on May 28, 2026 at 4:59 am

    The only place in the code you’ve posted that could cause a crash is the line:

    notesTextView.text = [values objectAtIndex:0];
    

    If the array is empty (has zero items in it) this will crash with an array out of bounds error. I suggest you put:

    if ([values count] > 0)
    {
        notesTextView.text = [values objectAtIndex:0];
    }
    

    And see if your crash goes away.

    In an unrelated note, you can actually simplify your code quite a bit by taking out the “if (fileExists)” part by just using [NSArray arrayWithContentsOfFile:…] which safely returns nil if the file doesn’t exist.

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

Sidebar

Related Questions

I've got some code here that works great on IPv4 machines, but on our
Here is some code that checks if a radio button is disabled. How do
Here is some code that I can't seem to understand how it works. I
Here is some code that i know works: require 'csv' class Motorcycle attr_reader :name,
I have some code that is using SyncEnumerator. As you can see here ,
So I have some PHP code that looks like: $message = 'Here is the
Given some JS code like that one here: for (var i = 0; i
Here's the situation: We have some generic graphics code that we use for one
Here's some example code: class Obj attr :c, true def == that p '=='
We have some old C code here that's built with nmake. Is there 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.