Problems passing data between different classes with a method - cocoa-touch

I have this in a class:
NSString *globalMidiData = #"30a0a00\n";
switch (IndicatorCheckNXT) {
case 1:
[testRobot checkTestRobot:globalMidiData];
break;
default:
break;
}
And in another class I have this:
-(void) checkTestRobot: (NSString *)midiDataGlobal{
bool pressed;
bool pressed2;
NSString *miawmiaw =[NSString alloc];
miawmiaw=midiDataGlobal;
}
And I got this message:
-[AppDelegate checkTestRobot:]: unrecognized selector sent to instance 0x18acb0
2012-11-23 20:45:31.755 Exemple1[477:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate checkTestRobot:]: unrecognized selector sent to instance 0x18acb0'
What I am doing wrong?

Obviously you send checkTestRobot to the wrong object. testRobot seems to point to the AppDelegate and not to an instance of your class.
Also you should replace this:
NSString *miawmiaw =[NSString alloc];
miawmiaw=midiDataGlobal;
with:
NSString *miawmiaw = [midiDataGlobal copy];

Related

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.

Why CCLabelAtlas[1] refuses to update?

I have 7 CCLabelAtlas labels declared in .h file like this CCLabelAtlas *numberStat[7]. Then I then initialized them in a for loop in .m file:
for (int i = 1; i <=7; i++) {
NSString* statName = [NSString stringWithFormat #"Number %d", i];
numberStat[i] = [[CCLabelAtlas labelWithString: [self loadThisValue:statName] charMapFile:#"digitalNumbers.png" itemWidth:26 itemHeight:37 startCharMap:'0'] retain];
[self addChild: numberStat[i]];
}
The problem comes when I try to update the label. I can update from 2 to 7 just fine, but when I try to update numberStat[1]'s string (numberStat[1].string = #"111";), it crashes. The exact same code works for 2-7.
Here's the crash log:
-[CCSprite setString:]: unrecognized selector sent to instance 0x897cbd0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CCSprite setString:]: unrecognized selector sent to instance 0x897cbd0'
One possibility is that somewhere in your code, numberStat[1] is being over-released, and by the time you come to assign a string to it, a CCSprite has moved into the memory that it occupied.

-[__NSCFNumber isEqualToString] error

I'm getting this crash, but, in my code I am using a string. I've been working on this one piece of code for 2 hours now and I just can't see what I'm missing! Any ideas?
NSString *codeR = [NSString stringWithFormat:#"%#", [[object objectForKey:#"code"] stringValue]];
if([codeR isEqualToString:#"200"])
Error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x181cf0'
I would be very grateful input, this is confusing the hell out of me!
Thanks.
Get rid of silly redundancy, see what happens.
NSString *codeR = [[object objectForKey:#"code"] stringValue];
// mysterious missing code
if ([coreR isEqualToString:#"200"]) // etc
Also, are you sure the error is raised from the if statement you posted? It could be coming from elsewhere.
NSString *codeR = [[object objectForKey:#"code"] stringValue];
if ([codeR isEqualToString:#"200"])
{
// Do stuff...
}

Error saving to iOS keychain using KeychainItemWrapper

I get an error every time I try to store data into the keychain
The error comes from the dictionaryToSecItemFormat method at these lines
NSString *passwordString = [dictionaryToConvert objectForKey:(id)kSecValueData];
[returnDictionary setObject:[passwordString dataUsingEncoding:NSUTF8StringEncoding] forKey:(id)kSecValueData]'
The error is
I'm calling the KeychainItemWrapper methods like this
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:#"credentials" accessGroup:nil];
[keychain setObject:username forKey:kSecAttrAccount];
[keychain release];
The error is
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[NSConcreteData dataUsingEncoding:]: unrecognized selector sent to instance"
dataUsingEncoding is a method from the NSString class, make username a NSString.

Last FM API SIG_ABRT error

I'm getting a SIG_ABRT error in the one line within the else of this method in the FMCallback class of the Last FM API.
- (void)fire {
if(_identifier == nil) {
[_target performSelector:_selector withObject:_userInfo];
} else {
[_target performSelector:_selector withObject:_identifier withObject:_userInfo];
}
}
The console output shows this:
2011-05-29 13:52:24.533 QueryTesting[6918:707] +[LastFM loginCallback:data:]: unrecognized selector sent to class 0x19550
2011-05-29 13:52:24.625 QueryTesting[6918:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[LastFM loginCallback:data:]: unrecognized selector sent to class 0x19550'
What does this mean? Am I not sending enough information with my request?
EDIT:
Here is the code to create the FMEngine (api key x'd out):
+ (void)logUserInWithUsername:(NSString *) username andPassword:(NSString *) password {
FMEngine *fmEngine;
fmEngine = [[FMEngine alloc] init];
NSString *authToken = [fmEngine generateAuthTokenFromUsername:username password:password];
NSDictionary *urlDict = [NSDictionary dictionaryWithObjectsAndKeys:username, #"username", authToken, authToken, _LASTFM_API_KEY_, #"XXXXXXXXXXXXXXXX", nil, nil];
[fmEngine performMethod:#"auth.getMobileSession" withTarget:self withParameters:urlDict andAction:#selector(loginCallback:data:) useSignature:YES httpMethod:POST_TYPE];
}
- (void)loginCallback:(NSString *)identifier data:(id)data {
// data is either NSData or NSError
NSLog(#"Got Data (%#): %#", identifier, data);
}
You've defined a -[LastFM loginCallback:data:] method, not +[LastFM loginCallback:data:].