日記
ブルプロの話を聞いた.リリースまでにはPCパーツ全部安くなって円高になってくれ.
今日書いたコード
import UIKit class Cls { init() { let someButton = UIButton() someButton.target(forAction: #selector(tapSomeButton), withSender: nil) let otherButton = UIButton() otherButton.target(forAction: #selector(tapOtherButton), withSender: nil) } } @objc extension Cls { func tapSomeButton() {} func tapOtherButton() {} }
感想
extension
に@objc
をつけると,その中で宣言された,@nonobjc
がついてないメンバすべてに@objc
をつけるのと同じことになる.上のコードみたいにまとめられるけどそこまでしたいことはなさそう.
Applying this attribute to an extension has the same effect as applying it to every member of that extension that isn’t explicitly marked with the nonobjc attribute. https://docs.swift.org/swift-book/ReferenceManual/Attributes.html