• Objective-C selectors in Swift I was building...
Objective-C selectors in Swift
I was building new exercises in Swift—Apple’s new development language—for our upcoming iOS training class in San Francisco, and when combining Swift and Cocoa Touch, I discovered something really interesting.
In particular, for this tutorial, I will examine methods that require a selector as the argument, such as: performSelector:, respondsToSelector: or performSelector:withObject:afterDelay:.
For this example, I will create an NSTimer that will change the background color of a viewcontroller’s view every second. An NSTimer, just to refresh the concept, represents a timer object that waits until a certain time interval has elapsed and then fires, sending a specified message to a target object.
First, let’s write some code in Objective-C. If you are familiar with Objective-C, the following example won’t contain any secrets.
Begin by creating an iOS application using the Single-View template. Then, name the project Timer. Next, add a viewDidAppear: method in the ViewController.m and add the following code to the method:
[super viewDidAppear:animated];
NSDictionary *userInfo = @{@