Proud Member
Proud Member

Reputation: 40496

How to check at runtime if a class method exists or not?

Since iOS5, UIKit can be customized with custom images. We have an app which must stay compatible with iOS 4, but if a user has iOS 5 we want to customize a slider.

Example:

[[UISlider appearance] setMaximumTrackImage:maxImage forState:UIControlStateNormal];

What's a safe way for checking at runtime if it's OK to do this call? The respondsToSelector: method is for instances only, but here it's a class itself.

Upvotes: 2

Views: 5169

Answers (1)

Max
Max

Reputation: 16719

You can use resolveClassMethod: for that, e.g.:

[MYClass resolveClassMethod: @selector(trololo)];

Or you can use respondsToSelector: since classes are also objects in Objective C.

Upvotes: 8

Related Questions