Questions tagged [respondstoselector]

`responds#to` is a Swift call, which checks if an object indeed responds to the given selector. For example, `if (x.responds(to: #selector(SomeClass.someCall))`.

41 questions
30
votes
3 answers

Objective-C: Why check nil before respondsToSelector:?

I've seen code like: if (delegate != nil && [delegate respondsToSelector:@selector(doSomething)]) ... But, sending a message to nil just returns nil (which evaluates to NO), so why not just do: if ([delegate…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
21
votes
5 answers

super respondsToSelector: returns true but actually calling super (selector) gives "unrecognized selector sent to instance"

OK, I am a little confused. I have a subclass of UIScrollView, which is my attempt at a horizontally scrolling "table view" like UI element. UIScrollView itself sets up UIGestureRecognizers it uses internally, and it appears to set itself up as the…
7
votes
2 answers

( ConformsToProtocol: && RespondsToSelector: ) vs just ( respondsToSelector: )

When wanting to call a protocol method on a delegate object that, hopefully, implements the respective protocol method, I see developers first checking if([delegate respondsToSelector: @selector(aMethod)]) { //send message; } Is it…
pnizzle
  • 6,243
  • 4
  • 52
  • 81
6
votes
3 answers

How do you know whether to invoke a superclass method in Objective C

Class Child extends Parent. Parent implements protocol C which has optional methods, including -(void)d. Child has an implementation of -d; should it invoke [super d]? In other words, what code do I write to invoke [super d] if and only if something…
Phil Willoughby
  • 1,649
  • 12
  • 16
6
votes
4 answers

Are performSelector and respondsToSelector banned by App Store?

My latest build was accepted into the Apple app store, but I got the notice quoted below a couple of days later. My app also uses Rollout.io, and I asked explicitly if this was the problem. No response yet. If respondsToSelector or performSelector…
Rayfleck
  • 12,116
  • 8
  • 48
  • 74
5
votes
3 answers

iOS Version Checking gives warning

In my app I need to present a view controller. The 6.0 method for presenting a view controller is presentViewController:animated:completion:. I want to support 4.3 also. In 4.3 the method to be called is presentModalViewController:animated:. So I…
saikamesh
  • 4,569
  • 11
  • 53
  • 93
4
votes
3 answers

Objective C - respondsToSelector for dynamic properties

I am currently facing the problem to check whether a property of an Object (NSManagedObject) exists or not. Unfortunately the method [[MyObject class] respondsToSelector:@selector(myProperty)]; always returns NO. I think it's because the property…
Alexander
  • 7,178
  • 8
  • 45
  • 75
4
votes
3 answers

Objective-C: How to check if a C function is supported

How can I perform a run-time check to see if I can use UIGraphicsBeginImageContextWithOptions, which is only available starting with iOS 4. I know I could check [[UIDevice currentDevice] systemVersion], but Apple recommends using things like…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
4
votes
2 answers

doesNotRecognizeSelector error after respondsToSelector check

Short description: I get doesNotRecognizeSelector error when call method on object that definitely has this method and it happens after calling respondsToSelector. It's a very strange situation and I didn't understand how it can be :). I saw this…
comrade
  • 4,590
  • 5
  • 33
  • 48
4
votes
2 answers

respondsToSelector: not working for delegate

I am new to iOS world and have run into an issue while trying to pass a value from a TableView back to the home controller. The scenario that I am working on is Home Controller has a button Click of button opens a list of items in the second…
Vivek
  • 957
  • 4
  • 12
  • 18
4
votes
3 answers

Can't remove shadow from UINavigationBar

I can't remove the shadow from my UINavigationBar for some reason on iOS6. Why isn't this working? I've tried the following: if ([[UINavigationBar appearance]respondsToSelector:@selector(setShadowImage:)]){ [[UINavigationBar…
aroooo
  • 4,726
  • 8
  • 47
  • 81
3
votes
1 answer

Why delegate.respondsToSelector (Selector ("testEnum:")) this code will return false in swift language?

I was a few days ago from Objective-C to write Swift language, in the project I have encountered a problem.This problem is when using respondsToSelector ("testEnum:") function to check whether to implement the function of the testEnum:,if the param…
fly_basket
  • 49
  • 7
3
votes
4 answers

Establish callback in Swift for PubNub 4.0 to receive messages

It appears to me that the documentation PubNub has for getting started in Swift don't apply to versions earlier than PubNub 4.0. I can't successfully establish a callback to register with PubNub. My code: class Communicator: NSObject,…
Scott Lobdell
  • 527
  • 1
  • 4
  • 11
3
votes
2 answers

How to pass string from a text field (embedded in a table cell) in 2nd controller back to a label in 1st controller (also embedded in a table cell)?

Edit 1: I think I have figured out the problem, I just haven't been able to solve it. In SecondViewController.m where textFieldShouldReturn is defined, "if ([self.delegate respondsToSelector:@selector(passString:)])" returns false, since NSLog was…
3
votes
2 answers

How to test Selectors on proxy-objects in Objective-C?

Is there any way to test selectors/methods when all you have is a proxy object? /* Proxy which may forward * the method to some other object */ id proxy = [UINavigationBar appearance]; /* This condition returns FALSE * despite the fact that the…
eric
  • 4,863
  • 11
  • 41
  • 55
1
2 3