0

So I have an NSObject which implements NSCoding. In my decoder method it needs to retrieve a BOOL that belongs to the class among other properties.

-(id)initWithCoder:(NSCoder *)decoder {
    self = [super init];
    if (self) {
        [self setRandomObject:[decoder decodeObjectForKey:@"randomObjectKey"]];
        [self setMyBool:[decoder decodeBoolForKey:@"myBoolKey"]];
    }
    return self;
}

This however throws the following warning on the line with [self setMyBool ... (Yellow warning, still runnable).

Incompatible integer to pointer conversion sending 'BOOL' (aka 'signed char') to parameter of type 'BOOL *' (aka 'signed char *')

I don't understand why it is trying to send a pointer of a bool to a bool. If anyone knows how this can be fixed please let me know! Thanks a ton.


Also, it's very late right now, and me being exhausted, I may have just missed something simple so please bear with me.

2
  • Is myBool a property? What's the type signature of setMyBool:?
    – jscs
    Jan 19, 2014 at 6:52
  • Read that error message again -- you're converting from integer (that's the BOOL) to a pointer to BOOL.
    – Caleb
    Jan 19, 2014 at 6:54

2 Answers 2

2

Does your method look like this?

- (void)setMyBool:(BOOL *)value
or:
@property BOOL *myBool;

Because it should be:

- (void)setMyBool:(BOOL)value
or:
@property BOOL myBool;
2
  • 1
    Either that, or the property declaration uses the wrong type.
    – Martin R
    Jan 19, 2014 at 6:58
  • Well I just discovered that I accidentally declared the property with type BOOL * instead of BOOL. Your answer did help though because after reading it I double checked the property declaration and noticed the mistake. Thank you!
    – willbattel
    Jan 19, 2014 at 15:25
0

So it appears I accidentally declared the property as a BOOL * instead of a BOOL. I changed it and everything works now. After reading the comments and answers I decided that the method was correct, then looked at the declaration of the property. Thank you very much, coding late at night is harder than I thought.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.