Interface Builder, @IBOutlet and protocols for delegate and dataSource in Swift
From the Xcode release notes:
Interface Builder does not support connecting to an outlet in a Swift file when the outlet’s type is a protocol.
Workaround: 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.
EDIT: Xcode 9 beta 3 release notes say that this workaround should no longer be necessary.
Is it possible to connect delegate and dataSource of CustomViews in interface builder?
You'll need to meet these conditions:
- The view's
Custom Class
should be set to your custom view's class name in Interface Builder (via the Identity Inspector). If your delegate or dataSource object is also a custom view, also make sure that that view's Custom Class is set - The
@interface
for your custom class should decorate its delegate and dataSource properties withIBOutlet
. For example,@property (nonatomic, weak) IBOutlet id <SomeProtocol> delegate;
- If you declared protocol(s) for your delegate or dataSource, the target object that you want to use as the delegate or dataSource should be declared as implementing that protocol
How to link Table dataSource and delegate outlets to UITableViewController?
In your storyboard, select the UITableView
and change this to the name of your UITableViewController
subclass. You then do not need to do any linking stuff.
Can not connect custom protocol delegate from storyboard in Xcode 6.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...
swift protocol, IBOutlet property cannot have non-object type
You have to declare your ThumbnailTableViewCellDelegate
protocol as @objc
:
@objc protocol ThumbnailTableViewCellDelegate {
func cellWasTouched(thumbnail: Bool, cell: UITableViewCell)
}
This is because @IBOutlet
declares the variable as weak
, which only works with objects. I'm not sure why you can't just say the protocol conforms to AnyObject
, perhaps that's a Swift bug.
@IBInspectable in Swift 4.0
Add notation @objc for both delegate and datasource in Swift 4 (as shown in below code)
open class SVContactBubbleView: UIView {
@IBInspectable open var dataSource: SVContactBubbleDataSource?
@IBInspectable open var delegate: SVContactBubbleDelegate?
}
@objc // add notation here
public protocol SVContactBubbleDataSource
{
//Methods here
}
@objc // add notation here
public protocol SVContactBubbleDelegate
{
//Methods here
}
Here is ref. snapshot with error resolution:
Here is Apple document for @objc
notation - Protocol - Optional Protocol Requirements
@IBOutlet implemented as property wrapper?
No. @IBOutlet
is a "Declaration Attribute", documented here.
Reference main NSWindow in AppDelegate using Storyboard?
I dont know if this is correct way of doing, but this will solve your problem.
Decalre a NSWindow property in AppDelegate
weak var window: NSWindow!
and set the property in something like windowWillLoad of the NSWindowController
(NSApplication.sharedApplication().delegate as! AppDelegate).window = self.window
You will have to subclass NSWindowController to define windowWillLoad
Related Topics
Wkwebview Does Not Load Links to Pdfs
Swift Sphere Combine Star Data
Alamofire Asynchronous Completionhandler For Json Request
Include Swiftui Views in Existing Uikit Application
Generating Random Numbers With Swift
Swiftui - Is There a Popviewcontroller Equivalent in Swiftui
What's the Difference Between Using Aranchor to Insert a Node and Directly Insert a Node
Generic Swift 4 Enum With Void Associated Type
Ios13 Navigation Bar Large Titles Not Covering Status Bar
How to Configure Contextmenu Buttons For Delete and Disabled in Swiftui
Nsimage to Nsdata as Png Swift
Using Function Parameter Names in Swift
Arkit: Placing an Scntext at a Particular Point in Front of the Camera
Simpliest Solution to Check If File Exists on a Webserver. (Swift)
Variable 'Xxx' Was Never Mutated, Consider Changing to 'Let'
Stop a Dispatchqueue That Is Running on the Main Thread
Firebase Instanceid.Instanceid().Token() Method Is Deprecated