Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chaosal

macrumors newbie
Original poster
Jan 26, 2010
3
0
hey guys been looking through a lot of info on the web but can't understand what i'm doing wrong:

my .h file:

Code:
@interface myClass : NSObject {

	NSString* colour;
}

- (NSString*) colour;
- (void) setColour:(NSString*)input;

@end

my .m file:

Code:
@implementation myClass

- (NSString*) colour {
    return colour;
}

- (void) setColour: (NSString*)input {
    colour = input;
}    

- (void) dealloc
{
    [colour release];
    [super dealloc];
}

@end

using myClass:

Code:
myClass *test = [[myClass alloc] init];
[myClass setNumber:10];

the error i get:

010-01-26 20:59:36.540 myApp[6428:207] *** -[NSCFString setNumber:]: unrecognized selector sent to instance 0x405c
2010-01-26 20:59:36.542 myApp[6428:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString setNumber:]: unrecognized selector sent to instance 0x405c'

any help or just pointing me in the right direction would be greatly appreciated :) thanks
 
hey guys been looking through a lot of info on the web but can't understand what i'm doing wrong:

my .h file:

Code:
@interface myClass : NSObject {

	NSString* colour;
}

- (NSString*) colour;
- (void) setColour:(NSString*)input;

@end



using myClass:

Code:
myClass *test = [[myClass alloc] init];
[myClass setNumber:10];

the error i get:

010-01-26 20:59:36.540 myApp[6428:207] *** -[NSCFString setNumber:]: unrecognized selector sent to instance 0x405c
2010-01-26 20:59:36.542 myApp[6428:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString setNumber:]: unrecognized selector sent to instance 0x405c'

any help or just pointing me in the right direction would be greatly appreciated :) thanks

You're calling a method called setNumber, but all I see in your class is a method called setColour.
 
oops sorry been testing loads and posted the wrong bit, this is what i'm actually trying to do:

Code:
myClass *test = [[myClass alloc] init];
NSString *testString = @"blue";
[test setColour:testString];
 
oops sorry been testing loads and posted the wrong bit, this is what i'm actually trying to do:

Code:
myClass *test = [[myClass alloc] init];
NSString *testString = @"blue";
[test setColour:testString];
And you're still getting
-[NSCFString setNumber:]: unrecognized selector sent to instance 0x405c
from this new code?

EDIT: P.S. It's also common convention to name classes starting with a capital letter so as to not confuse them with (commonly) lower-case-started instance variables. I.E. MyClass would be the conventional approach.
 
ok thanks will remember that and yeah im still gettin the same error:

*** -[NSCFString setColour:]: unrecognized selector sent to instance 0x405c

really don't know why it's failing, should be such a simple thing :S
 
I'm not getting any errors when running that code. Your code must be different than what you included. It's complaining that you are trying to call the instance method setColour: on an object of NSString type. Are you seeing any warnings when building?
 
I also think it's a good idea to realize that you might not be following the best practice with your setter. In your setColour: method, you have:

Code:
colour = input;

but then in your dealloc, you have:

Code:
[colour release]

Do you see where you might have a problem with this?
 
I would recommend using a @property
some thing like this

Code:
 @property ( nonatomic,retain) NSString * color;

then just call

Code:
[self setColor: myColor];
and it will properly retain and release it. But don't make a setColor method. ( it makes one for you)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.