NSMutableArray adding/removing objects + NSUserDefaults - objective-c

I want to make a "Favorites" in my RSS reader. My RSS parser is parsing a RSS feed to NSMutableArray, and then object "item" is created from part of my rss (selected post).
My code:
//Creating mutable array and adding items:
- (void)viewDidLoad {
if (favoritedAlready == nil) {
favoritedAlready = [[NSMutableArray alloc] init];
[[NSUserDefaults standardUserDefaults] setObject:favoritedAlready forKey:#"favorites"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(#"избранное с нуля");
}
}
- (void) addToFavorites {
NSMutableArray* favoritedAlready = [[NSUserDefaults standardUserDefaults] objectForKey:#"favorites"];
[favoritedAlready addObject: item];
[[NSUserDefaults standardUserDefaults] setObject:favoritedAlready forKey:#"favorites"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(#"Добавлено в избранное. В избранном %i статей", [favoritedAlready count]);
}
//Removing items (another View)
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
rssItems = [[NSUserDefaults standardUserDefaults] objectForKey:#"favorites"];
[self.tableView reloadData];
NSLog(#"Загрузилось избранное, %i избранных статей", [rssItems count]);
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"Номерок строчки в которой удаляемый объект %i", indexPath.row+1);
[rssItems removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[[NSUserDefaults standardUserDefaults] setObject:rssItems forKey:#"favorites"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
It worked perfectly initially, but when I added and removed items, it started crashing.
Crash logs:
I added object to Favorites and removed it:
2011-09-25 20:14:44.534 ARSSReader[36211:11303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object'
*** Call stack at first throw:
(
0 CoreFoundation 0x015505a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x016a4313 objc_exception_throw + 44
2 CoreFoundation 0x01508ef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x01508e6a +[NSException raise:format:] + 58
4 CoreFoundation 0x01547dd1 -[__NSCFArray removeObjectAtIndex:] + 193
5 ARSSReader 0x000a0ced -[FavoritesView tableView:commitEditingStyle:forRowAtIndexPath:] + 173
6 UIKit 0x00876037 -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 101
7 UIKit 0x0080b4fd -[UIApplication sendAction:to:from:forEvent:] + 119
8 UIKit 0x0089b799 -[UIControl sendAction:to:forEvent:] + 67
9 UIKit 0x0089dc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
10 UIKit 0x0089c7d8 -[UIControl touchesEnded:withEvent:] + 458
11 UIKit 0x0082fded -[UIWindow _sendTouchesForEvent:] + 567
12 UIKit 0x00810c37 -[UIApplication sendEvent:] + 447
13 UIKit 0x00815f2e _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x01c91992 PurpleEventCallback + 1550
15 CoreFoundation 0x01531944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x01491cf7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x0148ef83 __CFRunLoopRun + 979
18 CoreFoundation 0x0148e840 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x0148e761 CFRunLoopRunInMode + 97
20 GraphicsServices 0x01c901c4 GSEventRunModal + 217
21 GraphicsServices 0x01c90289 GSEventRun + 115
22 UIKit 0x00819c93 UIApplicationMain + 1160
23 ARSSReader 0x00001e79 main + 121
24 ARSSReader 0x00001df5 start + 53
)
terminate called throwing an exception(gdb)
But, if I added item, restarted app and then removed it, it worked perfectly.
I added item, restarted app, removed item, and tried to add new item:
2011-09-25 20:19:19.212 ARSSReader[36461:11303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object'
*** Call stack at first throw:
(
0 CoreFoundation 0x015505a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x016a4313 objc_exception_throw + 44
2 CoreFoundation 0x01508ef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x01508e6a +[NSException raise:format:] + 58
4 CoreFoundation 0x01547cf1 -[__NSCFArray insertObject:atIndex:] + 209
5 CoreFoundation 0x01544c14 -[__NSCFArray addObject:] + 68
6 ARSSReader 0x00004b35 -[DetailsViewController addToFavorites] + 149
7 UIKit 0x0080b4fd -[UIApplication sendAction:to:from:forEvent:] + 119
8 UIKit 0x00a1dcc3 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
9 UIKit 0x0080b4fd -[UIApplication sendAction:to:from:forEvent:] + 119
10 UIKit 0x0089b799 -[UIControl sendAction:to:forEvent:] + 67
11 UIKit 0x0089dc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
12 UIKit 0x0089c7d8 -[UIControl touchesEnded:withEvent:] + 458
13 UIKit 0x0082fded -[UIWindow _sendTouchesForEvent:] + 567
14 UIKit 0x00810c37 -[UIApplication sendEvent:] + 447
15 UIKit 0x00815f2e _UIApplicationHandleEvent + 7576
16 GraphicsServices 0x01c91992 PurpleEventCallback + 1550
17 CoreFoundation 0x01531944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
18 CoreFoundation 0x01491cf7 __CFRunLoopDoSource1 + 215
19 CoreFoundation 0x0148ef83 __CFRunLoopRun + 979
20 CoreFoundation 0x0148e840 CFRunLoopRunSpecific + 208
21 CoreFoundation 0x0148e761 CFRunLoopRunInMode + 97
22 GraphicsServices 0x01c901c4 GSEventRunModal + 217
23 GraphicsServices 0x01c90289 GSEventRun + 115
24 UIKit 0x00819c93 UIApplicationMain + 1160
25 ARSSReader 0x00001e79 main + 121
26 ARSSReader 0x00001df5 start + 53
)
terminate called throwing an exception(gdb)

In addToFavorites
NSMutableArray* favoritedAlready = [[NSUserDefaults standardUserDefaults] objectForKey:#"favorites"];
will return an NSArray (it makes no difference it you save a mutable version), not an NSMutableArray
You need to create a mutable version:
NSMutableArray* favoritedAlready = [[[NSUserDefaults standardUserDefaults] objectForKey:#"favorites"] mutableCopy];
You can obviously not add items to a non-mutable array. Also just casting the return value to a NSMutableArray is wrong, it may work or it may not but that is irrelevant.

The issue is that NSUserDefaults only returns immutable arrays, even if you put in a mutable array:
Special Considerations:
The returned array and its contents are immutable, even if the values you originally set were mutable.
Therefore, when you fetch your array from NSUserDefaults, you'll have to convert it by using the mutable copy method, or by creating a new NSMutableArray using the returned NSArray.
You may want to consolidate changes to fewer method calls to NSUserDefaults—perhaps in batches, perhaps at certain time intervals. Have a local array keep track of changes, then write the changes out, rather than grabbing the array from NSUserDefaults first. This will save one more trip to disk and will make your code more efficient as well.

Related

Data-core NSException

I don't know where is my problem because the entity "Utente" exist.
Error code:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Utente''
*** First throw call stack:
(
0 CoreFoundation 0x0000000101bf0495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001016f099e objc_exception_throw + 43
2 CoreData 0x0000000101e76599 +[NSEntityDescription entityForName:inManagedObjectContext:] + 217
3 CoreData 0x0000000101eb2e7e +[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 30
4 VucmpraJson 0x000000010000514b -[LoginViewController login:] + 4843
5 UIKit 0x000000010029ef06 -[UIApplication sendAction:to:from:forEvent:] + 80
6 UIKit 0x000000010029eeb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
7 UIKit 0x000000010037b880 -[UIControl _sendActionsForEvents:withEvent:] + 203
8 UIKit 0x000000010037adc0 -[UIControl touchesEnded:withEvent:] + 530
9 UIKit 0x00000001002d5d05 -[UIWindow _sendTouchesForEvent:] + 701
10 UIKit 0x00000001002d66e4 -[UIWindow sendEvent:] + 925
11 UIKit 0x00000001002ae29a -[UIApplication sendEvent:] + 211
12 UIKit 0x000000010029baed _UIApplicationHandleEventQueue + 9579
13 CoreFoundation 0x0000000101b7fd21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x0000000101b7f5f2 __CFRunLoopDoSources0 + 242
15 CoreFoundation 0x0000000101b9b46f __CFRunLoopRun + 767
16 CoreFoundation 0x0000000101b9ad83 CFRunLoopRunSpecific + 467
17 GraphicsServices 0x00000001040d0f04 GSEventRunModal + 161
18 UIKit 0x000000010029de33 UIApplicationMain + 1010
19 VucmpraJson 0x0000000100021d13 main + 115
20 libdyld.dylib 0x00000001025f15fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Code:
#property (nonatomic,strong) NSManagedObjectContext* managedObjectContext;
.
.
.
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject * Utente = [NSEntityDescription insertNewObjectForEntityForName:#"Utente" inManagedObjectContext:context];
[Utente setValue: emailText.text forKey:#"email"];
NSError *error;
//[context save:&error];
if (![context save:&error]) {
NSLog(#"Whoops, couldn't save: %#", [error localizedDescription]);
}
entities: Utente
attributes: email;password
thx to much guys
nil is not a legal NSManagedObjectContext parameter searching for entity name 'Utente'
means that your managed object context is nil. Check self.managedObjectContext assignment.
edit
if (! [self managedObjectContext]) {
NSLog(#"You will receive your exception");
} else {
// Insert new entity into specified context
}

Call to UIWebView crashing my app in iOS

I have a WebView in my storyboard. I created an outlet property to that webview in my view controller file. Then in my code in I'm calling it like this:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"news1" ofType:#"html" inDirectory:#"/HTML"]];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}
The problem is my app is crashing when I run this and I don't really know why. I get this error, but I need help deciphering what the issue is.
2014-05-20 20:18:10.214 MyApp[1789:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(
0 CoreFoundation 0x01f7b1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x019fe8e5 objc_exception_throw + 44
2 CoreFoundation 0x01f7afbb +[NSException raise:format:] + 139
3 Foundation 0x0161a92b -[NSURL(NSURL) initFileURLWithPath:] + 123
4 Foundation 0x0161a7fd +[NSURL(NSURL) fileURLWithPath:] + 67
5 MyApp 0x00011c3d -[LVGTutorialVC viewDidLoad] + 205
6 UIKit 0x007dd33d -[UIViewController loadViewIfRequired] + 696
7 UIKit 0x00803345 -[UINavigationController _layoutViewController:] + 39
8 UIKit 0x0080385b -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
9 UIKit 0x00803953 -[UINavigationController _startTransition:fromViewController:toViewController:] + 78
10 UIKit 0x008048cc -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
11 UIKit 0x008054e9 -[UINavigationController __viewWillLayoutSubviews] + 57
12 UIKit 0x009460d1 -[UILayoutContainerView layoutSubviews] + 213
13 UIKit 0x0072d964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 libobjc.A.dylib 0x01a1082b -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x01de245a -[CALayer layoutSublayers] + 148
16 QuartzCore 0x01dd6244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x01dd60b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
18 QuartzCore 0x01d3c7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
19 QuartzCore 0x01d3db85 _ZN2CA11Transaction6commitEv + 393
20 QuartzCore 0x01d3e258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
21 CoreFoundation 0x01f4336e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
22 CoreFoundation 0x01f432bf __CFRunLoopDoObservers + 399
23 CoreFoundation 0x01f21254 __CFRunLoopRun + 1076
24 CoreFoundation 0x01f209d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x01f207eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x03eab5ee GSEventRunModal + 192
27 GraphicsServices 0x03eab42b GSEventRun + 104
28 UIKit 0x006bef9b UIApplicationMain + 1225
29 MyApp 0x0002158d main + 141
30 libdyld.dylib 0x0262c701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The HTML file isn't in your bundle or isn't at the path specified. Check the case of the file and folder name. If you build/run in the simulator, you can look through the bundle inside of ~/Library/Application Support/iPhone Simulator/7.1/Applications.
Don't use loadRequest if you want to load html locally. use this
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"sample" ofType:#"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];

UILabel [__NSCFString set]: unrecognized selector sent to instance crash

I am having a weird crash related to a UILabel but the crash reporting service I am using doesn't give me much help to locate it. I can't know which Controller and which UILabel is causing it. The only help I have is the following:
-[__NSCFString set]: unrecognized selector sent to instance 0x1e0958d0
0 CoreFoundation __exceptionPreprocess + 162
1 libobjc.A.dylib objc_exception_throw + 30
2 CoreFoundation -[NSObject(NSObject) doesNotRecognizeSelector:] + 170
3 CoreFoundation ___forwarding___ + 392
4 CoreFoundation _CF_forwarding_prep_0 + 24
5 UIKit -[UILabel _legacy_drawTextInRect:baselineCalculationOnly:] + 2632
6 UIKit -[UILabel _drawTextInRect:baselineCalculationOnly:] + 166
7 UIKit -[UILabel drawTextInRect:] + 450
8 UIKit -[UILabel drawRect:] + 72
9 UIKit -[UIView(CALayerDelegate) drawLayer:inContext:] + 364
10 QuartzCore -[CALayer drawInContext:] + 112
11 QuartzCore CABackingStoreUpdate_ + 1808
12 QuartzCore CA::Layer::display_() + 980
13 QuartzCore CA::Layer::display_if_needed(CA::Transaction*) + 202
14 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
15 QuartzCore CA::Context::commit_transaction(CA::Transaction*) + 238
16 QuartzCore CA::Transaction::commit() + 316
17 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 60
18 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
19 CoreFoundation __CFRunLoopDoObservers + 276
20 CoreFoundation __CFRunLoopRun + 742
21 CoreFoundation CFRunLoopRunSpecific + 356
22 CoreFoundation CFRunLoopRunInMode + 104
23 GraphicsServices GSEventRunModal + 74
24 UIKit UIApplicationMain + 1120
25 App main.m line 14
26 App start + 40
Is there anything I can find my way through this? Thanx in advance!
Even though it's an old question, for anyone that encounters a similar issue:
If you're using attributedText in your UILabel, check the attribute value types you're setting. For example:
NSString* s = #"str";
NSMutableAttributedString* as = [[NSMutableAttributedString alloc] initWithString:s];
[as addAttribute:NSForegroundColorAttributeName value:someObjectThatsNotAUIColor range:NSMakeRange(0, s.length)];
will cause the UILabel [__NSCFString set]: unrecognized selector sent to instance crash.
You could try to put this in a .h :
#interface NSString (extended)
- (void)set;
#end
And this in a .m :
#implementation NSString (extended)
- (void)set
{
NSLog(#"[NSString set] ??? impossible !!!");
}
#end
Then set a breakpoint on this method.
Search your project for " set]" then you'll probably already find it, as this is a very untypical method name. If that doesn't help, use NSLog to print out all your labels adresses to your console to find out which label is causing this. Like
for (UIView *sub in self.subviews)
if ([sub kindOfClass:[UILabel class]]) NSLog(#"%p", sub);
(code untested, correct spelling if necessary)

xcode 'NSInvalidArgumentException', reason: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0'

i am not sure why i am getting this error
i created a regular tab bar application
made 5 tabs (compiles and runs)
then put a tableview in one of the tabs , put the code below and i get this error
cure.h
#import <UIKit/UIKit.h>
#interface cure : UIViewController
<UITableViewDataSource, UITableViewDelegate>
{
NSArray *exercises;
}
#end
cure.m
#import "cure.h"
#implementation cure
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
// create a cell
if ( cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"cell"];
}
// set the main text
cell.textLabel.text = [exercises objectAtIndex:indexPath.row];
// return the cell.
return cell;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
exercises = [[NSArray alloc]
initWithObjects:#"An Interesting Title",
#"A Not That Interesting Title",
#"And Still Another Title", nil];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
in mainwindows.xib
i have the right tab class name "cure"
error
2011-04-29 22:22:06.446 week 3 week clear [4950:40b] -[cure superview]: unrecognized selector sent to instance 0x4e3b7b0
2011-04-29 22:22:06.451 peek 3 week clear [4950:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc15a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f15313 objc_exception_throw + 44
2 CoreFoundation 0x00dc30bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d32966 ___forwarding___ + 966
4 CoreFoundation 0x00d32522 _CF_forwarding_prep_0 + 50
5 UIKit 0x002e2365 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 77
6 UIKit 0x002e0aa3 -[UIView(Hierarchy) addSubview:] + 57
7 UIKit 0x002e87c1 -[UIView initWithCoder:] + 840
8 Foundation 0x00017c24 _decodeObjectBinary + 3296
9 Foundation 0x00016d91 _decodeObject + 224
10 UIKit 0x004ac979 -[UIRuntimeConnection initWithCoder:] + 212
11 Foundation 0x00017c24 _decodeObjectBinary + 3296
12 Foundation 0x000189f5 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1354
13 Foundation 0x00019024 -[NSArray(NSArray) initWithCoder:] + 596
14 Foundation 0x00017c24 _decodeObjectBinary + 3296
15 Foundation 0x00016d91 _decodeObject + 224
16 UIKit 0x004abc36 -[UINib instantiateWithOwner:options:] + 804
17 UIKit 0x004adab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
18 UIKit 0x00363628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
19 UIKit 0x00361134 -[UIViewController loadView] + 120
20 UIKit 0x0036100e -[UIViewController view] + 56
21 UIKit 0x00373f54 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120
22 UIKit 0x00372aaa -[UITabBarController transitionFromViewController:toViewController:] + 64
23 UIKit 0x003748a2 -[UITabBarController _setSelectedViewController:] + 263
24 UIKit 0x00374711 -[UITabBarController _tabBarItemClicked:] + 352
25 UIKit 0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
26 UIKit 0x004b3ce6 -[UITabBar _sendAction:withEvent:] + 422
27 UIKit 0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
28 UIKit 0x00341799 -[UIControl sendAction:to:forEvent:] + 67
29 UIKit 0x00343c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
30 UIKit 0x00341750 -[UIControl sendActionsForControlEvents:] + 49
31 UIKit 0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
32 UIKit 0x00341799 -[UIControl sendAction:to:forEvent:] + 67
33 UIKit 0x00343c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
34 UIKit 0x003427d8 -[UIControl touchesEnded:withEvent:] + 458
35 UIKit 0x002d5ded -[UIWindow _sendTouchesForEvent:] + 567
36 UIKit 0x002b6c37 -[UIApplication sendEvent:] + 447
37 UIKit 0x002bbf2e _UIApplicationHandleEvent + 7576
38 GraphicsServices 0x01719992 PurpleEventCallback + 1550
39 CoreFoundation 0x00da2944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
40 CoreFoundation 0x00d02cf7 __CFRunLoopDoSource1 + 215
41 CoreFoundation 0x00cfff83 __CFRunLoopRun + 979
42 CoreFoundation 0x00cff840 CFRunLoopRunSpecific + 208
43 CoreFoundation 0x00cff761 CFRunLoopRunInMode + 97
44 GraphicsServices 0x017181c4 GSEventRunModal + 217
45 GraphicsServices 0x01718289 GSEventRun + 115
46 UIKit 0x002bfc93 UIApplicationMain + 1160
47 peek 3 week clear 0x00002658 main + 102
48 peek 3 week clear 0x000025e9 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
what am i doing wrong?
thank you
You have probably assigned the "cure" class to a UIView in the "Identity" tab in Interface Builder. "cure" is a view controller, so it doesn't implement any UIView methods (such as -superview), and thus throws an exception when trying to load the nib.
Btw, you have a whole bunch of leaks in your code, please read something about memory management in Objective-C (perhaps also about Cocoa naming conventions).

can someone please explain why this keeps crashing on iOS 4.2?

The code worked in iOS 3.2 and in 4.2 it keeps crashing.
Here's the line that it crashes on.
NSArray* address = [NSArray arrayWithArray:[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]];
2010-11-04 12:20:03.060 ContactMapper[2211:207] -[__NSCFDictionary getObjects:range:]: unrecognized selector sent to instance 0x5648e30
2010-11-04 12:20:03.062 ContactMapper[2211:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary getObjects:range:]: unrecognized selector sent to instance 0x5648e30'
*** Call stack at first throw:
(
0 CoreFoundation 0x0117abe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x012cf5c2 objc_exception_throw + 47
2 CoreFoundation 0x0117c6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x010ec366 ___forwarding___ + 966
4 CoreFoundation 0x010ebf22 _CF_forwarding_prep_0 + 50
5 CoreFoundation 0x01176605 -[NSArray initWithArray:range:copyItems:] + 245
6 CoreFoundation 0x010e1367 +[NSArray arrayWithArray:] + 119
7 ContactMapper 0x00003a8d -[RootViewController tableView:cellForRowAtIndexPath:] + 1333
8 UIKit 0x0033a7fa -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
9 UIKit 0x0033077f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
10 UIKit 0x00345450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
11 UIKit 0x0033d538 -[UITableView layoutSubviews] + 242
12 QuartzCore 0x01fc2451 -[CALayer layoutSublayers] + 181
13 QuartzCore 0x01fc217c CALayerLayoutIfNeeded + 220
14 UIKit 0x005c7702 -[UISplitViewController willRotateToInterfaceOrientation:duration:] + 1134
15 UIKit 0x00373df2 -[UIViewController window:willRotateToInterfaceOrientation:duration:] + 962
16 UIKit 0x002edee5 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 1783
17 UIKit 0x002e8538 -[UIWindow _setRotatableViewOrientation:duration:force:] + 89
18 UIKit 0x002eb643 -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 164
19 Foundation 0x000306c1 _nsnote_callback + 145
20 CoreFoundation 0x01152f99 __CFXNotificationPost_old + 745
21 CoreFoundation 0x010d233a _CFXNotificationPostNotification + 186
22 Foundation 0x00026266 -[NSNotificationCenter postNotificationName:object:userInfo:] + 134
23 UIKit 0x00477d0a -[UIDevice setOrientation:animated:] + 228
24 UIKit 0x002c9637 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 656
25 UIKit 0x002d3db2 -[UIApplication handleEvent:withNewEvent:] + 1533
26 UIKit 0x002cc202 -[UIApplication sendEvent:] + 71
27 UIKit 0x002d1732 _UIApplicationHandleEvent + 7576
28 GraphicsServices 0x01ab0a36 PurpleEventCallback + 1550
29 CoreFoundation 0x0115c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
30 CoreFoundation 0x010bc6f7 __CFRunLoopDoSource1 + 215
31 CoreFoundation 0x010b9983 __CFRunLoopRun + 979
32 CoreFoundation 0x010b9240 CFRunLoopRunSpecific + 208
33 CoreFoundation 0x010b9161 CFRunLoopRunInMode + 97
34 UIKit 0x002c8fa8 -[UIApplication _run] + 636
35 UIKit 0x002d542e UIApplicationMain + 1160
36 ContactMapper 0x00002638 main + 102
37 ContactMapper 0x000025c9 start + 53
)
terminate called after throwing an instance of 'NSException'
At first glance, this line is your problem:
[NSArray initWithArray:range:copyItems:]
at first glance, it might be that you need indexPath.row not [indexPath row].
Because iOS 4.2 is still under NDA, we cannot talk about 4.2-specific code.
We can however, talk about 4.1 and previous.
First, you're going to go to the 4.2 diffs page after you sign into the iOS Dev Center. This will tell you what's changed in that release. Since these pages only show release to release, look at the 3.2-4.0 diffs, 4.0-4.1 and 4.1-4.2 diffs. You are looking for a change in the API for UITableView or NSArray that obviously cannot be talked about here.
Second, you're going to download the WWDC '10 session on crash reports. It's a little tedious but the hour spent learning about how to read a crash report is WELL worth it.
Hope this helps!
The error you're getting tells you that the selector getObjects:range: is being sent to an __NSCFDictionary. So clearly the following:
[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]
... used to return an NSArray, but is now returning an NSDictionary.
I don't know what access is so I have no idea what else to say other than you can change the line you cited as the source of the error to:
NSDictionary* address = [NSDictionary dictionaryWithDictionary:[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]];
Once you've done that, whatever code follows that uses address clearly needs to also change to deal with the fact that you're no longer accessing an array.
You need the new iOS CookBook code