1

i have a model (core data) set up, called Animals. i have to access this in a specific order and to do so i use the code listed below. what am i supposed to type instead of the XXXXXXXXX in the for loop?

NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"order" ascending:YES];
NSArray *sortedArray = [animalscontroller.arrangedObjects sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
for (XXXXXXXX *a in sortedArray)
{

...........    

}

i have been told that i have to put the name of the model, so in this case "Animals" but that gives me an error saying that the variable Animals is not declared. i am pretty green on cocoa programming.

thank you

Best regards

Igor

sharkyenergy
  • 3,842
  • 10
  • 46
  • 97

1 Answers1

2

"Animals" is your entity name, not your class name. Unless you've specified that "Animals" has a custom class, the class name you want here is NSManagedObject, or you can just use id.

iluvcapra
  • 9,436
  • 2
  • 30
  • 32
  • 1
    thank you! mind telling me also how i could access the value "header" of my model inside the for loop? a.managedObjectModel.header? or something like that? – sharkyenergy Jan 30 '13 at 18:45
  • 1
    If you're casting to an `id` or `NSManagedObject`, you can use `valueForKey:`. If you want to be able to use the dot-notation to access the properties, you have to either declare them in a subclass or add them as a category to `NSManagedObject`... read this: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html#//apple_ref/doc/uid/TP40002154-SW7 – iluvcapra Jan 30 '13 at 18:50
  • yayyyyyyy it worked! thank you very much! :) you deffinetly made my day... :) – sharkyenergy Jan 30 '13 at 18:56