This past week John Sundell wrote a blog post (Unit testing asynchronous Swift code) about unit testing asynchronous code.

As I was trying to apply some fo the techniques when I came across a method I couldn’t mock because I was getting an error.

Objective-C method addNotificationRequest:withCompletionHandler: provided by method add(_:withCompletionHandler:) does not match the requirement’s selector (add:withCompletionHandler:)

Consider the following method for UNUserNotificationCenter in Swift.

func add(_ request: UNNotificationRequest, withCompletionHandler completionHandler: ((Error?) -> Swift.Void)? = nil)

If you would want to create a Swift protocol to mimic the interface to UNUserNotificationCenter that would be pretty simple.

@objc
protocol UserNotificationCenter {
	func add(_ request: UNNotificationRequest, withCompletionHandler completionHandler: ((Error?) -> Swift.Void)?)
}

The problem is that the method signature in Swift is different from the method signature in Objective-C. Here is the method definition in Objective-C.

- (void)addNotificationRequest:(UNNotificationRequest *)request withCompletionHandler:(nullable void(^)(NSError *__nullable error))completionHandler;

Since the Objective-C method has a different method signature than the Swift version, we have to specify the Objective-C method signature in our protocol.

@objc(addNotificationRequest:withCompletionHandler:)
func add(_ request: UNNotificationRequest, withCompletionHandler completionHandler: ((Error?) -> Swift.Void)?)

Now we can implement that method in our mock object!

I love podcasts. Podcasts are a great medium that I use for entertainment and learning. I have had many people interested in the podcasts I listen to so I figured I’d put a list of them in one place.

Today I needed an HDMI to DVI cable to connect a computer to a monitor. I wanted it right away so I started looking online for the cable at local computer stores. I planned to find the best deal and then drive to pick it up in the store. That was my plan until I found out that the more affordable cables were not available for store pickup. My only options were $15 - $30 cables and adapters.

I quickly checked Amazon to see if the prices were comparable. Not even close. The Amazon cable, exactly what I wanted, was only $6. Then I remembered that I live in a Prime Now location. (Prime Now is a part of Amazon Prime. When you order through Prime Now, they will deliver your order in 2 hours.) Sure enough, the cable was available via Prime Now. I even had to add another $14 to my cart since the minimum for delivery is $20. So in all I got the cable I wanted and some other goodies for under the price it would have cost me to get just the cable at Best Buy. Even better, I didn’t have to leave the house!

I can’t believe that the best deal for the cable I wanted at Best Buy was $30 + tax. Best Buy and other tech stores are doing it to themselves. If they can’t compete with the prices and convenience of Amazon then good riddance.

It’s a good thing these “experts” don’t work for Apple. That car is hideous.

Link: http://www.motortrend.com/news/apple-car-exclusive/

This past Wednesday I gave a talk about CloudKit at Nashville CocoaHeads. It was nice to get to meet everyone there and I am excited to be a part of the meetup! The slides for the presentation can be found here: CloudKit Overview Keynote.

Update 3/2/16

Video is now up on YouTube: CloudKit Overview Video

subscribe via RSS