-[__NSArrayI addObject:]: unrecognized selector sent to instance - ios

I have this code:
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
var array: AnyObject = []
for obj in Category.allObjects() {
if var add = obj as? Category {
array.addObject(add.name)
println(add.name)
}
}
return String(array[section] as String)
}
Im using a Realm database and I am trying to get one of the columns of the database to print in the section headers. Im also using a the same process for all the other required UITableView methods eg/ numberOfSectionsInTable etc etc. The code is giving me this error:
2014-10-26 20:47:33.479 Project[14631:937721] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x7fdaf270ddb0
2014-10-26 20:47:33.481 Project[14631:937721] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x7fdaf270ddb0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000109960f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001095f9bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010996804d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001098c027c ___forwarding___ + 988
4 CoreFoundation 0x00000001098bfe18 _CF_forwarding_prep_0 + 120
5 BuildersUtility 0x0000000108d7f720 _TFC15BuildersUtility29ProductsDetailsViewController27numberOfSectionsInTableViewfS0_FCSo11UITableViewSi + 1408
6 BuildersUtility 0x0000000108d7f8ca _TToFC15BuildersUtility29ProductsDetailsViewController27numberOfSectionsInTableViewfS0_FCSo11UITableViewSi + 58
7 UIKit 0x000000010a478a7e -[UITableViewRowData _updateNumSections] + 84
8 UIKit 0x000000010a479474 -[UITableViewRowData invalidateAllSections] + 69
9 UIKit 0x000000010a2cdb03 -[UITableView _updateRowData] + 214
10 UIKit 0x000000010a2e300f -[UITableView numberOfSections] + 27
11 UIKit 0x000000010a4e0645 -[UITableViewController viewWillAppear:] + 97
12 UIKit 0x000000010a327821 -[UIViewController _setViewAppearState:isAnimating:] + 487
13 UIKit 0x000000010a352960 -[UINavigationController _startTransition:fromViewController:toViewController:] + 776
14 UIKit 0x000000010a353487 -[UINavigationController _startDeferredTransitionIfNeeded:] + 523
15 UIKit 0x000000010a353f47 -[UINavigationController __viewWillLayoutSubviews] + 43
16 UIKit 0x000000010a499509 -[UILayoutContainerView layoutSubviews] + 202
17 UIKit 0x000000010a277973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
18 QuartzCore 0x000000010a089de8 -[CALayer layoutSublayers] + 150
19 QuartzCore 0x000000010a07ea0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
20 QuartzCore 0x000000010a07e87e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
21 QuartzCore 0x0000000109fec63e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
22 QuartzCore 0x0000000109fed74a _ZN2CA11Transaction6commitEv + 390
23 QuartzCore 0x0000000109feddb5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
24 CoreFoundation 0x0000000109895dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
25 CoreFoundation 0x0000000109895d20 __CFRunLoopDoObservers + 368
26 CoreFoundation 0x000000010988bb53 __CFRunLoopRun + 1123
27 CoreFoundation 0x000000010988b486 CFRunLoopRunSpecific + 470
28 GraphicsServices 0x000000010dec79f0 GSEventRunModal + 161
29 UIKit 0x000000010a1fe420 UIApplicationMain + 1282
30 BuildersUtility 0x0000000108d9589e top_level_code + 78
31 BuildersUtility 0x0000000108d958da main + 42
32 libdyld.dylib 0x000000010baaf145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
BTW if you have a better way for me to extract the code from the database for a project like this please chirp in! :)
Thanks in Advance

allObjects will return you an instance of RLMResults, which is one of the two list types in Realms, the other being RLMArray. They are both made to be similar to NSArrays or swift arrays, and implement a protocol called RLMCollection. Among other things, that means you can access its elements with normal [i] notation. So you can simply write
return Category.allObjects()[section].name
although you might want to do some checking before you return. Also, it is generally not advisable to repeat the allObjects() query more than you need to, so you could cache in a lazy instance variable or similar. In this case there probably aren't that many categories/section headers, so it shouldn't be an issue.
More importantly, keep in mind that although the RLMResults list you get back is ordered in the sense that it is an ordered list, there is no inherent order among the Category instances in the Realm, so the next time you do Category.allObjects() you are not really guaranteed to receive the objects in the same order. So what you should do is really to create an RLMArray of Category objects and make that a property of another object. Then the order will be preserved.

