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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:38:01+00:00 2026-05-27T14:38:01+00:00

Here is the code what I am trying.. but the thing is when I

  • 0

Here is the code what I am trying..

but the thing is when I load the view first time it works.. doesn’t give any problem..

but when i try to load view again and call this code.. it gives error on arrMain addObject:

I am trying to look over it but don’t find anything..

can anyone please help??

NSUserDefaults *ds = [NSUserDefaults standardUserDefaults];
NSMutableArray *arrMain = [ds objectForKey:@"files"];
int i;

if([arrMain count] > 0)
{
    i = [arrMain count] + 1;

}
else
{
    arrMain = [[NSMutableArray alloc] init];  
    i = 1;
}
NSLog(@"File Name To Be Saved %d.txt",i);

NSArray *sd = [[NSArray alloc] init];
sd = [dict componentsSeparatedByString:@"/"];
NSMutableDictionary *dict1 = [[NSMutableDictionary alloc] init];

[dict1 setObject:[sd objectAtIndex:[sd count] - 1] forKey:@"name"];
NSString *OrgFilename = [sd objectAtIndex:[sd count] - 1];
NSArray *extArr = [[NSArray alloc] init];
extArr = [OrgFilename componentsSeparatedByString:@"."];
NSString *flExt = [extArr    objectAtIndex:1];
[dict1 setObject:[NSString stringWithFormat:@"%d.txt",i,flExt] forKey:@"filename"];

// *** error happens VVVV
[arrMain addObject:dict1];
// *** error happens ^^^^

[ds setObject:arrMain forKey:@"files"];
[ds synchronize];
  • 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-27T14:38:02+00:00Added an answer on May 27, 2026 at 2:38 pm

    The problem is you are trying to retrieve a NSMutableArray from the NSUserDefaults. It will not be returning a NSMutableArray, but a NSArray instead. You will want to do:

    NSMutableArray *arrMain = [[[ds objectForKey:@"files"] mutableCopy] autorelease];
    

    The reason it “worked” the first time through was arrMain was nil, so you created a valid NSMutableArray, then saved it into the NSUserDefaults. After that, you got a valid object (non-nil), but it wasn’t the type you were expecting. Since -[NSUserDefaults objectForKey:] returns a id type, it happily assigned it your NSMutableArray object, even though it wasn’t that type.

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

Sidebar

Related Questions

I'm trying to solve the problem here but I don't know why my code
Trying to truncate some code here and running into a problem: <script type=text/javascript> $(function()
I am trying to get the code found here: http://snipplr.com/view/26643/mbprogresshud-with-an-asynchronous-nsurlconnection-call/ to work in my
I'm trying to make things simpler. Here is my code: If Threading.Monitor.TryEnter(syncRoot) Then Try
I'm trying to parse a view with BBCode, and it works fine. But there
I am trying to reduce some code here. I will explain how I have
I am trying to test some of these code here http://ha.ckers.org/xss.html on my code.
I am trying to reuse Apple's Speak Here sample code in my own iPhone
I am trying to install MySQLdb package. I found the source code here .
I'm trying to update an element in the XML document below: Here's the code:

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.