Finding the size of an NSArrayController?

Discussion in 'Mac Programming' started by Littleodie914, Mar 22, 2007.

  1. macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #1
    Hey guys, pretty simple question, I've got an NSArrayController, and I'm trying to somehow get the size of it. Right now I'm trying:

    [[stepsController arrangedObjects] count]

    But it's returning 0. Any ideas? Thanks! :)
     
  2. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    Dunno, seems like that should work, and I'm pretty sure I'm using exactly that code in one of my projects. Are you absolutely certain you have more than 0 objects being controlled by the controller? Are you maybe using Core Data (where "count" possibly doesn't reflect objects that haven't been fetched from the data store yet)?
     
  3. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #3
    Thats what I use too... Try checking the filter predicate is nil, then if it's still nil fetch the objects from the data store (Core Data only), see the following code.
    Code:
    	[arrayController setFilterPredicate:nil];
    	if([[arrayController arrangedObjects] count]==0){
    		//NSLog(@"no objects");//may be worth uncommenting this.
    		[arrayController addObjects:[mObjC executeFetchRequest:[model fetchRequestFromTemplateWithName:@"yourObject"  substitutionVariables:[NSDictionary dictionary]]
    															 error:nil]];
    	}
    
    EDIT: mObjC is the managedObjectContext and model is the managedObjectModel
     

Share This Page