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

  • Home
  • SEARCH
  • 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 7652063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:40:05+00:00 2026-05-31T11:40:05+00:00

While running this code: NSData *archivedSavedData = [[NSData alloc] init]; archivedSavedData = [defaults objectForKey:@listOfAccessNumbers];

  • 0

While running this code:

NSData *archivedSavedData = [[NSData alloc] init];    
archivedSavedData = [defaults objectForKey:@"listOfAccessNumbers"];
NSLog(@"archivedSavedData length is %d", [archivedSavedData length] );

I am getting this crash error (last line) only when running on a device that is connected:

[__NSCFArray length]: unrecognized selector sent to instance 0x2398a0
2012-03-13 20:25:33.088[7301:707] * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFArray length]: unrecognized selector sent to instance 0x2398a0’
*
First throw call stack:
(0x34dbc88f 0x361e3259 0x34dbfa9b 0x34dbe915 0x34d19650 0xccb1b 0x31e13e33 0x31e38629 0x31dfcd7d 0x31ebf4dd 0x31e0555d 0x31e05579 0x31e0540b 0x31e053e7 0xcfedf 0x31e12e53 0x31e0c985 0x31ddac6b 0x31dda70f 0x31dda0e3 0x3600f22b 0x34d90523 0x34d904c5 0x34d8f313 0x34d124a5 0x34d1236d 0x31e0ba13 0x31e08e7d 0xcfd39 0xcbe28)
terminate called throwing an exception

This doesn’t happen when running on the simulator or directly on the device with a distribution profile (through testflight for example).

Does anyone know how such a behavior could happen only in this case?

Thanks.

UPDATE: when trying to replace length with count I get this complication error: “No visible @interface for ‘NSData’ declares the selector ‘count'”

UPDATE2: I understand that it should be an NSArray rather than an NSData, but my problem is that I did store archived NSData cause my array consists of custom objects, so I had to archived this data into NSData format when saving in NSUserDefault. How else should I approach that otherwise?

Thats how I store the data:

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:array];
   [defaults setObject:data forKey:@"listOfAccessNumbers"];  

array is an array of custom objects of the form of:

@interface NumberDataObj : NSObject {

    NSString *inputName;
    NSString *inputNum;

}
  • 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-31T11:40:06+00:00Added an answer on May 31, 2026 at 11:40 am

    The error message says:

    -[__NSCFArray length]: unrecognized selector sent to instance
    

    That means that archivedSavedData is an array and that it doesn’t (obviously) respond to length so you should declare archivedSavedData as an array and use count instead.

    NSArray *archivedSavedData = [defaults objectForKey:@"listOfAccessNumbers"];
    NSLog(@"archivedSavedData length is %d", [archivedSavedData count]);
    

    Now, as to why this doesn’t happen when running on the simulator, my guess is that your test scenarios don’t make this part of the code get called.

    EDIT

    If you want to retrieve the data as NSData then use the method dataForKey:

    NSData *archivedSavedData = [defaults dataForKey:@"listOfAccessNumbers"];
    NSLog(@"archivedSavedData length is %d", [archivedSavedData length]);
    

    The documentation says for dataForKey:

    Return Value
    The data object associated with the specified key, or nil if the key does not exist or its value is not an NSData object.

    and for arrayForkey:

    Return Value
    The array associated with the specified key, or nil if the key does not exist or its value is not an NSArray object.

    So aways use the appropriate method when you know the type of the data to avoid problems like this.

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

Sidebar

Related Questions

I am getting a segmentation fault while running this code. I can't work out
While I am running this code it showing me a following error:- Column 'virtuemart_product_id'
I am getting this weird error while running cucumber test: ERROR Mongo::OperationFailure: Database command
While running this code it shows Stackoverflow error. What is it I am doing
This code compiles fine but give segmentation fault error while running? Can anyone tell
While running this code it shows alert. filtereditem is DevExpress listboxcontrol. existingItems is an
while i am running this code an exception is occuring at <%Eval(Firstname)%>.. the exception
I'm running this code in php while ($row = mysql_fetch_array($result)) { $arr = array(joke
I'm learning C++ and I'm using Visual C++ Express and while running this #include
Been trying to get this up and running for a while now. Basically i

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.