Error on application start

0

I am very new to Xcode. I followed an example on YouTube but I am getting the following error on launch of the app

2014-05-16 20:45:02.378 CoreData[9335:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Patient''
*** First throw call stack:
(
    0   CoreFoundation                      0x01b5a1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x018d98e5 objc_exception_throw + 44
    2   CoreData                            0x00238a1b +[NSEntityDescription entityForName:inManagedObjectContext:] + 251
    3   CoreData                            0x00004235 -[PatientsTableViewController fetechResultsController] + 213
    4   CoreData                            0x00003bd1 -[PatientsTableViewController viewDidLoad] + 97
    5   UIKit                               0x006b833d -[UIViewController loadViewIfRequired] + 696
    6   UIKit                               0x006b85d9 -[UIViewController view] + 35
    7   UIKit                               0x006e3509 -[UINavigationController rotatingSnapshotViewForWindow:] + 52
    8   UIKit                               0x00a2ae3c -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 420
    9   UIKit                               0x005dfc22 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 1495
    10  UIKit                               0x005df646 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
    11  UIKit                               0x005df518 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
    12  UIKit                               0x005df5a0 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
    13  UIKit                               0x005de63a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
    14  UIKit                               0x005de59c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
    15  UIKit                               0x005df2f3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
    16  UIKit                               0x005e28e6 -[UIWindow setDelegate:] + 449
    17  UIKit                               0x006bcb77 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
    18  UIKit                               0x005d8474 -[UIWindow addRootViewControllerViewIfPossible] + 591
    19  UIKit                               0x005d85ef -[UIWindow _setHidden:forced:] + 312
    20  UIKit                               0x005d886b -[UIWindow _orderFrontWithoutMakingKey] + 49
    21  UIKit                               0x005e33c8 -[UIWindow makeKeyAndVisible] + 65
    22  UIKit                               0x00593bc0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 2097
    23  UIKit                               0x00598667 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
    24  UIKit                               0x005acf92 -[UIApplication handleEvent:withNewEvent:] + 3517
    25  UIKit                               0x005ad555 -[UIApplication sendEvent:] + 85
    26  UIKit                               0x0059a250 _UIApplicationHandleEvent + 683
    27  GraphicsServices                    0x03a0df02 _PurpleEventCallback + 776
    28  GraphicsServices                    0x03a0da0d PurpleEventCallback + 46
    29  CoreFoundation                      0x01ad5ca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    30  CoreFoundation                      0x01ad59db __CFRunLoopDoSource1 + 523
    31  CoreFoundation                      0x01b0068c __CFRunLoopRun + 2156
    32  CoreFoundation                      0x01aff9d3 CFRunLoopRunSpecific + 467
    33  CoreFoundation                      0x01aff7eb CFRunLoopRunInMode + 123
    34  UIKit                               0x00597d9c -[UIApplication _run] + 840
    35  UIKit                               0x00599f9b UIApplicationMain + 1225
    36  CoreData                            0x00002efd main + 141
    37  libdyld.dylib                       0x021a1701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)        

This is how I am defining the function but I cant see anywhere its getting nill from?

-(NSFetchedResultsController*)fetechResultsController{

if (_fetechResultsController !=nil) {
    return  _fetechResultsController;
}
NSFetchRequest  *fetchRequest=[[NSFetchRequest alloc] init];
NSManagedObjectContext *context =[self managedObjectContext];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Patient" inManagedObjectContext:context];
[fetchRequest setEntity:entity];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]initWithKey:@"patientLastName" ascending:YES];
NSArray *sortdescriptors = [[NSArray alloc]initWithObjects:sortDescriptor, nil];

fetchRequest.sortDescriptors = sortdescriptors;

_fetechResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];

_fetechResultsController.delegate   =self;

return _fetechResultsController;

}
ios
objective-c
core-data
crash
asked on Stack Overflow May 16, 2014 by rogue39nin • edited May 17, 2014 by Lorenzo B

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0