Bharadwaj Srigiriraju
Bharadwaj Srigiriraju

Reputation: 2206

Semantic Issue: No setter method 'setisSelected:' for assignment to property

I am new to Objective-C, in fact it's been couple of hours since I have started learning it.

I am currently watching latest lectures from Stanford about iOS development, and in the second lecture Hegarty starts adding a basic button which gets selected upon clicking. Pretty basic stuff, but I can't figure out what's causing this error in my XCode, whereas the same code runs fine in the lecture video.

Here's the error message:

CardGameViewController.m
    Semantic Issue
     No setter method 'setIsSelected:' for assignment to property

This is my CardGameViewController.h file:

#import <UIKit/UIKit.h>

@interface CardGameViewController : UIViewController

@end

This is my CardGameViewController.m file:

#import "CardGameViewController.h"

@interface CardGameViewController ()

@end

@implementation CardGameViewController

- (IBAction)flipCard:(UIButton *)sender
{
    sender.isSelected  = !sender.isSelected;
}

@end

I am using XCode version 4.6.3, building a single view iPhone app, running it in iPhone 6.1 Simulator.

One difference I've observed in property isSelected in the video from mine is that in the video the isSelected is inherited from UIControl, whereas in my code the small documentation that comes up when alt-click says it's inherited from UITableViewCell instead.

I think that might be the reason behind this error, but don't know what those terms mean.

Can anybody help me with this issue? Thanks in advance!

Upvotes: 1

Views: 4438

Answers (2)

gaige
gaige

Reputation: 17481

It's not uncommon for BOOL values for a particular @property to use a slightly different method pattern, whereby the setter is -set<property>: and there's an alternative getter for -is<property>, which can cause some confusion when accessing through properties or KVC.

In this case, as @shem points out, the property you're looking for is selected, even though it's exposed in the API as -isSelected if you were to send a message to it, such as [sender isSelected].

You can see this if you look in the declaration for the property in UIControl (as UIButton is a subclass of UIControl):

@property(nonatomic, getter=isSelected) BOOL selected

Note that it overrides the getter, indicating that the messages used to implement the selected property are actually -setSelected: and -isSelected. In the end, though, this does not affect how you access the property when using dot notation, it's always just sender.selected.

This is really only important when looking at sample code that uses the method calls and then implementing using the properties.

Upvotes: 4

shem
shem

Reputation: 4712

It's selected and not isSelected :

- (IBAction)flipCard:(UIButton *)sender
{
    sender.selected  = !sender.selected;
}

Upvotes: 4

Related Questions