assigning values in NSArrays - objective-c

Objective C gives me a run-time error for the indicated line of code
-(void) play: (int)i at: (int)j {
if ([self.board[i][j] isEqualToString:#""]){
if (xplays) {
self.board[i][j] = #"x"; //<-----HERE
}
else
self.board[i][j] = #"x";
}
xplays = !xplays;
}
board is a property. The error message is
[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x7123120
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x7123120'
Do I need to use C-arrays for this kind of assignment?

You should be using an NSMutableArray.

Related

Is there anyway to check if my app calls any method exclusive for iOS 8?

After testing my app in a iOS 7 device, I got a crash calling containsString from NSString, and then I realised that that methods has NS_AVAILABLE(10_10, 8_0);
Is there anyway to check automatically my program to see if there is any other method that is not available in iOS 7?
How is possible to compile and app with deployment target of 7.0 and not saying any warning or error in these cases?
-[__NSCFString containsString:]: unrecognized selector sent to instance 0x1702297c0
2015-10-23 12:03:37.655 WA[1434:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString containsString:]: unrecognized selector sent to instance 0x1702297c0'
* First throw call stack:
(0x183bd2f50 0x1900dc1fc 0x183bd7c04 0x183bd5930 0x183af55dc 0x1002a2c08 0x1000c71dc 0x1000caa88 0x1000c69bc 0x1000f3a4c 0x186c1055c 0x186c0ff08 0x186c099ec 0x186b9d8cc 0x186b9cad0 0x186c09044 0x1897bb504 0x1897bb030 0x183b92e90 0x183b92df0 0x183b91014 0x183ad1c20 0x186c081c8 0x186c02fdc 0x1000b6040 0x1906cfaa0)
libc++abi.dylib: terminating with uncaught exception of type NSException
You should use rangeOfString instead of containsString. Since rangeOfString available from iOS 2.0, you will not get crash on this.
Code snippets,
NSString *string = #"https://www.google.co.in/";
NSString *substring = #"http";
if ([oneContent rangeOfString:subString].location == NSNotFound) {
NSLog(#"string does not contain substring");
} else {
NSLog(#"string contains substring!");
}
Otherwise you can add category class for NSString and have a method like containsString: where you can implement the above code. It'll work dynamically.

core data tableView crash

As the name states I am working with UITableView and CoreData. I have a custom UITableViewCell which has title and detail label. In my cellForRowAtIndexPath it crashes. I have found the issue I was passing NULL but the issue is it doesn't crash at
cell.detailLabel.text = [[factors valueForKey:#"factorsdescription"] lastObject];
but after many times cellForRowAtIndexPath is called and even on that cell in which I'm not passing null. any ideas?
crash Log
[NSNull length]: unrecognized selector sent to instance 0x34ed3690
2015-08-20 18:58:37.364 MASTER[1535:89769] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance

iOS Error - "unrecognized selector"

Main.m
NSDictionary *additionalQueryParameters = [NSURL ab_parseURLQueryString:[url query]];
OAuth.h
#interface NSURL (OAuthAdditions)
+ (NSDictionary *)ab_parseURLQueryString:(NSString *)query;
#end
OAuth.m
#implementation NUSL (OAuthAdditions)
+ (NSDictionary *)ab_parseURLQueryString:(NSString *)query
{
does something..
}
When it runs that line, it throws this error...
2012-12-03 15:10:58.506[12500:1d403] +[NSURL ab_parseURLQueryString:]:
unrecognized selector sent to class 0xaece26c
2012-12-03 15:10:58.508[12500:1d403] * Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '+[NSURL
ab_parseURLQueryString:]: unrecognized selector sent to class
0xaece26c'
* First throw call stack: (0xada8012 0xa3d6e7e 0xae332ad 0xad97bbc 0xad9794e 0x17b5ee8 0x17b5724 0x17b58d6 0xa84f53f 0xa861014 0xa8522e8
0xa851fcb 0x96097b24 0x960996fe) libc++abi.dylib: terminate called
throwing an exception
Any idea why it can't find it and how to fix it? Thanks.
Make sure OAuth.m is actually in the target and building in your project....
Your category implementation (OAuth.m) is named NUSL, not NSURL. The compiler is fine with the method since the category interface (header) is named correctly.

What situation can cause Terminating app due to uncaught exception of class 'nil'

My app crashed occasionally with
2012-10-10 23:19:24.039 [26442:850f] -[NSNull allKeys]: unrecognized selector sent to instance 0x7fff741cbea0
2012-10-10 23:19:24.040 [26442:850f] *** Terminating app due to uncaught exception of class 'nil'
The object has already been tested [obj isKindOfClass:[NSDictionary class]] before call allKeys:
and if I call [[NSNull null] allKeys] intentionally, it crashes with
2012-10-11 16:22:15.606 [14939:403] -[NSNull allKeys]: unrecognized selector sent to instance 0x7fff73659f00
2012-10-11 16:22:15.622 [14939:403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull allKeys]: unrecognized selector sent to instance 0x7fff73659f00'
I want to know what situation causes Terminating app due to uncaught exception of class 'nil' so I can debug this problem.
1: Because NSNull doesn't respond to message [allKeys], so it throws an exception.
2: you should check that your objet can [respondsToSelector:#selector(allKeys)] instead
3: if your NSNull class objet pass the [obj isKindOfClass:[NSDictionary class]], then there is a problem in your control statement

Why am I receiving an error message when attempting NSScanner to use in a NSString statement?

I would like to know why I get an error message
Thread 1: Program received signal: "SIGABRT")
When I use this line of code:
NSScanner *userEntered = [[NSScanner alloc] scannerWithString:temp];
The error is:
2011-04-18 02:06:11.995 XXX[25929:207] -[NSConcreteScanner scannerWithString:]: unrecognized selector sent to instance 0x6816bc0
2011-04-18 02:06:11.999 XXX[25929:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteScanner scannerWithString:]: unrecognized selector sent to instance 0x6816bc0'
Thank you.
+scannerWithString is a class method and should be used the following way:
NSScanner *userEntered = [NSScanner scannerWithString:temp];