EXC_BAD_ACCESS when setting scalar property of Core Data object (IOS 5) - objective-c

I am running the following code in the IOS 5.1 simulator:
Table* sparkFront =
[NSEntityDescription insertNewObjectForEntityForName:#"Table"
inManagedObjectContext:_context];
NSLog(#"%#", sparkFront);
NSEntityDescription* entity = [NSEntityDescription entityForName:#"Table"
inManagedObjectContext:_context];
NSDictionary* dict = [entity propertiesByName];
for (NSObject* key in [dict allKeys])
{
NSLog(#"%#", key);
}
sparkFront.columnValuesAddress = 0x606;
This code crashes with EXC_BAD_ACCESS on the last line. The Table object is a Core Data object implemented as follows:
#interface Table : NSManagedObject
#property (nonatomic) int32_t columnValuesAddress;
#end
I know Core Data doesn't natively do scalar types, but this is an IOS 5+ only app, and I was under the impression the un/boxing was done automatically. The output of the above code before the crash shows that my context and entity are good:
2012-07-20 22:17:52.714 otest[95147:7b03] <NSManagedObject: 0x9c87b20> (entity: Table; id: 0x9c86a80 <x-coredata:///Table/t2C0D90D5-E381-4BD0-B65D-8FC83C6D50DB2> ; data: {
columnValuesAddress = 0;
})
2012-07-20 22:17:52.716 otest[95147:7b03] columnValuesAddress
After the crash, the problem report shows the following:
Application Specific Information:
objc_msgSend() selector name: isNSNumber__
Simulator libSystem was initialized out of order.
Thread 0 Crashed:
0 libobjc.A.dylib 0x00635098 objc_msgSend + 12
1 CoreData 0x05c2e833 _PFManagedObject_coerceValueForKeyWithDescription + 483
2 CoreData 0x05bfe3d1 _sharedIMPL_setvfk_core + 209
3 CoreData 0x05c16687 _svfk_0 + 39
4 ECMCalTests 0x0187f8f1 -[ECMCalTests testInsertRecords] + 849 (ECMCalTests.m:73)
5 CoreFoundation 0x003f74ed __invoking___ + 29
6 CoreFoundation 0x003f7407 -[NSInvocation invoke] + 167
7 SenTestingKit 0x201039c4 -[SenTestCase invokeTest] + 184
8 SenTestingKit 0x20103868 -[SenTestCase performTest:] + 183
9 SenTestingKit 0x201034a9 -[SenTest run] + 82
10 SenTestingKit 0x20106db2 -[SenTestSuite performTest:] + 106
11 SenTestingKit 0x201034a9 -[SenTest run] + 82
12 SenTestingKit 0x20106db2 -[SenTestSuite performTest:] + 106
13 SenTestingKit 0x201034a9 -[SenTest run] + 82
14 SenTestingKit 0x20105e97 +[SenTestProbe runTests:] + 174
15 CoreFoundation 0x00492d51 +[NSObject performSelector:withObject:] + 65
16 otest 0x0000231c 0x1000 + 4892
17 otest 0x000025be 0x1000 + 5566
18 otest 0x00002203 0x1000 + 4611
19 otest 0x00001f8d 0x1000 + 3981
20 otest 0x00001f31 0x1000 + 3889
What am I doing wrong?
UPDATE: I implemented the setter/getter for the property according to the core data tutorial. It still crashes. It never hits a breakpoint in the setter so it is crashing before it even calls the setter. Am I hitting a bug in Apple's code?
#interface Table : NSManagedObject
{
int32_t columnValuesAddress;
}
#property (nonatomic) int32_t columnValuesAddress;
#end
#implementation Table
- (int32_t)columnValuesAddress
{
[self willAccessValueForKey:#"columnValuesAddress"];
int32_t address = columnValuesAddress;
[self didAccessValueForKey:#"columnValuesAddress"];
return address;
}
- (void)setColumnValuesAddress:(int32_t)address
{
[self willChangeValueForKey:#"columnValuesAddress"];
columnValuesAddress = address;
[self didChangeValueForKey:#"columnValuesAddress"];
}
- (void)setNilValueForKey:(NSString *)key
{
if ([key isEqualToString:#"columnValuesAddress"])
{
self.columnValuesAddress = 0;
}
else
{
[super setNilValueForKey:key];
}
}
#end

In the entity editor, you need to set your class. It is set for you when you create the core data class file with the file template. I created a class file without the template and thus the class wasn't set, so I was getting these errors. It will only auto box and un-box if it can see the class and see that you have it specified as assign.

I created a brand new project, created the model again from scratch, and copied over the test code from the old project. This new project works fine. I don't know why the old project doesn't work but at least there is a solution.

Related

UIWebDocumentView _updateSubviewCaches crash in iOS10

I am getting the following crash in HockeyApp more seriously in iOS10. Please find the crash log as given below.
Thread 4 Crashed:
0 libobjc.A.dylib 0x0000000187242f30 objc_msgSend + 16
1 UIKit 0x000000018e86e914 -[UIWebDocumentView _updateSubviewCaches] + 36
2 UIKit 0x000000018e69093c -[UIWebDocumentView subviews] + 88
3 UIKit 0x000000018e941bd4 -[UIView(CALayerDelegate) _wantsReapplicationOfAutoLayoutWithLayoutDirtyOnEntry:] + 68
4 UIKit 0x000000018e63d770 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1248
5 QuartzCore 0x000000018bb0640c -[CALayer layoutSublayers] + 144
6 QuartzCore 0x000000018bafb0e8 CA::Layer::layout_if_needed(CA::Transaction*) + 288
7 QuartzCore 0x000000018bafafa8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 28
8 QuartzCore 0x000000018ba77c64 CA::Context::commit_transaction(CA::Transaction*) + 248
9 QuartzCore 0x000000018ba9f0d0 CA::Transaction::commit() + 508
10 QuartzCore 0x000000018ba9faf0 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 116
11 CoreFoundation 0x00000001887a57dc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
12 CoreFoundation 0x00000001887a340c __CFRunLoopDoObservers + 368
13 CoreFoundation 0x00000001886d2068 CFRunLoopRunSpecific + 472
14 WebCore 0x000000018d273a2c RunWebThread(void*) + 452
15 libsystem_pthread.dylib 0x000000018788b860 _pthread_body + 236
16 libsystem_pthread.dylib 0x000000018788b770 _pthread_start + 280
17 libsystem_pthread.dylib 0x0000000187888dbc thread_start + 0
Any idea what is going on here ?
Seems like the following crash groups are also related.
Crash Group 1
[UIWebBrowserView _collectAdditionalSubviews]
objc_msgSend() selector name: autorelease
Crash Group 2
[UIWebDocumentView subviews]
objc_msgSend() selector name: arrayByAddingObjectsFromArray:
I am answering to my own question, since I am able to replicate this issue and found the root cause.
Please note the following.
1. I am using a UIWebView. First of all, this is not recommended.
2. The following way of implementation causes this issue. I am writing pseudo-code here to demonstrate the problem.
#implementation MyViewController
- (void)loadView {
//creating UIWebView Here
self.webView = [[UIWebView alloc] initWithFrame:_some_frame];
//setting the web view properties here.
//Adding to the view
[self.view addSubView: self.webView];
[self populateWebView];
}
- (void) populateWebView {
[self.webView loadHTMLString:_some_html
baseURL:[NSURL fileURLWithPath:_some_path]];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
if (self.webView) {
//The following two lines causing this issue.
self.webView.scrollView.contentInset = _some_insets;
self.webView.scrollView.scrollIndicatorInsets = _some_insets;
}
}
#end
3. The solution is given below.
#implementation MyViewController
- (void)loadView {
//creating UIWebView Here
self.webView = [[UIWebView alloc] initWithFrame:_some_frame];
//setting the web view properties here.
//Adding to the view
[self.view addSubView: self.webView];
[self populateWebView];
}
- (void) populateWebView {
[self.webView loadHTMLString:_some_html
baseURL:[NSURL fileURLWithPath:_some_path]];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
webView.scrollView.contentInset = _some_insets;
webView.scrollView.scrollIndicatorInsets = _some_insets;
}
#end
In my actual code, I was using a custom WebView class here by subclassing the UIWebView. Not think that will create some issue. The root cause is setting the "contentInset" and "scrollIndicatorInsets" in viewDidLayoutSubviews which is not a good idea. When I put the break points, "viewDidLayoutSubviews" called several times and eventually App crashes.
As a solution I moved the following part of the code into "webViewDidFinishLoad" which will call only when the WebView is ready after finished loading. So it makes sense to add this code under this delegate method.
webView.scrollView.contentInset = _some_insets;
webView.scrollView.scrollIndicatorInsets = _some_insets;

Typing in UISearchBar crashes my app

UPDATE 2
My app is crashing when presenting it modally after a user taps a button in ViewController1. In my storyboard, I have a standard present modally segue set to pop up the UINavController/UITableViewController containing the UISearchBar. That's failing every time.
However, in my AppDelegate, if I set the window's rootViewController to the same UINavController/UITableViewController, everything works as expected.
For some reason transitioning via segue and then acting the UISearchBar is causing the crash.
UPDATE 1
I'm now receiving the following error when tapping one letter:
2015-02-03 12:23:35.262 Afar D[28348:2740681] -[NSNull length]: unrecognized selector sent to instance 0x10e352ce0
2015-02-03 12:23:40.313 Afar D[28348:2740681] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x10e352ce0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e0a9f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010dd42bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010e0b104d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010e00927c ___forwarding___ + 988
4 CoreFoundation 0x000000010e008e18 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x000000010df89a7b CFStringCompareWithOptionsAndLocale + 219
6 Foundation 0x000000010d6822b7 -[NSString compare:options:range:] + 29
7 UIKit 0x000000010c5f53b4 -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 224
8 UIKit 0x000000010c53c12e -[UIResponder(Internal) _keyCommandForEvent:] + 285
9 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
10 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
11 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
12 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
13 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
14 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
15 UIKit 0x000000010c53c197 -[UIResponder(Internal) _keyCommandForEvent:] + 390
16 UIKit 0x000000010c3d8f0a -[UIApplication _handleKeyUIEvent:] + 126
17 UIKit 0x000000010c5c7fcc -[UIKeyboardImpl _handleKeyEvent:executionContext:] + 66
18 UIKit 0x000000010c75bbb7 -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 3611
19 UIKit 0x000000010c75a8e5 -[UIKeyboardLayoutStar touchUp:executionContext:] + 1374
20 UIKit 0x000000010c5d531b __28-[UIKeyboardLayout touchUp:]_block_invoke + 242
21 UIKit 0x000000010cb23914 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 332
22 UIKit 0x000000010c5d521c -[UIKeyboardLayout touchUp:] + 252
23 UIKit 0x000000010c5d5cc6 -[UIKeyboardLayout touchesEnded:withEvent:] + 319
24 UIKit 0x000000010c40b308 -[UIWindow _sendTouchesForEvent:] + 735
25 UIKit 0x000000010c40bc33 -[UIWindow sendEvent:] + 683
26 UIKit 0x000000010c3d89b1 -[UIApplication sendEvent:] + 246
27 UIKit 0x000000010c3e5a7d _UIApplicationHandleEventFromQueueEvent + 17370
28 UIKit 0x000000010c3c1103 _UIApplicationHandleEventQueue + 1961
29 CoreFoundation 0x000000010dfdf551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
30 CoreFoundation 0x000000010dfd541d __CFRunLoopDoSources0 + 269
31 CoreFoundation 0x000000010dfd4a54 __CFRunLoopRun + 868
32 CoreFoundation 0x000000010dfd4486 CFRunLoopRunSpecific + 470
33 GraphicsServices 0x000000010fc109f0 GSEventRunModal + 161
34 UIKit 0x000000010c3c4420 UIApplicationMain + 1282
35 My App 0x000000010a5e1c63 main + 115
36 libdyld.dylib 0x000000010e75a145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I'm using iOS8's new UISearchController to manage a UISearchBar for filtering data in a table. If I activate the UISearchBar, the app crashes as soon as I type the first letter (Interestingly, the on-screen keyboard doesn't appear in the Simulator, but I don't think that's related).
In order to narrow things down, I've commented almost everything out of my UIViewController so that the UITableView renders nothing. I've implemented UISearchControllerDelegate and UISearchBarDelegate just so I can log when each method gets called. However, after typing the first letter, I receive no console messages. I don't even know where I could set a breakpoint.
Here's the crash I get:
-[NSNull length]: unrecognized selector sent to instance 0x107602ce0
Note that nowhere in my file am I calling length on anything. Something behind the scenes is, but I can't figure out what.
Here's my code to set up the UISearchController:
- (void)viewDidLoad
{
[super viewDidLoad];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.definesPresentationContext = true;
self.searchController.hidesNavigationBarDuringPresentation = false;
[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.delegate = self;
self.searchController.delegate = self;
}
By request, here are my delegate methods (implemented just to see if anything gets called after typing the first letter - they don't):
#pragma mark - UISearchResultsUpdating
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
#pragma mark - UISearchControllerDelegate
- (void)didDismissSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)didPresentSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)presentSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)willDismissSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (void)willPresentSearchController:(UISearchController *)searchController
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(#"%s", __PRETTY_FUNCTION__);
return true;
}
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
return true;
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
return true;
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
NSLog(#"%s", __PRETTY_FUNCTION__);
}
NSNull is just a singleton object used to represent null. It is traditionally used to wrap around nil values in containers(arrays and dictionaries) that cannot handle nil entries.
This error often comes up when parsing json and trying to add the result in a collection.
Are you doing something like this in your delegate method(s)?
Edit: Judging by the message you are sending to that NSNull (length), you probably get an "empty" result for a string you asked for and expected not be nil.
After burning an entire day struggling with this, it came down to a totally unrelated problem: a corrupted storyboard.
This SO question recommended finding which scene was corrupt and recreating it. Unfortunately there was no way for me to determine that, so after some trial and error, it ended up being the initial view controller in my storyboard, which happened to be a UINavigationController. I deleted that, added it back in, and everything is golden.

-[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (myCustomClass)

I'm new to objective-c and cocoa, and trying to create a document based application that saves and loads a custom class to and from the filesystem. My custom class that conforms to nscoding protocol is as follow:
NSString *const description = #"description";
#implementation PhotoItem
#synthesize description = _description;
-(id)init {
if(self = [super init]){
self.description = #"";
}
return self;
}
/* serializing into file */
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:self.description forKey:description];
}
/* deserializing */
- (id)initWithCoder:(NSCoder *)aDecoder {
self.description = [aDecoder decodeObjectForKey:description];
return self;
}
and my document:
#implementation AMRDocument
#synthesize imgMainImage = _imgMainImage, lblCreationDate = _lblCreationDate, photo=_photo,
txtDescription = _txtDescription;
- (id)init
{
self = [super init];
if (self) {
self.photo = [[PhotoItem alloc] init];
}
return self;
}
- (NSString *)windowNibName
{
return #"AMRDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
NSLog(#"windowControllerDidLoadNib");
[super windowControllerDidLoadNib:aController];
// self.imgMainImage.image = self.photo.image;
[self.txtDescription setString: self.photo.description];
}
+ (BOOL)autosavesInPlace
{
return YES;
}
#pragma mark -saving and loading
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
// self.photo.image = self.imgMainImage.image;
// return [NSKeyedArchiver archivedDataWithRootObject:self.photo];
self.photo.description = self.txtDescription.string;
NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:self.photo];
return archivedData;
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
self.photo = [NSKeyedUnarchiver unarchiveObjectWithData:data];
return YES;
}
- (void)windowWillClose:(NSNotification *)notification {
}
- (IBAction)archiveClicked:(id)sender {
self.photo = [NSKeyedUnarchiver unarchiveObjectWithFile:[#"~/desktop/myphoto1.photo"
stringByExpandingTildeInPath]];
[self.txtDescription setString:self.photo.description];
}
- (IBAction)archiveClicked:(id)sender {
self.photo.description = self.txtDescription.string;
[NSKeyedArchiver archiveRootObject:self.photo toFile:[#"~/desktop/myphoto1.photo"
stringByExpandingTildeInPath]];
}
#end
As you can see I've created two actions called archiveClicked, and unarchiveClicked, one for writing and the other for reading from the file.
It works perfectly fine.
When I'm saving the document using command+s, it can also successfully writes to the file, or at least no exception is thrown then. But when I'm trying to open up the saved file, it'll give me following exception in a popup instead of running the application and loads from the disk.
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (PhotoItem)'
terminate called throwing an exception
abort() called
Application Specific Backtrace 1:
0 CoreFoundation 0x00007fff8f715b06 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff912f03f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8f7158dc +[NSException raise:format:] + 204
3 Foundation 0x00007fff98a1e8c3 _decodeObjectBinary + 2559
4 Foundation 0x00007fff98a1dd24 _decodeObject + 226
5 Foundation 0x00007fff98a90df3 +[NSKeyedUnarchiver unarchiveObjectWithData:] + 92
6 DocumentBasedApp 0x0000000108e49a11 -[AMRDocument readFromData:ofType:error:] + 113
7 AppKit 0x00007fff8d764527 -[NSDocument readFromURL:ofType:error:] + 546
8 AppKit 0x00007fff8d365348 -[NSDocument _initWithContentsOfURL:ofType:error:] + 135
9 AppKit 0x00007fff8d364ff4 -[NSDocument initWithContentsOfURL:ofType:error:] + 262
10 AppKit 0x00007fff8d78d765 -[NSDocumentController makeDocumentWithContentsOfURL:ofType:error:] + 332
11 AppKit 0x00007fff8d78ce7f __block_global_12 + 230
12 AppKit 0x00007fff8d78ca1b __block_global_8 + 955
13 AppKit 0x00007fff8d78bdba -[NSDocumentController _openDocumentWithContentsOfURL:usingProcedure:] + 593
14 AppKit 0x00007fff8d78c655 __block_global_7 + 273
15 libdispatch.dylib 0x00007fff926b4f01 _dispatch_call_block_and_release + 15
16 libdispatch.dylib 0x00007fff926b10b6 _dispatch_client_callout + 8
17 libdispatch.dylib 0x00007fff926b60c8 _dispatch_main_queue_callback_4CF + 275
18 CoreFoundation 0x00007fff8f6b7b4c __CFRunLoopRun + 1644
19 CoreFoundation 0x00007fff8f6b70e2 CFRunLoopRunSpecific + 290
20 HIToolbox 0x00007fff8df91eb4 RunCurrentEventLoopInMode + 209
21 HIToolbox 0x00007fff8df91b94 ReceiveNextEventCommon + 166
22 HIToolbox 0x00007fff8df91ae3 BlockUntilNextEventMatchingListInMode + 62
23 AppKit 0x00007fff8d44c533 _DPSNextEvent + 685
24 AppKit 0x00007fff8d44bdf2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
25 AppKit 0x00007fff8d4431a3 -[NSApplication run] + 517
26 AppKit 0x00007fff8d3e7bd6 NSApplicationMain + 869
27 DocumentBasedApp 0x0000000108e49652 main + 34
28 libdyld.dylib 0x00007fff8d2647e1 start + 0
I've actually created the actions to check the correctness of my nscoding functions and it seems to be working fine, but have no clue, and cannot find anything related to my issue.
Appreciate any help. Needless to say this is a part of my homework.
Edit:
name of this application is "PhotoManager". Earlier I had another document based app called "DocumentBasedApp", and the exception starts with :
Process: DocumentBasedApp [4852]
Path: /Users/USER/Library/Caches/*/DocumentBasedApp.app/Contents/MacOS/DocumentBasedApp
Identifier: com.cjcoax.DocumentBasedApp
Version: 1.0 (1)
Code Type: X86-64 (Native)
Parent Process: launchd [132]
User ID: 501
Your initWithCoder: needs to call [super init];.
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super init];
if (self) {
self.description = [aDecoder decodeObjectForKey:description];
}
return self;
}
The serialized version of MyCustomClass differs from the current version in your code, probably due to changes during development.
/Users/USER/Library/Caches/*/DocumentBasedApp.app/Contents/MacOS/DocumentBasedApp
Deleting the Cache directory got rid of the old serialized data.
Finally solved, I delete everything from the cache as I could not find following path:
/Users/USER/Library/Caches/*/DocumentBasedApp.app/Contents/MacOS/DocumentBasedApp
and it started working! Bizarre!
I had another problem with NSCoder's decodeObjectForKey method while using FXForm - it crashed without any explanation.
- (id)initWithCoder:(NSCoder *)decoder
{
if (self = [super init]) {
self.someObject = [decoder decodeObjectForKey:#"someObject"];
}
return self;
}
The reason was in memory issues. Commonly, looks like when there is no explanation of a bug in logs, it means, it's a memory issue. I forgot to use correct property attribute - copy. I used assign instead. This is correct code:
#interface MyClass : : NSObject <FXForm, NSCoding>
#property (nonatomic, copy) SomeClass *someObject;
#end
Just in case somebody meets this problem too.

iOS Stack Trace Mystery, ABRecordCopyValue Is Suspect

I'm currently using TestFlight in order to get remote crash reports on a beta version of our app. I've received a stack trace, however I'm not quite sure how to narrow down the problem. Here's the report I've received:
0 Holler 0x0003f2a1 Holler + 254625
1 Holler 0x0003f6b7 Holler + 255671
2 libsystem_c.dylib 0x344da72f _sigtramp + 42
3 AppSupport 0x34dfc58d CPRecordCopyProperty + 12
4 AddressBook 0x33e333bf ABRecordCopyValue + 14
5 Holler 0x00018df5 Holler + 97781
6 Holler 0x000182d3 Holler + 94931
7 Holler 0x0000a561 Holler + 38241
8 Holler 0x00033e0f Holler + 208399
9 CoreFoundation 0x3675d571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
10 UIKit 0x355efec9 -[UIApplication sendAction:to:from:forEvent:] + 84
11 UIKit 0x355efe69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
12 UIKit 0x355efe3b -[UIControl sendAction:to:forEvent:] + 38
13 UIKit 0x355efb8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
14 UIKit 0x355f0423 -[UIControl touchesEnded:withEvent:] + 342
15 UIKit 0x355eebf5 -[UIWindow _sendTouchesForEvent:] + 368
16 UIKit 0x355ee56f -[UIWindow sendEvent:] + 262
17 UIKit 0x355d7313 -[UIApplication sendEvent:] + 298
18 UIKit 0x355d6c53 _UIApplicationHandleEvent + 5090
19 GraphicsServices 0x35f11e77 PurpleEventCallback + 666
20 CoreFoundation 0x367c4a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
21 CoreFoundation 0x367c683f __CFRunLoopDoSource1 + 166
22 CoreFoundation 0x367c760d __CFRunLoopRun + 520
23 CoreFoundation 0x36757ec3 CFRunLoopRunSpecific + 230
24 CoreFoundation 0x36757dcb CFRunLoopRunInMode + 58
25 GraphicsServices 0x35f1141f GSEventRunModal + 114
26 GraphicsServices 0x35f114cb GSEventRun + 62
27 UIKit 0x35601d69 -[UIApplication _run] + 404
28 UIKit 0x355ff807 UIApplicationMain + 670
29 Holler 0x00002d79 Holler + 7545
30 Holler 0x00002d44 Holler + 7492
Unfortunately the last 8 items in the stack trace don't appear to be symbolicated. Is there a way for me to do this? I'm assuming hte problem is related to ABRecordCopyValue however I'm not 100% certain. Since I don't know what the last two Holler calls are, I'm somewhat confused. Anybody have an idea about what I should do to narrow down the problem?
I believe the problem now resides within a specific method as the sequence of events (ABRecordCopyValue) followed by two Holler calls is repeated. Here's the code ... I'm using it to load up a user's phone book/contact list. Let me know if this provides any more details:
ContactLists *list = [ContactLists defaultLists];
//Delete the phone contacts, and load them
[list clearContacts];
//Load them
ABAddressBookRef addressbook = ABAddressBookCreate();
if( addressbook )
{
//Got this via http://stackoverflow.com/questions/4641229/code-example-for-abaddressbookcopyarrayofallpeopleinsourcewithsortordering
ABRecordRef source = ABAddressBookCopyDefaultSource(addressbook);
CFArrayRef sortedPeople = ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressbook, source, kABPersonSortByFirstName);
//Sort them first
if( sortedPeople )
{
CFIndex contactCount = ABAddressBookGetPersonCount(addressbook);
for( int i = 0; i<contactCount; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex(sortedPeople, i);
NSMutableString *fName = [[[NSMutableString alloc] init] autorelease];
NSMutableString *lName = [[[NSMutableString alloc] init] autorelease];
NSMutableDictionary *identifiers = [[[NSMutableDictionary alloc]init]autorelease];
if( ref )
{
//Get the user's name first
CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
if( firstName )
{
NSString *fn = [NSString stringWithFormat:#"%#",firstName];
if([fn hasPrefix:#"(null"])
[fName appendString:#""];
else
{
[fName appendString:[NSString stringWithFormat:#"%#", firstName]];
[fName setString:[fName stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[fName substringToIndex:1]uppercaseString]]];
}
CFRelease(firstName);
}
CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
if( lastName )
{
NSString *ln = [NSString stringWithFormat:#"%#",lastName];
if([ln hasPrefix:#"(null"])
[lName appendString:#""];
else
[lName appendString:[NSString stringWithFormat:#"%#",lastName]];
CFRelease(lastName);
}
//If there is no first name don't deal with adding this contact to the ContactsList
if( [fName isEqualToString:#""] )
{
continue;
}
//Handle phone and email contacts
ABMultiValueRef phoneRef = ABRecordCopyValue(ref, kABPersonPhoneProperty);
if(phoneRef)
{
for( int i = 0; i<ABMultiValueGetCount(phoneRef); i++ )
{
CFStringRef phone = ABMultiValueCopyValueAtIndex(phoneRef, i);
if (phone) {
//Create the contact and add them to the phone contactList
NSString *mobileLabel = (NSString *)ABMultiValueCopyLabelAtIndex(phoneRef, i);
if( [mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel] )
[identifiers setValue:(NSString *)phone forKey:#"Mobile:"];
if( [mobileLabel isEqualToString:(NSString *)kABPersonPhoneIPhoneLabel] )
[identifiers setValue:(NSString *)phone forKey:#"iPhone:"];
if( [mobileLabel isEqualToString:(NSString *)kABPersonPhoneMainLabel] )
[identifiers setValue:(NSString *)phone forKey:#"Main:"];
if( [mobileLabel isEqualToString:(NSString *)kABWorkLabel] )
[identifiers setValue:(NSString *)phone forKey:#"Work:"];
if( [mobileLabel isEqualToString:(NSString *)kABHomeLabel] )
[identifiers setValue:(NSString *)phone forKey:#"Home:"];
if( [mobileLabel isEqualToString:(NSString *)kABOtherLabel] )
[identifiers setValue:(NSString *)phone forKey:#"Other:"];
CFRelease(phone);
[mobileLabel release];
}
}
CFRelease(phoneRef);
}
ABMultiValueRef emailRef = ABRecordCopyValue(ref, kABPersonEmailProperty);
if (emailRef) {
if (ABMultiValueGetCount(emailRef) > 0) {
CFStringRef email = ABMultiValueCopyValueAtIndex(emailRef, 0);
if (email) {
[identifiers setValue:(NSString *)email forKey:#"Email:"];
CFRelease(email);
}
}
CFRelease(emailRef);
}
if( [identifiers count] > 0 )
{
//This is where I believe the problem is happen as it's two calls to internal Holler models
[list addContact:[[[Contact alloc]initWithIdentifiers:identifiers firstName:fName lastName:lName]autorelease]];
}
}
}
CFRelease(sortedPeople);
}
CFRelease(addressbook);
CFRelease(source);
}
You need to have the stack trace symbolicated before anything educated can be said about where the crash is.
If you open the stack trace file in Xcode (Import button in the Organizer window) it will automatically be symbolicated with the matching binary and symbolic file....
that is if you have saved the binary/symbolic files - preferably by using the archive function.
If you have not saved symbolic files for that exact file then you can not symbolicate the crash log and would have to wildly guess the real cause.
You really need to symbolicate the Holler methods in the stack trace. Here's how:
Go to TestFlight --> Select the Builds tab, then click the Testers button under the build that you are having issues with. Scroll down to the bottom and click on the bit.ly link that can be used to manually notify testers. At the bottom of that page, it gives you the option to download the .ipa file that you previously uploaded. Download it.
Once downloaded to your computer, rename the file extension from .ipa to .zip. Then unarchive it, and you should get the .app file. Since you only have the stack trace and not the full crash report, you can't use XCode to symbolicate, but you can do symbolication manually using the instructions found here: http://www.bartlettpublishing.com/site/bartpub/blog/3/entry/311
Hope that helps, and I'd love to be a beta tester for your future apps!

NSInvalidArgumentException when calling selector with arguments

I'm trying to execute a method using selector with one NSString as parameter and fails. I have seen many questions (and answers) like this and tried most solutions but had no success. Please see code and errors below:
My MainView.m is my view controller and it has a method:
-(void)displayMessageOnTextView:(NSString *)message
{
[tv1 setText:message];
}
And in MainView.h:
#interface MainView : UIViewController {
UITextView *tv1;
}
-(void)displayMessageOnTextView:(NSString *)message;
....
I have another thread which is fired by MainView (this is from MainView.m):
- (void) runTest
{
MyThread *t = [[MyThread alloc] initWithInt:13253];
[t setMainView:self];
[t run];
[t release];
}
and MyThread.m:
#import "MyThread.h"
#import "MainView.h"
#implementation MyThread
MainView *_view;
-(id)initWithInt:(int)someInt{
_view = NULL;
return self;
}
-(void)setMainView:(MainView*)view
{
_view = view;
}
-(int)run{
NSString *s = [NSString stringWithFormat:#"Display on Gui:%d", 1];
[_view performSelectorOnMainThread:#selector(displayMessageOnTextView:message:) withObject:s waitUntilDone:YES];
}
#end
Error:
2011-04-20 02:08:11.553 myApp[22627:207] -[MainView displayMessageOnTextView:message:]: unrecognized selector sent to instance 0x4e383a0
2011-04-20 02:08:11.555 myApp[22627:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainView displayMessageOnTextView:message:]: unrecognized selector sent to instance 0x4e383a0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc55a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f19313 objc_exception_throw + 44
2 CoreFoundation 0x00dc70bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d36966 ___forwarding___ + 966
4 CoreFoundation 0x00d36522 _CF_forwarding_prep_0 + 50
5 Foundation 0x0079e94e __NSThreadPerformPerform + 251
6 CoreFoundation 0x00da68ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
7 CoreFoundation 0x00d0488b __CFRunLoopDoSources0 + 571
8 CoreFoundation 0x00d03d86 __CFRunLoopRun + 470
9 CoreFoundation 0x00d03840 CFRunLoopRunSpecific + 208
10 CoreFoundation 0x00d03761 CFRunLoopRunInMode + 97
11 GraphicsServices 0x00ffd1c4 GSEventRunModal + 217
12 GraphicsServices 0x00ffd289 GSEventRun + 115
13 UIKit 0x00025c93 UIApplicationMain + 1160
14 myApp 0x000024c9 main + 121
15 myApp 0x00002445 start + 53
)
terminate called after throwing an instance of 'NSException'
NOTE:
I'm new to Objective-C (and generally iOS) programming, so any comment regarding coding conventions and best practice will be appreciated (even if not related to my question, but related to my code)
Your method has been declared as
-(void)displayMessageOnTextView:(NSString *)message;
This means that the method name is displayMessageOnTextView: and the corresponding selector is #selector(displayMessageOnTextView:). Note that a method name does not include parameter (variable) names.
In your -run method, change
[_view performSelectorOnMainThread:#selector(displayMessageOnTextView:message:)
withObject:s
waitUntilDone:YES];
to
[_view performSelectorOnMainThread:#selector(displayMessageOnTextView:)
withObject:s
waitUntilDone:YES];
and that runtime error shouldn’t happen again.
For the record, a method declaration corresponding to displayMessageOnTextView:message: would be:
- (void)displayMessageOnTextView:(type1)parameter1 message:(type2)parameter2;
This method:
-(void)displayMessageOnTextView:(NSString *)message
has the selector displayMessageOnTextView:. The name of the parameter itself (message in your case) does not appear in the selector. (This should be sort of intuitive: the name doesn't necessarily appear when you call the method, so it doesn't appear in the selector.) So you need to be using #selector(displayMessageOnTextView:).