I'm searching an NSString with an email to find the # character. Here's the code:
NSRange range = [string rangeOfString:#"#"];
if (range.location != NSNotFound) // do stuff
Here's the error I'm getting...
-[__NSCFNumber rangeOfString:]: unrecognized selector sent to instance 0x1e51c550
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber rangeOfString:]: unrecognized selector sent to instance 0x1e51c550'
Your string variable points to an instance of NSNumber, not an instance of NSString. You are initializing it incorrectly.
Related
If catData is a dictionary returned from a rest API call:
NSString* catId = catData[#"id"];
This is fine if catData[#"id"] is a string. Not so much if it's an int or something else.
I tried this:
NSString* catId = [catData[#"id"] stringValue];
But that results in this:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString stringValue]: unrecognized selector sent to instance 0xa000030383130365'
How can I properly handle any type of value and get it converted to the string that I need?
I'm using AFNetworking with AFJSONResponseSerializer.
instead of using
NSString* catId = [catData[#"id"] stringValue
both case use
NSString* catId = catData[#"id"];
crash happen because you are trying to convert string to string value
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString
stringByAppendingString:]: nil argument'
iam getting this error help me out..
- (IBAction)sendAction:(id)sender
{
if([_chatTextField.text length] > 0)
{
NSString* po = getUser.ofUser;
bubbleTable.typingBubble = NSBubbleTypingTypeNobody;
NSBubbleData *messageBubble = [NSBubbleData dataWithText:_chatTextField.text date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine];
[bubbleData addObject:messageBubble];
[bubbleTable reloadData];
[bubbleTable scrollBubbleViewToBottomAnimated:YES];
NSLog(#"getuserAccount:%#", getUser.account);
NSLog(#"TextField:%#", _chatTextField.text);
NSLog(#"Po:%#", po);
NSLog(#"UserID:%#", [NSString stringWithFormat:#"%ld", (long)getUser.Id]);
NSLog(#"chatMessageKey:%#", chatMessageKey);
[[QuoteMessageController SharedInstance] SendChatMessageTo:getUser.account withContent:_chatTextField.text toUserId:[NSString stringWithFormat:#"%ld", (long)getUser.Id] andOFId:po andVerifyKey:chatMessageKey];
}
//[self StopInteraction];
}
outPut Iam getting is..
> userAccount:(null)
> 2015-01-12 19:09:26.050 SourceSage[6842:737878] TextField:haii
> 2015-01-12 19:09:26.051 SourceSage[6842:737878] Po:(null)
> 2015-01-12 19:09:26.052 SourceSage[6842:737878] UserID:0
> 2015-01-12 19:09:26.052 SourceSage[6842:737878] chatMessageKey:2365891
> 2015-01-12 19:09:44.240 SourceSage[6842:737878] dbPath:/var/mobile/Containers/Data/Application/C06E4910-88B7-46BF-A7A9-8FBDCDA44B67/Documents/Recipes/SourceSageDB.db
> 2015-01-12 19:09:44.264 SourceSage[6842:737878] dbPath:/var/mobile/Containers/Data/Application/C06E4910-88B7-46BF-A7A9-8FBDCDA44B67/Documents/Recipes/SourceSageDB.db
> 2015-01-12 19:09:44.273 SourceSage[6842:737878] *** Terminating app due to uncaught exception
> 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString
> stringByAppendingString:]: nil argument'
> *** First throw call stack:
> (0x2ce265f7 0x3a560c77 0x2ce2653d 0x2da749b3 0x1224b9 0xd2465 0x85569 0x302ff197 0x302ff139 0x302e9d1d 0x302feb69 0x302fe843
> 0x302f8151 0x302ce8c5 0x30542373 0x302cd307 0x2cdecfd7 0x2cdec3eb
> 0x2cdeaa69 0x2cd37b31 0x2cd37943 0x340f0051 0x3032d6f1 0x118fd9
> 0x3aafcaaf)
> libc++abi.dylib: terminating with uncaught exception of type NSException
> (lldb)
The log exactly says NSString* po = getUser.ofUser; returns null or nil value.
You're passing this nil argument to the method [[QuoteMessageController SharedInstance] SendChatMessageTo: withContent: toUserId: andOFId:po andVerifyKey:];.
I have array like this:
(
{
code = "+39";
country = "Italy (+39)";
},
{
code = "+93";
country = "Afghanistan(+93)";
},
)
And i trying to get elements on loop like this discribed here
So there are my code:
int i = 0;
for (id key in self.codes) {
NSDictionary *value = [self.codes objectForKey:key];
if(row == i)
{
return [value objectForKey:#"country"];
}
i++;
}
and i have this error:
2014-10-22 15:49:56.791 Surfree[1097:60b] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x15387e00
2014-10-22 15:49:56.793 Surfree[1097:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x15387e00'
*** First throw call stack:
(0x2e385ecb 0x38b20ce7 0x2e3897f7 0x2e3880f7 0x2e2d7058 0xe51af 0x30e27bf9 0x30e2ae81 0x3112984b 0x30cea179 0x30c913db 0x30cd5c8f 0x3107ec81 0x31128d7b 0x30e29bcf 0x30e29a85 0x30e2a7eb 0x30e27159 0x30e2724f 0x30bb6d17 0x30bb6a85 0x30bb63ed 0x2ececd33 0x30bb6271 0x30bc2ffd 0x30bc2a73 0x30d8c165 0x30bb6d17 0x30bb6a85 0x30bb63ed 0x2ececd33 0x30bb6271 0x30bc2ffd 0x30bc2a73 0x30d8b979 0x30bc90b5 0x30d8b1cd 0x30d483b1 0x30c6546f 0x30c65279 0x30c65211 0x30bb72e5 0x3083331b 0x3082eb3f 0x3082e9d1 0x3082e3e5 0x3082e1f7 0x30bba99f 0x2e350faf 0x2e350477 0x2e34ec67 0x2e2b9729 0x2e2b950b 0x332286d3 0x30c1a871 0xe6bd9 0x3901eab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
How i can to fix it? and Why i have error?
Whe i do debug i see that error in this line :
NSDictionary *value = [self.codes objectForKey:key];
It looks like self.codes is an array; you can't access that like a dictionary. The correct way to use your code is like this:
int i = 0;
for (NSDictionary *value in self.codes) {
if(row == i)
{
return [value objectForKey:#"country"];
}
i++;
}
However, it really just looks like you're trying to access this:
self.codes[row][#"country"]
The error is that you call a NSDictionary method on the NSArray method.
self.codes is a NSArray, it needs to be a NSDictionary.
I am new to Obj-C and somehow I can get the output of a JSON-Request due to difficulties with arrays, dictionareis and syntax. It would be great if someone could get me on my way.
NSLog(#"JSON Feed: %#", self.classified);
NSDictionary *test = self.classified;
NSLog(#"andy %#", [test objectForKey:#"text"]);
this throws an exception :
JSON Feed: (
{
text = "test text";
}
)
2014-06-05 17:25:28.170 Nerdfeed[2321:4107] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x10b988da0
2014-06-05 17:25:28.173 Nerdfeed[2321:4107] * Terminating app due to uncaught exception
I now tried to find a solution for hours but cant fix it. Thank you so much for any help.
self.classified seems to be a NSArray with a single item (and not a NSDictionary). Try [[self.classified firstObject] objectForKey:#"text"]
I'm getting an exception while running iOS app in simulator
2013-09-16 18:03:44.346 DEV[26529:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber isEqualToString:]: unrecognized selector sent to instance 0xf98fc70'
*** First throw call stack:
(0x17bf012 0x1c38e7e 0x184a4bd 0x17aebbc 0x17ae94e 0x1b813 0x1c4c705 0x653920 0x6538b8 0x714671 0x714bcf 0x713d38 0x917213 0x1787afe 0x1787a3d 0x17657c2 0x1764f44 0x1764e1b 0x29db7e3 0x29db668 0x65065c 0x25c9 0x2505 0x1)
UPD:
Exception is caused by the following code:
if([self.media.idtype isEqualToString:IMAGETYPE])
Where idtype is #property(retain, nonatomic) NSString *idtype; and IMAGETYPE is static NSString *VIDEOTYPE = #"2";
How can I see function names instead of addresses?
isEqualToString can compare two NSstrings not the other type of data that u are comparing which is NSDecimalNumber
convert your NSDecimalNumber to nsstring then do this
NSDecimalNumber* dec1;
NSString* str;
str = dec1.stringValue;
NSString *str2=#"world";
[str isEqualToString:str2];
There is some where in your code you are setting the value of property idtype (self.media.idtype). This must be the source of the problem:
Possible Problems could be Extracting contents from Webservice and while parsing you might be assigning it to the self.media.idtype object.