问题
I just upgraded my mac to 10.10 and Xcode to 6.1,
found a strange thing which about storyboard,
my case is using a swift project, can not connect custom protocol delegate from storyboard anymore.
the old connected which comes with old version of Xcode is fine, but I can not connect any new delegate anymore.
even I can not reconnect the old one once I removed the connected.
Does anyone occur this situation ??
============================== Updated ==============================
View Class
@objc public protocol VideoViewResizeDelegate {
func shouldVideoViewResetLayout(videoView: GvVideoView) -> Bool;
}
@IBOutlet var resizeDelegate: VideoViewResizeDelegate?;
ViewController Class
@IBDesignable public class ViewController: UIViewController, VideoViewResizeDelegate {
...
}
回答1:
https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051
Interface Builder
Interface Builder does not support connecting to an outlet in a Swift file when the outlet’s type is a protocol. Declare the outlet's type as AnyObject or NSObject, connect objects to the outlet using Interface Builder, then change the outlet's type back to the protocol. (17023935)
it's sucks...
回答2:
It's 2017....
Using swift 3, this will work:
open class YourClass: UIView {
#if TARGET_INTERFACE_BUILDER
@IBOutlet open weak var delegate: AnyObject?
#else
open weak var delegate: YourClassDelegate?
#endif
}
A precondition is:
YourClassDelegate must be decorated with @objc
For example:
@objc public protocol MyDelegate: class {
func myFunc()
func myFunc2()
}
Update
This should be fixed in Xcode 9
来源:https://stackoverflow.com/questions/26603571/can-not-connect-custom-protocol-delegate-from-storyboard-in-xcode-6-1