> On Nov 15, 2016, at 8:53 AM, Rick Mann <[email protected]> wrote:
> 
> 
>> On Nov 14, 2016, at 22:51 , Charlie Monroe via swift-evolution 
>> <[email protected]> wrote:
>> 
>> One major example is the NS/UITableViewDataSource or Delegate - there are 
>> many many methods that you don't need to implement, hence are optional.
>> 
>> But I think that this was partially solved by default implementation of 
>> protocol methods, which pretty much does what you want...
> 
> I just realized I only responded to someone else, and not the whole list. It 
> does, but it forces me to make the return value of the protocol method 
> optional, so that the default implementation can return nil. 

You'd still get an optional even with @optional protocol methods:

@objc
protocol Foo {
        @optional func bar() -> Int
}

let x = foo.bar?() // x is Int?

Nevertheless, in the previous example:

>       var titleForRow:((_ indexPath:IndexPath)->(String))? { get }

You can return String? in the closure instead and the default implementation 
can simply return a closure that returns nil. This is pretty much equivalent.


> In the end, I guess that's not so bad, since I'm not happy with the entire 
> approach, but it'll do for now.
> 
> -- 
> Rick Mann
> [email protected]
> 
> 

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to