Movatterモバイル変換


[0]ホーム

URL:


Monday,June6,2016

Avoiding the Overuse of @objc in Swift

Swift 2.2’s#selector syntax introduces a new compiler error:

Argument of '#selector' refers to a method that is not exposed to Objective-C.Fix-it   Add '@objc' to expose this method to Objective-C

Jesse Squires:

We cannot simply add@objc to this method in the originalViewControllerType protocol for a number of reasons. If we do, then the entire protocol needs to be marked@objc, which means[…] Our example here is simple, but imagine a much more complex object graph that makes heavy use of Swift’s value types and a hierarchy of three protocols with this one in the middle. Introducing@objc as the fix-it suggests wouldbreak the entire world in our app.

[…]

We can decompose this protocol by separating out all of the@objc code into its own protocol. Then, we can use protocol composition to reunite them.

CommentsRSS ·Twitter

Leave a Comment

  

Black Friday
Blog
Archives
Tag Cloud
Top Posts

Recently Updated
RSS Feed ·Comments
Mastodon ·Twitter
Apple News
Trackback

Support this site viaPatreon.

Try my Mac apps:

DropDMGDropDMGDropDMG
EagleFilerEagleFilerEagleFiler
SpamSieveSpamSieveSpamSieve
ToothFairyToothFairyToothFairy
Copyright © 2000–2025Michael Tsai.

[8]ページ先頭

©2009-2025 Movatter.jp