Another favourite from Xcode 7.3

In previous versions of Xcode, if you were working with Swift and tried to override a var from a super-class, you had no auto-completion suggestions. Most if the time, I had to go into the super declaration to copy the signature and then just add override in front of it.

Xcode 7.3 changes that, for good.

Yay! 🎉

#selector

One of my favourite changes in Swift 2.2 is that Objective-C selectors now are first class citizens in the Swift ecosystem. So long to error-prone selector names as Strings.

Swift 2.2 lets you use the #selector expression to reference a selector from your Swift code.


class MyView: UIView {
    private lazy var button: UIButton = {
        let b = UIButton()
    
        // Swift 2.1 and earlier
        b.addTarget(
            self,
            action: "buttonTapped:",
            forControlEvents: .TouchUpInside
        )
        
        // Swift 2.2
        b.addTarget(
            self,
            action: #selector(MyView.buttonTapped(_:)),
            forControlEvents: .TouchUpInside
        )
        return b
    }()
    
    func buttonTapped(sender: UIButton) {
        // ...
    }
}

My only complain about this is that the actions still need to be declared either internal or public, declaring the action as private returns the error Argument of '#selector' refers to a method that is not exposed to Objective-C, which makes sense if yout think about it.

EDIT: I should have read the error message more carefully.

Turns out that if you want your selector to be private, you only need to add the @objc attribute to the function declaration, and you’re set:

extension Selector {
    static let cancelButtonTapped = #selector(MyView.cancelButtonTapped)
}

class MyView: UIView {
    @objc fileprivate func cancelButtonTapped() {
        // ...    
    }
}

EDIT: In Swift 3.0, the function needs to be set to fileprivate in order to be available from outside its scope.

On Leveling Up as a Developer

I just read this post from David Bryant Copeland at naildrivin5.com.

This resonated with me:

[…] This may seem like a lot, but these meetings are crucial. Having dedicated time with your manager every week is important. So is having a weekly time to talk with the people for whom you are building software about priorities. And if you aren’t part of these discussions, they are still going to happen, but they will lack your input. That could go bad for you.

I’ve been on both ends of the spectrum before. Neither of which is good, you have to strive to find a balance there.