1

I'm trying to make a custom class to hold data in my iPhone app. I want a box object that will hold 2 variables, it's state (as an int) and whether it's filled or not. (as a bool) In my .h I have this:

#import <Foundation/Foundation.h>

@interface box : NSObject
{
    BOOL filled;
    int state;
}

- (id)init;
-(void)setState:(int)thestate;
-(BOOL)isFilled;

-(BOOL)filled;
-(int)state;
-(void)setFilled:(BOOL)input;
-(void)setState:(int)input;
@end

and in my .m I have this:

#import "box.h"

@implementation box

- (id)init
{
    self = [super init];
    if (self) {
        [self setState:0];
        [self setFilled:NO];
    }

    return self;
}

-(void) setState:(int)input
{
    state = input;
    [self setFilled:YES];
    if (state == 0)
    {
        [self setFilled:NO];
    }
}

-(int) getState
{
    return self.state;
}

-(BOOL)filled
{
    return self.filled;
}

-(void)setFilled:(BOOL)input
{
    filled = input;
}
@end

I'm making my own setters and getters because when I did @property (nonatomic) int state; I had problems. Whenever getState is called, I get a Program received signal: "SIGABRT" error. The console says:

-[box state]: unrecognized selector sent to instance 0x4e51970
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[box state]: unrecognized selector sent to instance 0x4e51970'

How do I fix this error? Thanks.

1 Answer 1

4

Were you synthesizing the properties using @synthesize in your class implementation?

EDIT When a property is synthesized, by default the getter will be propname and not getPropname.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I synthesised it. I'll try changing it back to work with properties, I think I changed some stuff since then.
The @property way worked. Sorry that I submitted a whole question for such an easy fix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.