Subhash
Subhash

Reputation: 175

Checking if Class respondsToSelector not working

The following line compiles fine but incorrectly returns false in iOS 8. Why?

[[NSLayoutConstraint class] respondsToSelector:@selector(setActive:)]

However, the following correctly returns true -

[self.heightLayoutConstraint respondsToSelector:@selector(setActive:)]

where self.heightLayoutConstraint is of type NSLayoutConstraint.

Upvotes: 0

Views: 552

Answers (1)

jscs
jscs

Reputation: 64002

setActive: is not a class method on NSLayoutConstraint, so the return value is correct: the class itself does not respond to that selector.

I think you're looking for the class method +instancesRespondToSelector:

[NSLayoutConstraint instancesRespondToSelector:@selector(setActive:)]

Upvotes: 2

Related Questions