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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:25:21+00:00 2026-06-06T17:25:21+00:00

I came to notice that executing a for/in operation in objective c on an

  • 0

I came to notice that executing a for/in operation in objective c on an initialized empty NSMutableArray was not working as expected.

Simplified code is :

+(void) convertArray: (NSMutableArray*)arrayIN {

    NSMutableArray *arrayOUT = [NSMutableArray array];

    NSLog(@"is nil %d - count %d", !arrayIN, [arrayIN count]);

    for(NSObject *o in arrayIN)
        [arrayOUT addObject:[o convertToAnotherClass]];

}

Actual code is :

+(BOOL) writeTasks: (NSArray*)tasksArray {

    NSMutableArray *arr = [NSMutableArray array];
    NSLog(@"is nil %d - count %d", !arr, [arr count]);
    for(Task *t in tasksArray)
        [arr addObject:[t getDictionary]];

    NSError *error; 
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:&error];

    if (! jsonData) {
        NSLog(@"Got an error: %@", error);
        return NO;
    } else {
        //NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        [jsonData writeToFile:path options:NSDataWritingAtomic error:nil];
        return YES;
    }
}

the suprising thing is that executing [dummyClass convertArray:[NSMutableArray array]] is showing this :

2012-06-25 13:51:34.236 Planorama[740:707] is nil 0 - count 0
2012-06-25 13:51:34.239 Planorama[740:707] -[__NSArrayM convertToAnotherClass]: unrecognized selector sent to instance 0xde9b580
(lldb) 

Why ? arrayIN is empty, why is convertToAnotherClass even called ?

  • 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-06T17:25:24+00:00Added an answer on June 6, 2026 at 5:25 pm

    if you use the block based enumeration it will work the way you want.
    Also, the output indicates that o is set to some instance of something, so you may have another problem.

    Elegant way to get all objects of a specific type in an Objective-C array

    Lastly, it looks like this is a static method, but your example calls it as an instance method.

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

Sidebar

Related Questions

It came to my notice that a TreeSet doesn't keep the mutable objects in
Well, I am trying to get Java3D working in Scala. I came to notice
I have experimented with both of these loops and came to notice that even
I was working again with C++ during the weekend and came to notice something
I recently upgraded from php4 to php5 and with it came the notice that
Came across this code: <?php require_once 'HTTP/Session/Container/DB.php'; $s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db'); ini_get('session.auto_start') or session_start();
Came by a curious case today, that got me thinking about how the object
I came across this Linq to Sql code in an application I am maintaining:
I came across a piece of code which looks like this: jQuery(function($) { $('#saySomething').click(function()
I have some messages in my queue. Now I notice that after 3 tries

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.