Getting an error in BNRItemStore init


#1

I cannot even tell what the problem is, I am getting a breakpoint error when I try to build at:

    context=[[NSManagedObjectContext init]alloc];

If anyone can help me out I would really appreciate it. Thanks much!

I am posting my whole m file:

//
// BNRItemStore.m
// Homepwner
//
// Created by
// Copyright © 2012 MyCompanyName. All rights reserved.
//

#import “BNRItemStore.h”
#import “BNRItem.h”
#import “BNRImageStore.h”

@implementation BNRItemStore

  • (BNRItemStore *)sharedStore;
    {

    //Note we want to make this class a singleton, which will only allow a single instance

    //Note static means it’s not destroyed in the stack
    static BNRItemStore *sharedStore=nil;

    if(!sharedStore){
    sharedStore=[[super allocWithZone:nil] init];
    }
    return sharedStore;

}

+(id)alllocWithZone:(NSZone *)zone;
{

//*************NOTE THIS IS WHAT MAKES IT SINGLETON, when ALLOCATED, IT WILL RETURN ITS SINGLE INSTANCE
return [self sharedStore];

}

-(id)init;
{

//overide init to allocate a mutalbe array to allItesm
self=[super init];
if(self){
    
    //read in homepwner.xcdatamodeled
    model=[NSManagedObjectModel mergedModelFromBundles:nil];
    
    NSPersistentStoreCoordinator *psc=[[NSPersistentStoreCoordinator alloc]initWithManagedObjectModel:model];
    
    //where does the sql lite file go?
    
    NSString *path=[self itemArchivePath];
    
    NSURL *storeURL=[NSURL fileURLWithPath:path];
    
    NSError *error=nil;
    
    if(![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
         {
             [NSException raise:@"open failed" format:@"Reason: %@",[error localizedDescription]];
             
         }
    
    
    //create the managed object context
    context=[[NSManagedObjectContext init]alloc];
    [context setPersistentStoreCoordinator:psc];
    
    //The managed object context can manage undo, but we don't need it
    [context setUndoManager:nil];
    
    [self loadAllItems];
    
    
    
    
}
return self;

}

-(NSArray *)allItems;
{
return allItems;

}

-(BNRItem *)createItem;
{
//BNRItem *p=[BNRItem randomItem];
BNRItem *p=[[BNRItem alloc]init];

[allItems addObject:p];

return p;

}

-(void)removeItem:(BNRItem *)p;
{

NSString *key=[p imageKey];
[[BNRImageStore sharedStore]deleteImageForKey:key];

[allItems removeObjectIdenticalTo:p];

}

-(void)moveItemAtIndex:(int) from toIndex:(int) to;
{

if(from==to){
    return;
}

//Get pointer to item being moved so we can insert it
BNRItem *p=[allItems objectAtIndex:from];

//Remove p from array
[allItems removeObjectIdenticalTo:p];

//Insert p in new location
[allItems insertObject:p atIndex:to];

}

-(NSString *)itemArchivePath;
{
NSArray *documentDirectories=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

//get one and only one document directory from that list

NSString *documentDirectory=[documentDirectories objectAtIndex:0];

return [documentDirectory stringByAppendingPathComponent:@"store.data"];

}

-(BOOL)saveChanges;
{
NSError *err=nil;
BOOL successful=[context save:&err];

if(!successful)
{
    NSLog(@"Error saving: %@",[err localizedDescription]);
          
}
          return successful;

}

-(void)loadAllItems;
{
if(!allItems)
{
NSFetchRequest *request=[[NSFetchRequest alloc]init];

    NSEntityDescription *e=[[model entitiesByName]objectForKey:@"BNRItem"];
    
    [request setEntity:e];
    
    NSSortDescriptor *sd=[NSSortDescriptor sortDescriptorWithKey:@"orderingValue" ascending:YES];
    
    [request setSortDescriptors:[NSArray arrayWithObject:sd]];
    
    NSError *error;
    
    NSArray *result=[context executeFetchRequest:request error:&error];
    
    if(!result)
    {
        [NSException raise:@"Fetch failed" format:@"Reason: %@",[error localizedDescription]];
        
    }
    
    allItems =[[NSMutableArray  alloc]initWithArray:result];
    
    
    
    
}

}

@end


#2

Never mind, I am a moron!

I had the init before Alloc.

sorry.