Questions tagged [protocol-extension]
90 questions
3
votes
1 answer
UIButton stop showing UIControl actions in interface builder after adding extension to it
I have the simplest UI - just one button:
As you can see, I can drag any event (like UITouchUpInside) from interface builder to my code.
BUT if I add some extension to UIButton like:
protocol SomeProtocol {}
extension UIButton: SomeProtocol…

Fyodor Volchyok
- 5,610
- 4
- 28
- 45
3
votes
1 answer
Extending custom type where associated type is equal to Void
I'm in a situation where I have a custom type that contains an associatedtype. In the case where this is equal to Void, I would like to have some default behaviour (to make the call-site more convenient). I tried to boil the example down…

Steffen D. Sommer
- 2,896
- 2
- 24
- 47
3
votes
1 answer
How to set delegate in a protocol extension
I have multiple view controllers which shows same kind of cells. I want to set delegate in a protocol extension like this:
class ProductsViewController: UIViewController, ProductShowcase {
//other properties
@IBOutlet weak var…

osrl
- 8,168
- 8
- 36
- 57
3
votes
2 answers
Mutating Function in Protocol Extension Where Self is UIViewController
I've written a protocol and corresponding extension which utilizes a simple StringStack in tandem with a naming convention of the form "@" to perform segues between nested views in my Swift application. I'm new to swift so if…

rmorshea
- 832
- 1
- 7
- 25
3
votes
0 answers
How to use Swift protocol with extension in Objective-C?
I'm trying to use a Swift in an Objective-C class, but having trouble with the syntax or even if it's possible. Below is what I'm trying.
Swift:
@objc protocol MyProtocol {
var someManager: MyManager? { get set }
var someState: MyState {…

TruMan1
- 33,665
- 59
- 184
- 335
3
votes
1 answer
Default implementation of protocol method with Swift extension
I'm trying to write default behaviour for a delegate method using a Swift extension as below, but it is never called. Does anyone know why or how to do it the right way?
extension NSURLSessionDelegate {
public func URLSession(session:…

Stephan
- 881
- 9
- 24
3
votes
2 answers
Swift 2.0 Protocol as a Type Extension
While playing around in playground with protocol extension I came to strange error. More precisely I declared a protocol and used it as type in the following manner :
protocol InvokeProtocol{
func invokeA()
func invokeB()
}
class…

Zell B.
- 10,266
- 3
- 40
- 49
2
votes
1 answer
Instance is necessarily treated as value type in extensions of non-class-bound protocols
Here's the code:
protocol A {
var a: Int { get set }
}
extension A {
var convenientAccessor: Int {
get { return a }
set { a = newValue }
}
}
class B: A {
var a: Int = 0
}
func acceptsB (instance: B) {
instance.a = 1 …

jeremyabannister
- 3,796
- 3
- 16
- 25
2
votes
1 answer
Protocol with Empty Init
I am using a framework that has a 'user' protocol with all the desired properties listed, the protocol also has an empty init method. I need to create a user but any instance I create using the protocol complains that the init doesnt initialize all…

user499846
- 681
- 3
- 11
- 24
2
votes
1 answer
Protocol extension and subclassing issue
So here is a thing I wanted to use the protocol oriented programming paradigm with the OOP to have some of variables assigned to main classes like let's say UIView, UIImageView etc. but then have some other variables defined in their subclasses. To…

matthewfx
- 1,244
- 1
- 9
- 14
2
votes
1 answer
Calling protocol extension function from selector
i have protocol class named MenuDisplayable. This protocol has an extension.
protocol MenuDisplayable {}
extension MenuDisplayable where Self: UIViewController {
func showMenu( ) {
let storyboard = UIStoryboard(storyboard: .Menu)
let menuVC =…

Murat Yılmaz
- 51
- 2
2
votes
2 answers
Protocol extension methods don't get called when protocol extends existing Apple API protocol
I want a protocol to inherit from an Apple protocol UIViewControllerTransitioningDelegate, add additional protocol requirements and provide a default implementation for some methods in that protocol. When I do that, the methods do not get called.…

SirRupertIII
- 12,324
- 20
- 72
- 121
2
votes
1 answer
Ambiguous functions in multiple protocol extensions?
I have multiple protocols that have the same function name. Some protocols have associated types, where I can't figure out how to call the functions as I do in non-generic protocols. I get the error: Protocol 'MyProtocol1' can only be used as a…

TruMan1
- 33,665
- 59
- 184
- 335
2
votes
3 answers
Extending UIApplicationDelegate Protocol
I would like to extend UIApplicationDelegate protocol and provide a default implementation for application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool method. However, default…

user1994321
- 81
- 1
- 8
2
votes
1 answer
Protocol extensions are not in effect (Swift)
As of the time of writing this question, I am using Swift 2.1 and Xcode 7.2.1.
The code below (meant for encoding a struct) does not work and makes an Xcode playground crash without error. When in a project, it causes a segmentation fault during…

Learing
- 559
- 4
- 13