I am trying to add object to the array from a dictionary . In else part I am getting this error
mutating method sent to immutable object'
NSMutableDictionary *selectedDict = [NSMutableDictionary new];
[selectedDict setObject:editedLineItem forKey:#"Text"];
[selectedDict setObject:#"fa-check" forKey:#"IconClass"];
NSMutableArray *tagListDictionary = [NSMutableArray new];
[tagListDictionary addObject:selectedTagsArray];
LineItemsStorage *linestorage = [LineItemsStorage sharedManager];
if(![linestorage.packagesArray valueForKey:#"Id"])
{
[linestorage.selectedLineItemsAndTagsArray addObject:selectedDict];
}
else{ [[linestorage.packagesArray valueForKey:#"LineItems"]addObject:[NSMutableArray arrayWithObject:selectedDict]];
}
-[NSCFArray insertObject:atIndex:]: mutating method sent to immutable object'
*** First throw call stack:
(
0 CoreFoundation 0x00000001154a1d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000114f15deb objc_exception_throw + 48
2 CoreFoundation 0x00000001154a1cbd +[NSException raise:format:] + 205
3 CoreFoundation 0x0000000115497b0a -[__NSCFArray insertObject:atIndex:] + 106
4 FlatPebble 0x000000010f276014 -[LineItemViewController okayAction] + 836
5 UIKit 0x0000000113809a8d -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x000000011397ce67 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000011397d143 -[UIControl _sendActionsForEvents:withEvent:] + 327
8 UIKit 0x000000011397c263 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000011387c99f -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x000000011387d6d4 -[UIWindow sendEvent:] + 865
11 UIKit 0x0000000113828dc6 -[UIApplication sendEvent:] + 263
12 UIKit 0x0000000113802553 _UIApplicationHandleEventQueue + 6660
13 CoreFoundation 0x00000001153c7301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
14 CoreFoundation 0x00000001153bd22c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x00000001153bc6e3 __CFRunLoopRun + 867
16 CoreFoundation 0x00000001153bc0f8 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x0000000116e5cad2 GSEventRunModal + 161
18 UIKit 0x0000000113807f09 UIApplicationMain + 171
19 *********** 0x000000010f348c2f main + 111
20 libdyld.dylib 0x0000000115d9992d start + 1
)
Use this code
NSMutableDictionary *selectedDict = [[NSMutableDictionary new]mutableCopy];
[selectedDict setObject:editedLineItem forKey:#"Text"];
[selectedDict setObject:#"fa-check" forKey:#"IconClass"];
NSMutableArray *tagListDictionary = [[NSMutableArray new]mutableCopy];
[tagListDictionary addObject:selectedTagsArray];
LineItemsStorage *linestorage = [LineItemsStorage sharedManager];
if(![linestorage.packagesArray valueForKey:#"Id"])
{
[linestorage.selectedLineItemsAndTagsArray addObject:selectedDict];
}
else{ [[linestorage.packagesArray valueForKey:#"LineItems"]addObject:[NSMutableArray arrayWithObject:selectedDict]];
}
Assuming your packagesArray contains an array containing one or more objects that have a LineItems property (that happens to also be an array); your problem is here:
[[linestorage.packagesArray valueForKey:#"LineItems"]addObject:[NSMutableArray arrayWithObject:selectedDict]]
Breaking it down it is equivalent to:
NSArray* packagesLineItems = [linestorage.packagesArray valueForKey:#"LineItems"];
NSMutableArray* selected = [NSMutableArray arrayWithObject:selectedDict];
[packagesLineItems addObject:selected];
So your problem is either the return type of valueForKey (when called on an array), or the action you're trying to do on it.
Related
I am adding Realm source files in my project. I want to create realm class dynamically. Following is my demo code:
-(void)createDynamicClassObject
{
[self createDynamicSchema];
[self createDynamicSchema2];
}
-(void)createDynamicSchema{
_schema = [[RLMSchema alloc] init];
RLMProperty *prop = [[RLMProperty alloc] initWithName:#"a"
type:RLMPropertyTypeInt
objectClassName:nil
linkOriginPropertyName:nil
indexed:NO
optional:NO];
RLMObjectSchema *objectSchema1 = [[RLMObjectSchema alloc] initWithClassName:#"TrulyDynamicObject"
objectClass:RLMObject.class properties:#[prop]];
_schema.objectSchema = #[objectSchema1];
NSLog(#"dyrealm %#",_dyrealm);
NSLog(#"schema %#",[_schema schemaForClassName:#"TrulyDynamicObject"]);
}
-(void)createDynamicSchema2 {
RLMProperty *prop1 = [[RLMProperty alloc] initWithName:#"apple"
type:RLMPropertyTypeString
objectClassName:nil
linkOriginPropertyName:nil
indexed:NO
optional:NO];
RLMProperty *prop2 = [[RLMProperty alloc] initWithName:#"banana"
type:RLMPropertyTypeFloat
objectClassName:nil
linkOriginPropertyName:nil
indexed:NO
optional:NO];
RLMProperty *prop3 = [[RLMProperty alloc] initWithName:#"Mango"
type:RLMPropertyTypeObject
objectClassName:#"TrulyDynamicObject"
linkOriginPropertyName:nil
indexed:NO
optional:NO];
RLMObjectSchema *objectSchema = [[RLMObjectSchema alloc] initWithClassName:#"DynamicTestObject"
objectClass:RLMObject.class properties:#[prop1,prop2,prop3]];
NSMutableArray *array = [NSMutableArray arrayWithArray:_schema.objectSchema];
[array addObject:objectSchema];
_schema.objectSchema = array;
_dyrealm = [self realmWithTestPathAndSchema:_schema];
NSLog(#"DynamicTestObject dyrealm %#",_dyrealm);
NSLog(#"DynamicTestObject schema %#",[_schema schemaForClassName:#"DynamicTestObject"]);
}
while creating schema2, app is crashing.
2016-06-17 15:10:13.491 realmLibraryDemo[1770:82980] schema TrulyDynamicObject {
a {
type = int;
objectClassName = (null);
linkOriginPropertyName = (null);
indexed = NO;
isPrimary = NO;
optional = NO;
}
}
2016-06-17 15:10:13.499 realmLibraryDemo[1770:82980] *** Terminating app due to uncaught exception 'RLMException', reason: 'Schema validation failed due to the following errors:
- 'Object' property 'Mango' must be nullable.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010217ae65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000101bf1deb objc_exception_throw + 48
2 Realm 0x0000000101281c49 _Z18RLMSetErrorOrThrowP7NSErrorPU15__autoreleasingS0_ + 985
3 Realm 0x00000001012606e6 _Z26RLMRealmTranslateExceptionPU15__autoreleasingP7NSError + 598
4 Realm 0x0000000101260dfc +[RLMRealm openSharedRealm:error:] + 268
5 Realm 0x0000000101261e66 +[RLMRealm realmWithConfiguration:error:] + 4022
6 realmLibraryDemo 0x0000000100fa4eb9 -[ViewController realmWithTestPathAndSchema:] + 217
7 realmLibraryDemo 0x0000000100fa4cb8 -[ViewController createDynamicSchema2] + 776
8 realmLibraryDemo 0x0000000100fa46f6 -[ViewController createDynamicClassObject] + 70
9 realmLibraryDemo 0x0000000100fa42d0 -[ViewController viewDidLoad] + 288
10 UIKit 0x00000001026bef98 -[UIViewController loadViewIfRequired] + 1198
11 UIKit 0x00000001026bf2e7 -[UIViewController view] + 27
12 UIKit 0x0000000102595ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x0000000102596199 -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x00000001025a7c2e -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000102520663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000102526cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
17 UIKit 0x0000000102523e7b -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000104f28754 -[FBSSerialQueue _performNext] + 192
19 FrontBoardServices 0x0000000104f28ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
20 CoreFoundation 0x00000001020a6a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x000000010209c95c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x000000010209be13 __CFRunLoopRun + 867
23 CoreFoundation 0x000000010209b828 CFRunLoopRunSpecific + 488
24 UIKit 0x00000001025237cd -[UIApplication _run] + 402
25 UIKit 0x0000000102528610 UIApplicationMain + 171
26 realmLibraryDemo 0x0000000100fa562f main + 111
27 libdyld.dylib 0x00000001048ce92d start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
How to check whether TrulyDynamicObject is created or not as when I executed code using only [self createDynamicSchema]; it is working fine.
Anybody knows how to create multiple schemas with realm object as a reference when class is dynamically created?
From the "Optional Properties" section of Realm's docs (link):
RLMObject subclass properties always can be nil and thus cannot be included in requiredProperties, and RLMArray does not support storing nil.
Translated into RLMProperty wording, it means that properties of type RLMPropertyTypeObject must be optional since the underlying data format can't guarantee that there will always be a link there.
I am using for in loop to fetch data from plist. But it is showing following exception:
2015-07-16 11:16:43.597 plistNeha[640:60b] -[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x8d671b0
2015-07-16 11:16:43.721 plistNeha[640:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x8d671b0'
*** First throw call stack:
(
0 CoreFoundation 0x017ed1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0156c8e5 objc_exception_throw + 44
2 CoreFoundation 0x0188a243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x017dd50b ___forwarding___ + 1019
4 CoreFoundation 0x017dd0ee _CF_forwarding_prep_0 + 14
5 plistNeha 0x00002b7d -[sdViewController plistbtn:] + 333
6 libobjc.A.dylib 0x0157e880 -[NSObject performSelector:withObject:withObject:] + 77
7 UIKit 0x0022e3b9 -[UIApplication sendAction:to:from:forEvent:] + 108
8 UIKit 0x0022e345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
9 UIKit 0x0032fbd1 -[UIControl sendAction:to:forEvent:] + 66
10 UIKit 0x0032ffc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
11 UIKit 0x0032f243 -[UIControl touchesEnded:withEvent:] + 641
12 UIKit 0x0026dddd -[UIWindow _sendTouchesForEvent:] + 852
13 UIKit 0x0026e9d1 -[UIWindow sendEvent:] + 1117
14 UIKit 0x002405f2 -[UIApplication sendEvent:] + 242
15 UIKit 0x0022a353 _UIApplicationHandleEventQueue + 11455
16 CoreFoundation 0x0177677f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
17 CoreFoundation 0x0177610b __CFRunLoopDoSources0 + 235
18 CoreFoundation 0x017931ae __CFRunLoopRun + 910
19 CoreFoundation 0x017929d3 CFRunLoopRunSpecific + 467
20 CoreFoundation 0x017927eb CFRunLoopRunInMode + 123
21 GraphicsServices 0x037e15ee GSEventRunModal + 192
22 GraphicsServices 0x037e142b GSEventRun + 104
23 UIKit 0x0022cf9b UIApplicationMain + 1225
24 plistNeha 0x00002e1d main + 141
25 libdyld.dylib 0x01e34701 start + 1
26 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Code:
NSString *path=[[NSBundle mainBundle]pathForResource:#"x" ofType:#"plist"];
ald=[[NSDictionary alloc]initWithContentsOfFile:path];
for(NSDictionary *awq in ald){
NSLog(#"check");
NSString *qqw=#"";
qqw=[awq objectForKey:#"qq"];
NSLog(#"%#",qqw);
}
But, if I am fetching data one by one then it is showing on debugger area. for in loop is also working as it is printing check. May be the line after NSLog(#"check"); is creating some exceptions.
Try this
NSString *path=[[NSBundle mainBundle]pathForResource:#"x" ofType:#"plist"];
NSDictionary *ald=[[NSDictionary alloc]initWithContentsOfFile:path];
for(NSDictionary *awq in [ald allValues]){
NSLog(#"check");
NSString *qqw=#"";
qqw=[awq objectForKey:#"qq"];
NSLog(#"%#",qqw);
}
for in on a dictionary is enumerating its keys, not values. See this question for each loop in objective c for accessing NSMutable dictionary
Try this:
NSString *path=[[NSBundle mainBundle]pathForResource:#"x" ofType:#"plist"];
NSDictionary *plistDictionary = [[NSDictionary alloc]initWithContentsOfFile:path];
for(NSString *key in plistDictionary){
NSDictionary *dictionary = [plistDictionary objectForKey:key];
NSLog(#"%#",[dictionary objectForKey:#"qq"]);
}
I had to change your variable names because it was too confusing to work with 'ald', 'awq', 'qqw' , etc.
This is my code for loading data from sqlite file
- (void) loadInitialData{
// Form the query.
NSString *query = #"select * from tasklist";
// Get the results.
if (self.toDoItems != nil) {
self.toDoItems = nil;
}
NSArray *dbResultArray = [[NSArray alloc] initWithArray:[self.dbManager loadDataFromDB:query]];
//Logging for debug purpose
NSLog(#"Result set starts");
for(NSArray *subArray in dbResultArray) {
NSLog(#"Data in array: %#",subArray);
}
NSLog(#"Result set ends");
self.toDoItems = [[NSMutableArray alloc]initWithArray:dbResultArray];
// Reload the table view.
//[self.tblPeople reloadData];
[self.tableView reloadData];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.dbManager = [[DBManager alloc] initWithDatabaseFilename:#"todotaskdb.sql"];
self.toDoItems = [[NSMutableArray alloc] init];
[self loadInitialData];
}
And I am getting this error using NSLog
2014-11-25 18:24:13.862 ToDoList[3213:60b] Result set ends
2014-11-25 18:24:13.865 ToDoList[3213:60b] -[__NSArrayM itemName]: unrecognized selector sent to instance 0x8c996f0
2014-11-25 18:24:13.900 ToDoList[3213:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM itemName]: unrecognized selector sent to instance 0x8c996f0'
*** First throw call stack:
(
0 CoreFoundation 0x018dc1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0165b8e5 objc_exception_throw + 44
2 CoreFoundation 0x01979243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x018cc50b ___forwarding___ + 1019
4 CoreFoundation 0x018cc0ee _CF_forwarding_prep_0 + 14
5 ToDoList 0x00004882 -[XYZToDoListTableViewController tableView:cellForRowAtIndexPath:] + 306
6 UIKit 0x0041411f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
7 UIKit 0x004141f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
8 UIKit 0x003f5ece -[UITableView _updateVisibleCellsNow:] + 2428
9 UIKit 0x0040a6a5 -[UITableView layoutSubviews] + 213
10 UIKit 0x0038a964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
11 libobjc.A.dylib 0x0166d82b -[NSObject performSelector:withObject:] + 70
12 QuartzCore 0x03d4745a -[CALayer layoutSublayers] + 148
13 QuartzCore 0x03d3b244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
14 QuartzCore 0x03d473a5 -[CALayer layoutIfNeeded] + 160
15 UIKit 0x0044cae3 -[UIViewController window:setupWithInterfaceOrientation:] + 304
16 UIKit 0x00362aa7 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
17 UIKit 0x00361646 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
18 UIKit 0x00361518 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
19 UIKit 0x003615a0 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
20 UIKit 0x0036063a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
21 UIKit 0x0036059c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
22 UIKit 0x003612f3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
23 UIKit 0x003648e6 -[UIWindow setDelegate:] + 449
24 UIKit 0x0043eb77 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
25 UIKit 0x0035a474 -[UIWindow addRootViewControllerViewIfPossible] + 591
26 UIKit 0x0035a5ef -[UIWindow _setHidden:forced:] + 312
27 UIKit 0x0035a86b -[UIWindow _orderFrontWithoutMakingKey] + 49
28 UIKit 0x003653c8 -[UIWindow makeKeyAndVisible] + 65
29 UIKit 0x00315bc0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 2097
30 UIKit 0x0031a667 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
31 UIKit 0x0032ef92 -[UIApplication handleEvent:withNewEvent:] + 3517
32 UIKit 0x0032f555 -[UIApplication sendEvent:] + 85
33 UIKit 0x0031c250 _UIApplicationHandleEvent + 683
34 GraphicsServices 0x038d1f02 _PurpleEventCallback + 776
35 GraphicsServices 0x038d1a0d PurpleEventCallback + 46
36 CoreFoundation 0x01857ca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
37 CoreFoundation 0x018579db __CFRunLoopDoSource1 + 523
38 CoreFoundation 0x0188268c __CFRunLoopRun + 2156
39 CoreFoundation 0x018819d3 CFRunLoopRunSpecific + 467
40 CoreFoundation 0x018817eb CFRunLoopRunInMode + 123
41 UIKit 0x00319d9c -[UIApplication _run] + 840
42 UIKit 0x0031bf9b UIApplicationMain + 1225
43 ToDoList 0x00004e0d main + 141
44 libdyld.dylib 0x01e25701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Ironically, if put below line at the end of viewDidLoad method, then it works.
self.dbManager = [[DBManager alloc] initWithDatabaseFilename:#"todotaskdb.sql"];
Can anyone please tell me what is it that I am doing wrong?
Your toDoItems contains Arrays which contains your items! You're may be getting arrays of the single rows in your database, so you would have to fill them into single toDoItems objects first.
Maybe you could use a factory-like pattern with a method like popToDoItemFromRow:(NSArray *)row which returns your toDoItem for this row.
Then fill an new array in your for (NSArray *subArray in dbResultArray) for these single rows. This new array should you use in you cellForRow...
may be like..
- (void) loadInitialData{
// Form the query.
NSString *query = #"select * from tasklist";
// Get the results.
if (self.toDoItems != nil) {
self.toDoItems = nil;
}
NSArray *dbResultArray = [[NSArray alloc] initWithArray:[self.dbManager loadDataFromDB:query]];
if (self.toDoItems) {
[self.toDoItems removeAllObjects];
}
else {
self.toDoItems = [NSMutableArray new];
}
for(NSArray *subArray in dbResultArray) {
[self.toDoItems addObject:[ToDoItem popToDoItemFromRow:subArray]];
}
// Reload the table view.
//[self.tblPeople reloadData];
[self.tableView reloadData];
}
I am getting this crash showing up in BugSense:
-[NSConcreteData count]: unrecognized selector sent to instance 0x14e57f10 - NSInvalidArgumentException
in this code:
+ (NSMutableArray *)applyFilters:(NSMutableArray *)theItems fromFilter:(NSDictionary *)filters
{
NSMutableArray *items = [[NSMutableArray alloc] initWithArray:theItems];
if ([[filters allKeys] count] > 0)
{
NSMutableArray *tempFilteredItems = [[NSMutableArray alloc] init];
for (NSString *key in [filters allKeys])
{
NSMutableString *convertedKey = [NSMutableString stringWithString:key];
[convertedKey replaceOccurrencesOfString:#" "
withString:#"_"
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, [convertedKey length])];
NSArray *tempFilterAttributes = [NSArray arrayWithArray:filters[key]];
for (NSDictionary *item in items)
{
if (![[item[convertedKey] componentsSeparatedByString:#"*"] firstObjectCommonWithArray:tempFilterAttributes])
{
if (![tempFilteredItems containsObject:item])
{
[tempFilteredItems addObject:item];
}
}
}
[items removeObjectsInArray:tempFilteredItems];
[tempFilteredItems removeAllObjects];
}
}
return items;
}
Why/how is this happening?
Stack trace is:
CoreFoundation <redacted> + 130
1 libobjc.A.dylib objc_exception_throw + 38
2 CoreFoundation <redacted> + 202
3 CoreFoundation <redacted> + 706
4 CoreFoundation _CF_forwarding_prep_0 + 24
5 CoreFoundation <redacted> + 28
6 Video Games +[Helper applyFilters:fromFilter:] (Helper.m:2862)
7 Video Games -[WishlistViewController loadUp] (WishlistViewController.m:409) + 29303
8 Video Games -[WishlistViewController viewWillAppear:] (WishlistViewController.m:363) + 27955
9 UIKit <redacted> + 374
10 UIKit <redacted> + 612
11 UIKit <redacted> + 572
12 UIKit <redacted> + 44
13 UIKit <redacted> + 184
14 UIKit <redacted> + 380
15 QuartzCore <redacted> + 142
16 QuartzCore <redacted> + 350
17 QuartzCore <redacted> + 16
18 QuartzCore <redacted> + 228
19 QuartzCore <redacted> + 314
20 UIKit <redacted> + 126
21 CoreFoundation <redacted> + 20
22 CoreFoundation <redacted> + 286
23 CoreFoundation <redacted> + 738
24 CoreFoundation CFRunLoopRunSpecific + 524
25 CoreFoundation CFRunLoopRunInMode + 106
26 GraphicsServices GSEventRunModal + 138
27 UIKit UIApplicationMain + 1136
28 Video Games main (main.m:16) + 888911
29 libdyld.dylib <redacted> + 2
The problem has nothing to do with the code that you provided. The error messages says that the message count was sent to the class NSConcreteData, which is essentially the same as NSData, and such a class method does not exist.
I suggest that you set an exception breakpoint (in Xcode select left the breakpoint navigator, click + left bottom, and select add exception breakpoint).
When you execute the app, it will stop at the faulty instruction.
EDIT (due to the stack trace you provided now):
The stack trace indeed says that your method applyFilters:fromFilter: is responsible for the crash. The only place where the message count is sent in this method, is the statement [[filters allKeys] count]. It looks then that count is sent to an NSConcreteData object, and not to an NSArray object as you might have expected. One reason could be that the argument filters, that should be a NSDictionary, is an object of a different type.
So when the app stops at the exception breakpoint, please check the class of the instance filters.
I need to add an empty object to index 0 and index 1 of an array being populated with data from a third party XML feed.
This is my parseXML method, it works.
-(void) parseXML{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"APIKEYHERECANTSHOW YOU"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *xmlString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSLog(#"The string : %#", xmlString);
NSDictionary *xml = [NSDictionary dictionaryWithXMLString:xmlString];
NSLog(#"The dict:%#", xml);
NSMutableDictionary *PageItem = [xml objectForKey:#"TeamLeagueStanding"];
NSLog(#"PageItem: %#", PageItem);
NSMutableArray *items = [xml objectForKey:#"TeamLeagueStanding"];
NSNull *nullValue = [NSNull null];
[items insertObject:nullValue atIndex:0]; <- THIS MAKES MY APP CRASH
NSLog(#"The array: %#", items);
[self setTableData:items];
}
But when i run this i get a crash with the console output:
2014-02-03 21:24:09.063 Liga Zon Sagres Companion[9645:70b] -[NSNull objectForKey:]: unrecognized selector sent to instance 0x101a85b40
2014-02-03 21:24:09.066 Liga Zon Sagres Companion[9645:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull objectForKey:]: unrecognized selector sent to instance 0x101a85b40'
*** First throw call stack:
(
0 CoreFoundation 0x000000010192a795 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010168d991 objc_exception_throw + 43
2 CoreFoundation 0x00000001019bbbad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010191c09d ___forwarding___ + 973
4 CoreFoundation 0x000000010191bc48 _CF_forwarding_prep_0 + 120
5 Liga Zon Sagres Companion 0x000000010000ee20 -[StandingsTableViewController tableView:cellForRowAtIndexPath:] + 256
6 UIKit 0x00000001003bbb8a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 348
7 UIKit 0x00000001003a3836 -[UITableView _updateVisibleCellsNow:] + 2297
8 UIKit 0x00000001003b4381 -[UITableView layoutSubviews] + 207
9 UIKit 0x000000010034bb27 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
10 QuartzCore 0x0000000102081a22 -[CALayer layoutSublayers] + 151
11 QuartzCore 0x0000000102076589 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
12 QuartzCore 0x0000000102081956 -[CALayer layoutIfNeeded] + 162
13 UIKit 0x00000001003ebfc2 -[UIViewController window:setupWithInterfaceOrientation:] + 264
14 UIKit 0x000000010032ab4d -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 4360
15 UIKit 0x0000000100329a3f -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36
16 UIKit 0x000000010032998f -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 101
17 UIKit 0x0000000100328c9e -[UIWindow _updateToInterfaceOrientation:duration:force:] + 377
18 UIKit 0x00000001003dfd4a -[UIViewController _tryBecomeRootViewControllerInWindow:] + 147
19 UIKit 0x0000000100323a87 -[UIWindow addRootViewControllerViewIfPossible] + 506
20 UIKit 0x0000000100323bd5 -[UIWindow _setHidden:forced:] + 275
21 UIKit 0x000000010032cca2 -[UIWindow makeKeyAndVisible] + 51
22 UIKit 0x00000001002eb0c8 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1449
23 UIKit 0x00000001002eebe8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660
24 UIKit 0x00000001002ffaab -[UIApplication handleEvent:withNewEvent:] + 3092
25 UIKit 0x00000001002fff1e -[UIApplication sendEvent:] + 79
26 UIKit 0x00000001002f02be _UIApplicationHandleEvent + 618
27 GraphicsServices 0x0000000102578bb6 _PurpleEventCallback + 762
28 GraphicsServices 0x000000010257867d PurpleEventCallback + 35
29 CoreFoundation 0x00000001018ac819 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
30 CoreFoundation 0x00000001018ac5ee __CFRunLoopDoSource1 + 478
31 CoreFoundation 0x00000001018d5ab3 __CFRunLoopRun + 1939
32 CoreFoundation 0x00000001018d4f33 CFRunLoopRunSpecific + 467
33 UIKit 0x00000001002ee4bd -[UIApplication _run] + 609
34 UIKit 0x00000001002f0043 UIApplicationMain + 1010
35 Liga Zon Sagres Companion 0x0000000100011f93 main + 115
36 libdyld.dylib 0x0000000102f815fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Any ideas how to solve this? Thank you.
The error is coming from your StandingsTableViewController tableView:cellForRowAtIndexPath: method. Your data is giving you an NSNull instance where you expect an NSDictionary.
Since you explicitly add the NSNull object you need to update your cellForRow... method to check to see if the object is an NSNull instance before assuming it is an NSDictionary.
Something like this:
NSDictionary *data = self.tableData[someIndex];
if ([data isKindOfClass:[NSDictionary class]]) {
// process the data as usual
} else {
// This is probably the NSNull object, ignore it or handle appropriately
}