It is because AnyObject does not support the method addObject
I think what you have in mind is that you want the variable array to be an array of type AnyObject.
You should declare it this way:
var array:[AnyObject] = []
And then when you want to add anything to the array, do this:
array.append(add.name)

In addition to what #AnthonyKong is pointing out, it is a bit unclear from the above code why you would want an array of AnyObject in the first place.
var array = [AnyObject]()
It seems what you actually want is an array of String?
var array = [String]()
then your return statement is simplified down to:
return array[section]
When feeling up to it you might also look into filter to rip out some of that almost-boiler-plate-logic in your code.

I had a similar problem but with an NSMutableArray. Thanks to #Gusutafu's comment above that setting an array to #[] converts it to an NSArray.
My incorrect code (selectedTags is an NSMutableArray):
selectedTags = ([theInputParameters valueForKey:kAcronymTagsSelectedTags] != nil)
? [theInputParameters valueForKey:kAcronymTagsSelectedTags]
: #[];
This gave the error -[__NSArrayI addObject:]: unrecognized selector sent to instance when I tried to add an object.
My corrected code
selectedTags = ([theInputParameters valueForKey:kAcronymTagsSelectedTags] != nil)
? [theInputParameters valueForKey:kAcronymTagsSelectedTags]
: [NSMutableArray arrayWithArray:#[]];

Related

iOS app crashing on [NSNull hasColorGlyphsInRange:attributes:]

I'm facing this exception, and i'm not being able to figure out the problem.
i tried adding exception breakpoint and symbolic breakpoint but it didn't show any more useful data. it's crashing on the main.h return with nothing in the backtrace
this is the exception:
2016-10-20 17:32:58.615 <AppName>[15655:3398242] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull hasColorGlyphsInRange:attributes:]: unrecognized selector sent to instance 0x10b1acfb0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010aeef34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010f90221e objc_exception_throw + 48
2 CoreFoundation 0x000000010af5ef34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010ae74c15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010ae74798 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010d9c66c1 -[UILabel _determineContentsFormat] + 1475
6 UIKit 0x000000010d9c6f9d -[UILabel _evaluateContentsFormat] + 33
7 UIKit 0x000000010d801923 -[UIView(CALayerDelegate) layerWillDraw:] + 65
8 QuartzCore 0x000000010d2c0b26 _ZN2CA5Layer8display_Ev + 146
9 QuartzCore 0x000000010d2b5596 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 294
10 QuartzCore 0x000000010d2b5629 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35
11 QuartzCore 0x000000010d24362c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
12 QuartzCore 0x000000010d270713 _ZN2CA11Transaction6commitEv + 475
13 QuartzCore 0x000000010d271083 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113
14 CoreFoundation 0x000000010ae93e17 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
15 CoreFoundation 0x000000010ae93d87 __CFRunLoopDoObservers + 391
16 CoreFoundation 0x000000010ae78b9e __CFRunLoopRun + 1198
17 CoreFoundation 0x000000010ae78494 CFRunLoopRunSpecific + 420
18 GraphicsServices 0x0000000111c6fa6f GSEventRunModal + 161
19 UIKit 0x000000010d73df34 UIApplicationMain + 159
20 AppName 0x0000000109998c73 main + 1187
21 libdyld.dylib 0x00000001103f368d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
'-[NSNull hasColorGlyphsInRange:attributes:]: unrecognized selector sent to instance 0x10b1acfb0'
This means you've used a NSNull object. From the call stack, maybe a NSNull used as NSString or NSAttributedString. So you need check it before use it.
if (str != [NSNull null]) {
label.text = str
}
are you use this function hasColorGlyphsInRange if you use
try
if ([self respondsToSelector:#selector(hasColorGlyphsInRange:)]) {
//code
}
You need to be able to read and understand error messages.
You are told that someone or something tried to send a message hasColorGlyphsInRange to an instance of NSNull. Even if it is hard to accept because that shouldn't happen, that's the error message and that's what happened.
So you have put an NSNull instance somewhere where you shouldn't have. hasColorGlyphsInRange doesn't seem documented anywhere, so it's something internal to iOS or macOS. But it very much looks like something about text, and there are UILabel methods on the call stack. And there is a layerWillDraw: on the call stack, so it's something trying to draw a UILabel.
UILabels don't get redrawn immediately, but when the system decides to redraw anything. So the most likely thing is that you have set the text of a UILabel to an NSNull object.
And where does the NSNull object come from? Bets are that you are processing JSON and you assume that you are getting a string and don't check for null objects, and that's why you are setting the text of some UILabel to an NSNull instance.

what causes my app crashing when coming back to screen?

I have listing of videos in UITableView which uses custom class. This is tabbar application. When I scroll down to 8th video, and go to next screen and when I come back to video listing screen, the app crashes. I tried to debug but cannot figure out the issue. This is what I get from debugger.
2016-06-08 12:47:46.919 Votocast[2283:453809] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 8 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108ba9d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010a7f9deb objc_exception_throw + 48
2 CoreFoundation 0x0000000108a87804 -[__NSArrayM objectAtIndex:] + 212
3 Votocast 0x0000000107dfd4de -[HomeView tableView:cellForRowAtIndexPath:] + 958
4 UIKit 0x000000010b6914f4 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 766
5 UIKit 0x000000010b69162c -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
6 UIKit 0x000000010b665c8a -[UITableView _updateVisibleCellsNow:isRecursive:] + 2799
7 UIKit 0x000000010b69a686 -[UITableView _performWithCachedTraitCollection:] + 92
8 UIKit 0x000000010b681344 -[UITableView layoutSubviews] + 224
9 UIKit 0x000000010b5ee980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
10 QuartzCore 0x0000000109ff1c00 -[CALayer layoutSublayers] + 146
11 QuartzCore 0x0000000109fe608e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
12 QuartzCore 0x0000000109fe5f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
13 QuartzCore 0x0000000109fda3c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
14 QuartzCore 0x000000010a008086 _ZN2CA11Transaction6commitEv + 486
15 UIKit 0x000000010b52e72e _UIApplicationHandleEventQueue + 7135
16 CoreFoundation 0x0000000108acf301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x0000000108ac522c __CFRunLoopDoSources0 + 556
18 CoreFoundation 0x0000000108ac46e3 __CFRunLoopRun + 867
19 CoreFoundation 0x0000000108ac40f8 CFRunLoopRunSpecific + 488
20 GraphicsServices 0x000000010d4ebad2 GSEventRunModal + 161
21 UIKit 0x000000010b533f09 UIApplicationMain + 171
22 Votocast 0x0000000107e48d8f main + 111
23 libdyld.dylib 0x000000010cc0792d start + 1
24 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
In viewWillAppear, I remove all objects from this array and call webservice. But before I get response from webservice, app crashes to a line in cellForRowAtIndexPath. Your little help will be appreciated.
EDIT:
I have noticed that app only crashes when my tableview decelerationrate and I go to next screen and comeback to video listing screen. I have not done any type of code regarding decelerationration.
Clearly your datasource delegate isn't working properly. If you empty an array that is used by the datasource, then you must call reloadData. And when you get new data, you call reloadData again.
However, you shouldn't refresh data that way. You should display the old data until new data arrives.
You Clear all the object From Array in viewWillAppear Method But, do you Reload the tableview after that.
because this can cause the crash. you remove all the object but tableview tries to goto the last scrolled index. so it cause the crash.
Hope this will help You.
Thank you guys. I fixed it. I actually was allocating array in viewDidLoad and was just removing objects from that array in viewWillAppear. So I preserve my data and not calling webservice in viewWillAppear.

How Do I Fix: Terminating app due to uncaught exception 'NSUnknownKeyException'

I've read that other people have had similar uncaught exceptions, however most seem to be caused by a missing outlet connection. I don't believe mine is related to IBOutlets because the VC runs fine in most scenarios and so do my other VCs.
I think it has to do with Core Data. Here's the error, which I believe occurs in my table's cellForRowAtIndexPath:
2016-01-05 15:18:14.947 Do List[1476:81278] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSManagedObject 0x7fbb89e7cc50> valueForUndefinedKey:]: the entity TomTask is not key value coding-compliant for the key "completedDate".'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102b5ee65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000104cfddeb objc_exception_throw + 48
2 CoreFoundation 0x0000000102b5eaa9 -[NSException raise] + 9
3 CoreData 0x0000000102757ec1 -[NSManagedObject valueForUndefinedKey:] + 289
4 Do List 0x000000010235b9d6 _TFC7Do_List24AllocationViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 2630
5 Do List 0x000000010235c24f _TToFC7Do_List24AllocationViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79
6 UIKit 0x0000000103933e43 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 766
7 UIKit 0x0000000103933f7b -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
8 UIKit 0x0000000103908a39 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2996
9 UIKit 0x000000010393d01c -[UITableView _performWithCachedTraitCollection:] + 92
10 UIKit 0x0000000103923edc -[UITableView layoutSubviews] + 224
11 UIKit 0x00000001038914a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
12 QuartzCore 0x000000010369659a -[CALayer layoutSublayers] + 146
13 QuartzCore 0x000000010368ae70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
14 QuartzCore 0x000000010368acee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
15 QuartzCore 0x000000010367f475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
16 QuartzCore 0x00000001036acc0a _ZN2CA11Transaction6commitEv + 486
17 UIKit 0x00000001037d4f7c _UIApplicationHandleEventQueue + 7329
18 CoreFoundation 0x0000000102a8aa31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x0000000102a8095c __CFRunLoopDoSources0 + 556
20 CoreFoundation 0x0000000102a7fe13 __CFRunLoopRun + 867
21 CoreFoundation 0x0000000102a7f828 CFRunLoopRunSpecific + 488
22 GraphicsServices 0x0000000106bb7ad2 GSEventRunModal + 161
23 UIKit 0x00000001037da610 UIApplicationMain + 171
24 Do List 0x0000000102368fad main + 109
25 libdyld.dylib 0x000000010a52392d start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
A Few Notes
There's a particular set of VCs that, if run in a particular order, cause this error.
The error occurs when I go from A -> B -> C, then try to unwind to A.
If you look at the exception stack above, the error is happening in the cellForRowAtIndexPath of the allocViewController. That VC is B ,so it shouldn't be loading, just being unwound through.
It references "CompletedDate" which is the new thing I added yesterday that kick this whole thing off. CompletedDate was an existing CoreData attribute which I just started showing in view controller C.
If you look at the first line of the error, it looks like you have a class called TomTask which you're trying to use the "completedDate" from, but there isn't a "completedDate" in TomTask.
It appears (from entry #4 in your call stack) you're trying to do this in your tableView:cellForRowAtIndexPath: method of that view controller.

NSUserDefaults setObject method causes the app to crash in ios8

I am having an app in which I am passing some data between viewControllers with NSUserDefaults.
This is the code below I am using.
[[NSUserDefaults standardUserDefaults]setObject:selectedLists forKey:UserID];
Where selectedLists is NSMutableArray and UserID is NSString.
This code works fine until ios7 and xCode5.
Since I have updated xCode6 and now I am using ios8, my app works fine with xCode 6 and ios 7.1 but the app crashes when I run the app in ios8 devices with the error below.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x7a027060'
I just don't understand what is the problem here.
If anyone has faced this problem with ios8 then please help me.
Thanks in advance.
Value of selectedLists
{
CardFace = Word;
ImportFlag = Import;
ListID = 1;
ListName = "Adjectives - Appearance";
QuizBy = Definition;
UserID = 1;
}
and UserId is 1.
EDITED
*** First throw call stack:
(
0 CoreFoundation 0x06a24df6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x03ac8a97 objc_exception_throw + 44
2 CoreFoundation 0x06a2ca75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x069759c7 ___forwarding___ + 1047
4 CoreFoundation 0x0697558e _CF_forwarding_prep_0 + 14
5 CoreFoundation 0x068df30f CFStringGetLength + 143
6 CoreFoundation 0x069de510 _CFPrefsEncodeKeyValuePairIntoMessage + 64
7 CoreFoundation 0x06a275cf -[CFPrefsPlistSource sendMessageSettingValue:forKey:] + 111
8 CoreFoundation 0x06954f3a -[CFPrefsPlistSource alreadylocked_setValue:forKey:] + 250
9 CoreFoundation 0x06954e22 -[CFPrefsSource setValue:forKey:] + 82
10 CoreFoundation 0x06954dc3 ___CFPreferencesSetValueWithContainer_block_invoke + 51
11 CoreFoundation 0x0690ef0a +[CFPrefsSource withSourceForIdentifier:user:byHost:container:perform:] + 1274
12 CoreFoundation 0x06954d61 _CFPreferencesSetValueWithContainer + 225
13 CoreFoundation 0x06a0aa62 _CFPreferencesSetAppValueWithContainer + 66
14 Foundation 0x0347f53f -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 59
15 Foundation 0x0353eeba -[NSUserDefaults(NSKeyValueCoding) setValue:forKey:] + 68
16 Vocab 0x000eaecc Vocab + 720588
17 libobjc.A.dylib 0x03ade7cd -[NSObject performSelector:withObject:withObject:] + 84
18 UIKit 0x022a079d -[UIApplication sendAction:to:from:forEvent:] + 99
19 UIKit 0x022a072f -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
20 UIKit 0x023d3a16 -[UIControl sendAction:to:forEvent:] + 69
21 UIKit 0x023d3e33 -[UIControl _sendActionsForEvents:withEvent:] + 598
22 UIKit 0x023d309d -[UIControl touchesEnded:withEvent:] + 660
23 UIKit 0x022f0aba -[UIWindow _sendTouchesForEvent:] + 874
24 UIKit 0x022f1595 -[UIWindow sendEvent:] + 791
25 UIKit 0x022b6aa9 -[UIApplication sendEvent:] + 242
26 UIKit 0x022c68de _UIApplicationHandleEventFromQueueEvent + 20690
27 UIKit 0x0229b079 _UIApplicationHandleEventQueue + 2206
28 CoreFoundation 0x069487bf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x0693e2cd __CFRunLoopDoSources0 + 253
30 CoreFoundation 0x0693d828 __CFRunLoopRun + 952
31 CoreFoundation 0x0693d1ab CFRunLoopRunSpecific + 443
32 CoreFoundation 0x0693cfdb CFRunLoopRunInMode + 123
33 GraphicsServices 0x0436424f GSEventRunModal + 192
34 GraphicsServices 0x0436408c GSEventRun + 104
35 UIKit 0x0229ee16 UIApplicationMain + 1526
36 Vocab 0x0004c9bc Vocab + 72124
37 libdyld.dylib 0x03ee6ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Edited
On my tableview's didselect method...
UserID = [[users objectAtIndex:indexPath.row] valueForKey:#"UserID"];
where users is an array.
You should check the UserID type because crash is not related with changing NSArray to NSMutableArray.
You must be confusing NSNumber with NSString on your userID:
Change your code and instead of userID use the variable userIDString
NSString userIDString;
//If UserID is class of NSNumber turn its value to NSString
if ([UserID isKindOfClass:[NSNumber class]])
{
userIDString = [UserID stringValue];
}
else
userIDString = UserID ;
During runtime UserId is probably of type NSNumber, even if in your code it is typed NSString.
Check how UserId is created. Use the debugger to check the runtime type.
The newly posted code shows that your retrieve the UserId from the users array which probably consists of dictionaries. In those dictionaries there's a value for the key UserID. It depends on how the array of dictionaries is created (json deserialization?) but it seems that the type of object referred to by the UserID key is a number type, not a string. So all you have to do is convert this number into a string:
UserID = [[[users objectAtIndex:indexPath.row] valueForKey:#"UserID"] stringValue];
Now your key is always a string.
Try to encode your data in NSData and save it in NSUserDefaults and retrieved back, once needed. Have a look at this thread and this one.
Should not use NSUSerdefault to keep a collection of custom objects.
You should save them using NSkeyedUnarchiver/NSkeyedarchiver.
Ref: NSCoding.
I think can't store NSMutableArrays in NSUserDefaults since iOS8 (according to different posts). Try casting it into an array before (or create a new one).
Like this for example :
NSArray *arr = [NSArray arrayWithArray:selectedLists];
And store arr in NSUserDefaults.

Removing an object at a NSMutableArray causes a crash

Attempting to remove an object at a NSMutableArray causes a crash:
2014-03-07 18:58:03.755 HomeWork Pro +[12637:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0xa2f4c20'
remove object code:
[hwArray removeObjectAtIndex:self.indexPath.row];
This only happens if I do it with self.indexPath.row, if I do it with a number it functions normally. I know the self.indexPath.row is not nil, I've NSlogged it to be sure and it turnde right. After doing that I do
[table reloadData]
to reload the UITableView data and the methods.
Any clue on what's the issue here?
Call stack
*** First throw call stack:
(
0 CoreFoundation 0x017aa5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0152d8b6 objc_exception_throw + 44
2 CoreFoundation 0x01847903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0179a90b ___forwarding___ + 1019
4 CoreFoundation 0x0179a4ee _CF_forwarding_prep_0 + 14
5 HomeWork Pro + 0x00006c88 -[HomeWork SelfDelete] + 216
6 HomeWork Pro + 0x0000711a -[HomeWork done:] + 618
7 libobjc.A.dylib 0x0153f874 -[NSObject performSelector:withObject:withObject:] + 77
8 UIKit 0x0029d0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
9 UIKit 0x0029d04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
10 UIKit 0x003950c1 -[UIControl sendAction:to:forEvent:] + 66
11 UIKit 0x00395484 -[UIControl _sendActionsForEvents:withEvent:] + 577
12 UIKit 0x00394733 -[UIControl touchesEnded:withEvent:] + 641
13 UIKit 0x002da51d -[UIWindow _sendTouchesForEvent:] + 852
14 UIKit 0x002db184 -[UIWindow sendEvent:] + 1232
15 UIKit 0x002aee86 -[UIApplication sendEvent:] + 242
16 UIKit 0x0029918f _UIApplicationHandleEventQueue + 11421
17 CoreFoundation 0x0173383f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x017331cb __CFRunLoopDoSources0 + 235
19 CoreFoundation 0x0175029e __CFRunLoopRun + 910
20 CoreFoundation 0x0174fac3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x0174f8db CFRunLoopRunInMode + 123
22 GraphicsServices 0x023349e2 GSEventRunModal + 192
23 GraphicsServices 0x02334809 GSEventRun + 104
24 UIKit 0x0029bd3b UIApplicationMain + 1225
25 HomeWork Pro + 0x00008bad main + 141
26 libdyld.dylib 0x02c8a70d start + 1
27 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
It looks to me like the crash message you posted and your stack trace do not match. The stack trace shows an "unrecognized selector" crash in the making, but the crash message shows that you were attempting to insert a nil object into an array.
Neither of those things matches the line of code that you posted. (removing an object from an array.) I guess you could get an unrecognized selector error from the line of source you posted if the array wasn't really a mutable array...
EDIT:
Based on your updated question, it's clear. Your array is not actually a mutable array even though you think it is.
Post the code that creates the array.
If you're copying it somewhere, look at that code carefully. If you're loading it from a plist or an archive, be aware that mutable arrays come back as immutable when you read them back in.
What you have is an immutable NSArray. What you want is an NSMutableArray, which actually does implement removeObjectAtIndex:. Make sure your array isn't getting replaced with an immutable version at some point.

Resources