0

SaveNotes *saveNotes = [[SaveNotes alloc]initWithTitleString:title descrString:descr]; [titleDescrObjects addObject:saveNotes]; [saveNotes release];

from the above code i have saved title,descr to a class SaveNotes , and then i have stored that object in my NSMutableArray -> titleDescrObjects, Its working fine,

i need to get particular objects "descr" alone,

how to get the descr from objectAtIndex:i

i am trying

for (int i=0; i<[titleDescrObjects count]; i++)
{   
  NSLog(@"\n ((%@))\n",[titleDescrObjects objectAtIndex:i].descr); 
}

Thanks in advance,

1 Answer 1

1

-objectAtIndex: returns an id. Since an id can be of any Objective-C class, the compiler cannot associate the property .descr into a getter, which is why it chooses not to make it valid at all.

There are 3 ways to fix it.

  1. Use a getter: [[titleDescrObjects objectAtIndex:i] descr]

  2. Cast into a SaveNotes: ((SaveNotes*)[titleDescrObjects objectAtIndex:i]).descr

  3. Use fast enumeration. This is the recommended method.

    for (SaveNotes* notes in titleDescrObjects) {
       NSLog(@"\n ((%@))\n", notes.descr); 
    }
    
Sign up to request clarification or add additional context in comments.

2 Comments

excellent Kenny , its worked for case 2,3 , thank you very much. but its not working for case 1.
@mac: Maybe your getter of the property .descr isn't -descr.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.