iPhone crash on CoreData save - iphone

This is a different situation than this question, as the solution provided doesn't work and the stack is different.
Periodical crash when I save data using coredata.
The stack trace isn't 100% clear on where this is happening, but I'm certain it's this routine that's being called. It's either the save: in this method or the one following.
Code:
-(void)saveWine {
if ([self validInfo]) {
Wine *wine = (Wine *)wineToEdit;
if (wine == nil) {
wine = (Wine *)[NSEntityDescription insertNewObjectForEntityForName:#"Wine" inManagedObjectContext:self.managedObjectContext];
}
wine.uuid = [Utils createUUID];
wine.name = self.wineNameField.text;
wine.vineyard = self.vineyardField.text;
wine.vintage = [[self numberFormatter] numberFromString:self.vintageField.text];
wine.timeStamp = [NSDate date];
wine.rating = [NSNumber numberWithInt:self.ratingControl.selectedSegmentIndex];
wine.partnerRating = [NSNumber numberWithInt:self.partnerRatingControl.selectedSegmentIndex];
wine.varietal = self.currentVarietal;
wine.tastingNotes = self.currentTastingNotes;
wine.dateTasted = self.currentDateTasted;
wine.tastingLocation = [[ReferenceDataAccessor defaultReferenceDataAccessor] addEntityForType:TASTING_LOCATION
withName:self.currentWhereTasted];
id type = [[ReferenceDataAccessor defaultReferenceDataAccessor] entityForType:WINE_TYPE
withOrdinal:self.typeControl.selectedSegmentIndex];
wine.type = type;
NSError *error;
NSLog(#"Saving %#",wine);
if (![self.managedObjectContext save:&error]) {
[Utils showAlertMessage:#"There was a problem saving your wine; try restarting the app" withTitle:#"Problem saving"];
NSLog(#"Error while saving new wine %#, %#", error, [error userInfo]);
}
}
else {
NSLog(#"ERROR - someone is calling saveWine with invalid info!!");
}
}
Code for addEntityForType:withName::
-(id)addEntityForType:(NSString *)type withName:(NSString *)name {
if ([Utils isStringBlank:name]) {
return nil;
}
id existing = [[ReferenceDataAccessor defaultReferenceDataAccessor] entityForType:type withName:name];
if (existing != nil) {
NSLog(#"%# with name %# already exists",type,name);
return existing;
}
NSManagedObject *newEntity = [NSEntityDescription insertNewObjectForEntityForName:type
inManagedObjectContext:self.managedObjectContext];
[newEntity setValue:name forKey:#"name"];
NSError *error;
if (![self.managedObjectContext save:&error]) {
[Utils showAlertMessage:[NSString stringWithFormat:#"There was a problem saving a %#",type] withTitle:#"Database Probem"];
[Utils logErrorFully:error forOperation:[NSString stringWithFormat:#"saving new %#",type ]];
}
return newEntity;
}
Stack trace:
Thread 0 Crashed:
0 libSystem.B.dylib 0x311de2d4 __kill + 8
1 libSystem.B.dylib 0x311de2c4 kill + 4
2 libSystem.B.dylib 0x311de2b6 raise + 10
3 libSystem.B.dylib 0x311f2d72 abort + 50
4 libstdc++.6.dylib 0x301dea20 __gnu_cxx::__verbose_terminate_handler() + 376
5 libobjc.A.dylib 0x319a2594 _objc_terminate + 104
6 libstdc++.6.dylib 0x301dcdf2 __cxxabiv1::__terminate(void (*)()) + 46
7 libstdc++.6.dylib 0x301dce46 std::terminate() + 10
8 libstdc++.6.dylib 0x301dcf16 __cxa_throw + 78
9 libobjc.A.dylib 0x319a14c4 objc_exception_throw + 64
10 CoreData 0x3526e83e -[NSManagedObjectContext save:] + 1098
11 Wine Brain 0x0000651e 0x1000 + 21790
12 Wine Brain 0x0000525c 0x1000 + 16988
13 Wine Brain 0x00004894 0x1000 + 14484
14 Wine Brain 0x00008716 0x1000 + 30486
15 CoreFoundation 0x31477fe6 -[NSObject(NSObject) performSelector:withObject:withObject:] + 18
16 UIKit 0x338c14a6 -[UIApplication sendAction:to:from:forEvent:] + 78
17 UIKit 0x3395c7ae -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 86
18 CoreFoundation 0x31477fe6 -[NSObject(NSObject) performSelector:withObject:withObject:] + 18
19 UIKit 0x338c14a6 -[UIApplication sendAction:to:from:forEvent:] + 78
20 UIKit 0x338c1446 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
21 UIKit 0x338c1418 -[UIControl sendAction:to:forEvent:] + 32
22 UIKit 0x338c116a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 350
23 UIKit 0x338c19c8 -[UIControl touchesEnded:withEvent:] + 336
24 UIKit 0x338b734e -[UIWindow _sendTouchesForEvent:] + 362
25 UIKit 0x338b6cc8 -[UIWindow sendEvent:] + 256
26 UIKit 0x338a1fc0 -[UIApplication sendEvent:] + 292
27 UIKit 0x338a1900 _UIApplicationHandleEvent + 5084
28 GraphicsServices 0x35d66efc PurpleEventCallback + 660
29 CoreFoundation 0x314656f8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20
30 CoreFoundation 0x314656bc __CFRunLoopDoSource1 + 160
31 CoreFoundation 0x31457f76 __CFRunLoopRun + 514
32 CoreFoundation 0x31457c80 CFRunLoopRunSpecific + 224
33 CoreFoundation 0x31457b88 CFRunLoopRunInMode + 52
34 GraphicsServices 0x35d664a4 GSEventRunModal + 108
35 GraphicsServices 0x35d66550 GSEventRun + 56
36 UIKit 0x338d5322 -[UIApplication _run] + 406
37 UIKit 0x338d2e8c UIApplicationMain + 664
38 Wine Brain 0x000021ba 0x1000 + 4538
39 Wine Brain 0x00002184 0x1000 + 4484
I have no idea why my app's memory locations aren't being symbolocated, but the code paths lead to only two manavedObjectContext save: calls. The time this happend, addEntityForType was called all the way through, creating a new object for the "whereTasted" entity, before the final save: on the entire wine object.
When I go through the same procedure again, it works fine. This leads me to believe it's something to do with the app having been run for a while when adding a new location, but I'm not sure.
Any thoughts on how I can debug this and get more info the next time this happens?

put #try - #catch around your save calls. There seems to be an exception thrown while saving:
9 libobjc.A.dylib 0x319a14c4 objc_exception_throw + 64
Sample:
#try
{
if (![self.context save:&error]) {
[[NSApplication sharedApplication] presentError:error];
}
#catch (NSException * e)
{
NSLog(#"exception saving: %#", e);
abort();
}

You should try to activate "Run > Stop on Objective-C exception". It allowed me to find the place where there was an access to an object turned into fault which was the root cause of the problem. (This was advice that recently worked very well for me. Thanks to Kamchatka.)

Related

FBSession.m Crashes in iOS6.0 with FacebookSdk.framework

I am using new FacebookSdk and My app is crashing when running in iOS 6.0.Here is crash log
*** Assertion failure in -[FBSession close], /Users/jacl/src/release/ios-sdk/src/FBSession.m:404
2012-12-12 12:48:49.993 localfave[1406:1d903] uncaughtExceptionHnadler -- Exception FBSession: should only be used from a single thread
2012-12-12 12:48:49.996 test[1406:1d903] Stack trace: (
0 CoreFoundation 0x02d6b02e __exceptionPreprocess + 206
1 libobjc.A.dylib 0x01cd6e7e objc_exception_throw + 44
2 CoreFoundation 0x02d6ae78 +[NSException raise:format:arguments:] + 136
3 Foundation 0x0176cf35 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 localfave 0x000f6e1d -[FBSession close] + 177
5 localfave 0x000f753e +[FBSession setActiveSession:] + 50
6 localfave 0x000fa6ee +[FBSession openActiveSessionWithPermissions:allowLoginUI:allowSystemAccount:isRead:defaultAudience:completionHandler:] + 230
7 test 0x000f7408 +[FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler:] + 82
8 test 0x00002fc6 -[AppDelegate openSessionWithAllowLoginUI:] + 166
9 test 0x0008adc5 -[FacebookLoginViewController registerFacebook:] + 165
10 libobjc.A.dylib 0x01cea705 -[NSObject performSelector:withObject:withObject:] + 77
11 UIKit 0x00c21920 -[UIApplication sendAction:to:from:forEvent:] + 96
12 UIKit 0x00c218b8 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
13 UIKit 0x00ce2671 -[UIControl sendAction:to:forEvent:] + 66
14 UIKit 0x00ce2bcf -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 578
15 UIKit 0x00ce1d38 -[UIControl touchesEnded:withEvent:] + 546
16 UIKit 0x00c5133f -[UIWindow _sendTouchesForEvent:] + 846
17 UIKit 0x00c51552 -[UIWindow sendEvent:] + 273
18 UIKit 0x00c2f3aa -[UIApplication sendEvent:] + 436
19 UIKit 0x00c20cf8 _UIApplicationHandleEvent + 9874
20 GraphicsServices 0x03057df9 _PurpleEventCallback + 339
21 GraphicsServices 0x03057ad0 PurpleEventCallback + 46
22 CoreFoundation 0x02ce0bf5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
23 CoreFoundation 0x02ce0962 __CFRunLoopDoSource1 + 146
24 CoreFoundation 0x02d11bb6 __CFRunLoopRun + 2118
25 CoreFoundation 0x02d10f44 CFRunLoopRunSpecific + 276
26 CoreFoundation 0x02d10e1b CFRunLoopRunInMode + 123
27 GraphicsServices 0x030567e3 GSEventRunModal + 88
28 GraphicsServices 0x03056668 GSEventRun + 104
29 UIKit 0x00c1e65c UIApplicationMain + 1211
30 test 0x00002545 main + 213
31 test 0x00002425 start + 53
)
And Code is
/*
* Opens a Facebook session and optionally shows the login UX.
*/
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
return [FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
/*
* Callback for session changes.
*/
Please Help!
just write this code where you want to post on facebook and discard everyfunction that you have made for facebook integration and i think you have imported #import in .h file.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"ResultCancelled");
} else
{
NSLog(#"Success");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:#"Awesome App"];
[controller addImage:photoImage.image];
[self presentViewController:controller animated:YES completion:Nil];
}
let me know it is working or not....!!!
Happy Coding!!!!
Make sure you have Social, Accounts, AdSupport frameworks and they are optional.
Copy FacebookSDK.framework, FacebookSDKResources.bundle, FBUserSettingsViewResources.bundle.
They can be found on Facebook Developers for iOS web page. If the problem occurs again, try deleting all the frameworks and add them again. This is a framework problem, not with the code.

App crashes on device, however works fine on Simulator

My addressbook app works fine on Simulator. I have Contact Add feature.
On device(IOS 6) it get crashed.. with following message.
ContactPro[837] has active assertions beyond permitted time:
{(
<BKProcessAssertion: 0x1f5a28a0> identifier: Suspending process: ContactPro[837] permittedBackgroundDuration: 10.000000 reason: suspend owner pid:52 preventSuspend preventThrottleDownCPU preventThrottleDownUI )}
After that, many lines of information comes like this
Elapsed total CPU time (seconds): 10.030 (user 10.030, system 0.000), 100% CPU
Elapsed application CPU time (seconds): 3.724, 37% CPU
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libsystem_c.dylib 0x33be8b1e __vfprintf + 158
1 libsystem_c.dylib 0x33b93106 vsnprintf_l + 170
2 libsystem_c.dylib 0x33b9455c snprintf + 68
3 libsystem_c.dylib 0x33b968a6 asl_string_append_char_no_encoding + 102
4 libsystem_c.dylib 0x33b9694c asl_string_append_internal + 124
5 libsystem_c.dylib 0x33b96536 asl_msg_to_string_raw + 118
6 libsystem_c.dylib 0x33b95b06 _asl_send_message + 1018
7 CoreFoundation 0x380d417a __CFLogCString + 602
8 CoreFoundation 0x3807801e _CFLogvEx + 186
9 Foundation 0x3a13ed8a NSLogv + 82
10 Foundation 0x3a13ed2a NSLog + 22
11 ContactPro 0x000a7d38 0xa4000 + 15672
12 ContactPro 0x000a686e 0xa4000 + 10350
13 ContactPro 0x000b9dd0 0xa4000 + 89552
14 UIKit 0x37a6f590 -[UIViewController loadViewIfRequired] + 360
15 UIKit 0x37ac4136 -[UIViewController contentScrollView] + 22
16 UIKit 0x37ac407c -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 24
17 UIKit 0x37ac3f60 -[UINavigationController _layoutViewController:] + 28
18 UIKit 0x37ac3e84 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 268
19 UIKit 0x37ac35c4 -[UINavigationController _startTransition:fromViewController:toViewController:] + 60
20 UIKit 0x37ac34ac -[UINavigationController _startDeferredTransitionIfNeeded:] + 320
21 UIKit 0x37a944e4 -[UILayoutContainerView layoutSubviews] + 176
22 UIKit 0x37a53806 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 254
23 QuartzCore 0x36145d5e -[CALayer layoutSublayers] + 210
24 QuartzCore 0x361458fc CA::Layer::layout_if_needed(CA::Transaction*) + 456
25 QuartzCore 0x361747a2 -[CALayer layoutIfNeeded] + 138
26 UIKit 0x37afd0cc -[UIViewController window:setupWithInterfaceOrientation:] + 204
27 UIKit 0x37afc2b8 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 3616
28 UIKit 0x37afb48a -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 42
29 UIKit 0x37afb414 -[UIWindow _setRotatableViewOrientation:duration:force:] + 64
30 UIKit 0x37c3117c __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke_0 + 100
31 UIKit 0x37ab967e -[UIWindow _updateToInterfaceOrientation:duration:force:] + 214
32 UIKit 0x37ab93c0 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 688
33 UIKit 0x37ab8d2e -[UIViewController _tryBecomeRootViewControllerInWindow:] + 154
34 UIKit 0x37aafea6 -[UIWindow addRootViewControllerViewIfPossible] + 366
35 UIKit 0x37aabae8 -[UIWindow _setHidden:forced:] + 360
36 UIKit 0x37aed1cc -[UIWindow makeKeyAndVisible] + 56
37 ContactPro 0x000a5c88 0xa4000 + 7304
38 UIKit 0x37ab0ad4 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 248
39 UIKit 0x37ab065e -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1186
40 UIKit 0x37aa8846 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 694
41 UIKit 0x37a50c3c -[UIApplication handleEvent:withNewEvent:] + 1000
42 UIKit 0x37a506d0 -[UIApplication sendEvent:] + 68
43 UIKit 0x37a5011e _UIApplicationHandleEvent + 6150
44 GraphicsServices 0x35ce35a0 _PurpleEventCallback + 588
45 CoreFoundation 0x380bb680 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
46 CoreFoundation 0x380baee4 __CFRunLoopDoSources0 + 208
47 CoreFoundation 0x380b9cb2 __CFRunLoopRun + 642
48 CoreFoundation 0x3802ceb8 CFRunLoopRunSpecific + 352
49 CoreFoundation 0x3802cd44 CFRunLoopRunInMode + 100
50 UIKit 0x37aa7480 -[UIApplication _run] + 664
51 UIKit 0x37aa42fc UIApplicationMain + 1116
52 ContactPro 0x000a5864 0xa4000 + 6244
53 libdyld.dylib 0x36982b1c start + 0
Can anyone provide some tips as to how to solve it!
For accessing ADDRESS BOOK in IOS6, i am using following lines..
ABAddressBookRef ab = ABAddressBookCreateWithOptions(NULL, NULL);
__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(ab, ^(bool granted, CFErrorRef error) {
accessGranted = granted;
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
// dispatch_release(sema);
}
else { // we're on iOS 5 or older
accessGranted = YES;
}
if (accessGranted) {
// Do whatever you want here
}
I changed the Addressbook access code,
ABAddressBookRef abcd = ABAddressBookCreateWithOptions(NULL, NULL);
__block BOOL accessGranted = NO;
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(abcd, ^(bool granted, CFErrorRef error) {
// First time access has been granted, add the contact
accessGranted = granted;
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
// The user has previously given access, add the contact
accessGranted = YES;
}
else {
// The user has previously denied access
// Send an alert telling user to change privacy setting in settings app
}
if (accessGranted) {
CFIndex recordsCount = ABAddressBookGetPersonCount(abcd);
CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(abcd);
ABRecordRef ref = CFArrayGetValueAtIndex(all,recordsCount);
NSLog(#"%#", ref);
ABRecordID record = ABRecordGetRecordID(ref);
}
With this also i am not getting a reference to Contact?.. Also the app getting crashed in both Simulator and Device. However i am getting access to AddressBook. #pls suggest me.. what can be done to solve this issue. Thanks
Thanks & Regards
I think the problem is this: you are using a semaphore to block the thread until "the green light" appears. But you are executing this code on the thread 0 (the main thread, that manages the user interface).
For this reason you are blocking all changes in the user interface, including the alert requesting access to contacts.
EDIT for the new code
First thing: try on a device. For some reason, Simulator always return authorized even if not: ABAddressBookGetAuthorizationStatus in simulator always returns kABAuthorizationStatusAuthorized .
Second thing, your "if (accessGranted)" won't be executed the first time the user authorize the app, because it is executed before the completion block (the completion block waits the user decision), but the code immediately after the block is executed immediately. You should move that code in another function (called after the completion block only once authorized, for example).
But, for testing purpose, this code should work the second time you try to access the AB, once authorized.
Your accessGranted code is fine except one thing: if you have an array of 250 records, you are trying to access the record 250 (that doesn't exists, the last record is number 249).
Change this line
ABRecordRef ref = CFArrayGetValueAtIndex(all,recordsCount);
with this
ABRecordRef ref = CFArrayGetValueAtIndex(all,recordsCount-1);
I tried and it works

ios core data cannot find NSManagedObjectModel for entity name 'Cartdetail' with this code

Hi i'm creating an app that needs to save data in my label content to my core data model which is named as cart.xcdatamodeld and my entity named as Cartdetail.When i press a save button in my app i'm getting following error...
- (void)viewDidLoad {
if (managedObjectContext == nil) {
managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate]managedObjectContext];
}
}
- (IBAction)SaveTest:(id)sender {
ViewController2 *second = (ViewController2 *)[NSEntityDescription insertNewObjectForEntityForName:#"Cartdetail" inManagedObjectContext:managedObjectContext];
}
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Cartdetail''
*** Call stack at first throw:
(
0 CoreFoundation 0x010265a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01444313 objc_exception_throw + 44
2 CoreData 0x00036ebb +[NSEntityDescription entityForName:inManagedObjectContext:] + 187
3 CoreData 0x0006e9eb +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 59
4 tablevc 0x00009c97 -[Description alertView:clickedButtonAtIndex:] + 519
5 UIKit 0x00621c5f -[UIAlertView(Private) _buttonClicked:] + 296
6 UIKit 0x002784fd -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x00308799 -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x0030ac2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
9 UIKit 0x003097d8 -[UIControl touchesEnded:withEvent:] + 458
10 UIKit 0x0029cded -[UIWindow _sendTouchesForEvent:] + 567
11 UIKit 0x0027dc37 -[UIApplication sendEvent:] + 447
12 UIKit 0x00282f2e _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x01c34992 PurpleEventCallback + 1550
14 CoreFoundation 0x01007944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
15 CoreFoundation 0x00f67cf7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00f64f83 __CFRunLoopRun + 979
17 CoreFoundation 0x00f64840 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00f64761 CFRunLoopRunInMode + 97
19 GraphicsServices 0x01c331c4 GSEventRunModal + 217
20 GraphicsServices 0x01c33289 GSEventRun + 115
21 UIKit 0x00286c93 UIApplicationMain + 1160
22 tablevc 0x00001d4a main + 170
23 tablevc 0x00001c95 start + 53
)
terminate called throwing an exception
I'm new to iOS..Please help me..Thanks..
You probably haven't set up your managed object context in AppDelegate!
Take a look at the AppDelegate implementation of the iPhoneCoreDataRecipes example provided by apple:
iPhoneCoreDataRecipes example

provide case- insensitive search of DB (core data)

I am a starter in iPhone. I wanted to do case-insensitive search. Database helper used: Core Data.
Following is my code:
-(WebAttendee *) FindAttendeeBy:(NSString *) badgeID_
{
AppDelegate_Shared *delegate1 = [[UIApplication sharedApplication]delegate];
badgeID_=[badgeID_ stringByReplacingOccurrencesOfString:#"\\" withString:#"\\\\"];
badgeID_=[badgeID_ stringByReplacingOccurrencesOfString:#"'" withString:#"\\'"];
self.managedObjectContext = delegate1.managedObjectContext;
return (WebAttendee *)[self FetchManagedObject:#"WebAttendee" :[NSString stringWithFormat:# "Barcode LIKE [c] %#",badgeID_ ]];
}
-(NSManagedObject *)FetchManagedObject:(NSString *)entity_:(NSString *)predicate_
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entity_ inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicate_];
[request setPredicate:predicate];
NSError *error = nil;
//--------------------------crashes at this step---------------------------------
mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
NSLog(#"FetchResult=%#",mutableFetchResults);
[request release];
if (mutableFetchResults == nil) {
// Handle the error.
}
if([mutableFetchResults count]!=0)
return [mutableFetchResults objectAtIndex:0];
else {
return nil;
}
}
but i am getting the following error:
2012-07-05 12:58:52.917 SpotLighter[963:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unimplemented SQL generation for predicate (Barcode LIKE[c] 1123)'
*** Call stack at first throw:
(
0 CoreFoundation 0x01783be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x018d85c2 objc_exception_throw + 47
2 CoreData 0x00fe4676 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 1270
3 CoreData 0x00f1ca78 -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 488
4 CoreData 0x00f1c881 -[NSSQLAdapter newSelectStatementWithFetchRequest:] + 49
5 CoreData 0x00f1c72e -[NSSQLCore newRowsForFetchPlan:] + 430
6 CoreData 0x00f1bab5 -[NSSQLCore objectsForFetchRequest:inContext:] + 357
7 CoreData 0x00f1b66e -[NSSQLCore executeRequest:withContext:error:] + 206
8 CoreData 0x00fcb0ec -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1084
9 CoreData 0x00f18807 -[NSManagedObjectContext executeFetchRequest:error:] + 359
10 SpotLighter 0x0000ff26 -[EntityCommands FetchManagedObject::] + 310
11 SpotLighter 0x0001436e -[WebAttendeeController FindAttendeeBy:] + 300
12 SpotLighter 0x0009aac6 -[MapBadge Map:::] + 4673
13 SpotLighter 0x000687d7 -[SpotLighterHomeScreen SpotLighterDataReceived::::] + 1111
14 SpotLighter 0x0002ca83 -[SpotlighterViewController txtNumericBadgeFieldDone:] + 445
15 UIKit 0x0051da6e -[UIApplication sendAction:to:from:forEvent:] + 119
16 UIKit 0x005ac1b5 -[UIControl sendAction:to:forEvent:] + 67
17 UIKit 0x005ae647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
18 UIKit 0x005ad1f4 -[UIControl touchesEnded:withEvent:] + 458
19 UIKit 0x007a8987 _UIGestureRecognizerSortAndSendDelayedTouches + 3609
20 UIKit 0x007a90fc _UIGestureRecognizerUpdateObserver + 927
21 CoreFoundation 0x01764fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
22 CoreFoundation 0x016fa0e7 __CFRunLoopDoObservers + 295
23 CoreFoundation 0x016c2bd7 __CFRunLoopRun + 1575
24 CoreFoundation 0x016c2240 CFRunLoopRunSpecific + 208
25 CoreFoundation 0x016c2161 CFRunLoopRunInMode + 97
26 GraphicsServices 0x01f07268 GSEventRunModal + 217
27 GraphicsServices 0x01f0732d GSEventRun + 115
28 UIKit 0x0052c42e UIApplicationMain + 1160
29 SpotLighter 0x00002168 main + 102
30 SpotLighter 0x000020f9 start + 53
)
terminate called after throwing an instance of 'NSException'
return (WebAttendee *)[self FetchManagedObject:#"WebAttendee" :[NSString stringWithFormat:# "Barcode LIKE [c] %#",badgeID_ ]];
was giving error...
I replaced the above line with
return (WebAttendee *)[self FetchManagedObject:#"WebAttendee" :[NSString stringWithFormat:# "Barcode LIKE [c] '%#'",badgeID_ ]];
and it worked fine!

[NSCFNumber _isNaturallyRTL]: unrecognized selector sent to instance 0x605ac10

my app got crashed an showed that keyword. There is no error and warning. can some body help me??
this is stack that showed :
Call stack at first throw: (
0 CoreFoundation 0x012ccbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x014215c2 objc_exception_throw + 47
2 CoreFoundation 0x012ce6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0123e366 ___forwarding___ + 966
4 CoreFoundation 0x0123df22 _CF_forwarding_prep_0 + 50
5 UIKit 0x0042d35e -[UITextField setText:] + 53
6 MyApp 0x0006427a -[FilePropertiesViewController viewWillAppear:] + 442
7 UIKit 0x003c4d52 -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 207
8 UIKit 0x003cfa2b -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 378
9 UIKit 0x003cfa5c -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 427
10 UIKit 0x003cfa5c -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 427
11 UIKit 0x003c6b36 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 370
12 UIKit 0x003c514f -[UIView(Hierarchy) addSubview:] + 57
13 UIKit 0x006ad8ae -[UIPopoverView presentFromRect:inView:contentSize:backgroundStyle:animated:] + 1920
14 UIKit 0x006a0a4c -[UIPopoverView presentFromRect:inView:animated:] + 236
15 UIKit 0x006d9b20 -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:] + 1046
16 MyApp 0x0001f90f -[codeViewController arrangeTabWithTypeGesture:andNumtag:] + 4683
17 MyApp 0x0001e68f -[codeViewController setTap2:] + 99
18 UIKit 0x0061e9c7 -[UIGestureRecognizer _updateGestureWithEvent:] + 727
19 UIKit 0x0061a9d6 -[UIGestureRecognizer _delayedUpdateGesture] + 47
20 UIKit 0x00620fa5 _UIGestureRecognizerUpdateObserver + 584
21 UIKit 0x0062118a _UIGestureRecognizerUpdateGesturesFromSendEvent + 51
22 UIKit 0x003bc6b4 -[UIWindow _sendGesturesForEvent:] + 1292
23 UIKit 0x003b7f87 -[UIWindow sendEvent:] + 105
24 UIKit 0x0039b37a -[UIApplication sendEvent:] + 447
25 UIKit 0x003a0732 _UIApplicationHandleEvent + 7576
26 GraphicsServices 0x0191fa36 PurpleEventCallback + 1550
27 CoreFoundation 0x012ae064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
28 CoreFoundation 0x0120e6f7 __CFRunLoopDoSource1 + 215
29 CoreFoundation 0x0120b983 __CFRunLoopRun + 979
30 CoreFoundation 0x0120b240 CFRunLoopRunSpecific + 208
31 CoreFoundation 0x0120b161 CFRunLoopRunInMode + 97
32 GraphicsServices 0x0191e268 GSEventRunModal + 217
33 GraphicsServices 0x0191e32d GSEventRun + 115
34 UIKit 0x003a442e UIApplicationMain + 1160
35 MyApp 0x00002680 main + 102
36 MyApp 0x00002611 start + 53
37 ??? 0x00000001 0x0 + 1
)
update
this is the code :
-(void)viewWillAppear:(BOOL)animated{
DocSegmentedModel *docSegmentedModel = [docProperties objectAtIndex:index];
NSString *segmenid = docSegmentedModel.docSegmentId;
NSFileManager *filemgr = [NSFileManager defaultManager];
NSDictionary *attribs;
NSString *sizes;
NSString *localFilePath = docSegmentedModel.docSegmentLocalPath;
NSLog(#"segmen id : %#", segmenid);
//get file name
fileName.text = docSegmentedModel.docSegmentFileName;
//get file size
attribs = [filemgr attributesOfItemAtPath:localFilePath error:NULL];
sizes = [attribs objectForKey:#"NSFileSize"];
NSLog(#"local path : %#", localFilePath);
NSLog(#"filesize : %#", sizes);
fileSize.text = sizes;
[filemgr release];
[attribs release];
}
the code is crash when I set the fileSize.text = sizes;
this is the dealloc method :
- (void)dealloc {
[fileSize release];
[super dealloc];
}
_isNaturallyRTL is an undocumented method of NSString. I assume that fileSize is a UILabel and so you need to assign an NSString to its text property. However, the dictionary you got returned by the fileManager holds an NSNumber object for the NSFileSize key containing an unsigned long long value. So you assign an NSNumber object to an NSString property, which cannot work.
Try fileSize.text = [sizes stringVlue];.