Can't hook custom protocol delegate from storyboard in Xcode 6.1

I just updated my mac to 10.10 and Xcode to 6.1.

found a weird thing about storyboarding,

In my case using a swift project, it is no longer possible to bind the custom protocol delegate from the storyboard.

the old connected one that ships with the old version of Xcode is fine, but I can't connect the new delegate anymore.

even i can't reconnect the old one once i removed the connected one.

Is there such a situation?

=================================================== =================================================== =========

View class

@objc public protocol VideoViewResizeDelegate {

    func shouldVideoViewResetLayout(videoView: GvVideoView) -> Bool;

}

@IBOutlet var resizeDelegate: VideoViewResizeDelegate?;

      

ViewController class

@IBDesignable public class ViewController: UIViewController, VideoViewResizeDelegate {

...

}

      

+3


source to share


2 answers


https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051

Interface constructor

The Builder interface does not support plugging into an outlet in a Swift file when the output type is protocol. Declare the outlet type as AnyObject or NSObject, connect the objects to the outlet using Interface Builder, then change the outlet type back to protocol. (17023935)



it sucks ...

+12


source


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 :

YourClassDelegate should be decorated with @objc



For example:

@objc public protocol MyDelegate: class {
    func myFunc()
    func myFunc2()
}

      

Update

This should be fixed in Xcode 9

+5


source







All Articles