Hi,<div><br></div><div>I don't understand your comment, can you explain some more please?</div><div><br></div><div>Thanks,</div><div><br></div><div> -- Howard. <span></span><br><br>On Monday, 21 March 2016, zh ao <<a href="mailto:owenzx@gmail.com">owenzx@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">You protocol is not defined properly.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 21, 2016 at 7:08 AM, Howard Lovatt via swift-users <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','swift-users@swift.org');" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">HI,<div><br></div><div>Does anyone know what is happening here:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p>protocol Subscriptable {</p></div><div><p> associatedtype Element</p></div><div><p> associatedtype Index</p></div><div><p> var firstIndex: Index { get }</p></div><div><p> var lastIndex: Index { get }</p></div><div><p> subscript(index: Index) -> Element { get set }</p></div><div><p>}</p></div><div><p><br></p></div><div><p>struct AllSubscriptable<E, I>: Subscriptable {</p></div><div><p> typealias Element = E</p></div><div><p> typealias Index = I</p></div><div><p> let firstIndexee: () -> I</p></div><div><p> let lastIndexee: () -> I</p></div><div><p> let subscriptee: (index: I) -> E</p></div><div><p> let setSubscriptee: (index: I, element: E) -> Void</p></div><div><p> var firstIndex: I { return firstIndexee() }</p></div><div><p> var lastIndex: I { return lastIndexee() }</p></div><div><p> subscript(index: I) -> E {</p></div><div><p> get { return subscriptee(index: index) }</p></div><div><p> set { setSubscriptee(index: index, element: newValue) }</p></div><div><p> }</p></div><div><p>}</p></div><div><p><br></p></div><div><p>extension Array {</p></div><div><p> var asScriptable: AllSubscriptable<Element, Int> {</p></div><div><p> return AllSubscriptable(</p></div><div><p> firstIndexee: { return self.startIndex }, // Error: Cannot convert `() -> Int` to expected `() -> _`</p></div><div><p> lastIndexee: { return self.endIndex },<br></p></div><div><p> subscriptee: { return self[$0] },</p></div><div><p> setSubscriptee: { self[$0] = $1 }</p></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p> )</p></div><div><p> }</p></div><div><p>} </p><p><br></p></div></blockquote>The error, "Cannot convert `() -> Int` to expected `() -> _`", on the `firstIndexee` closure is very strange since the types are correct and the same as `lastIndexee` which does not have an error. <div><br></div><div>Also if the set subscript in Subscriptable and then all the other set support in AnySubscriptabe and in the extension is removed, then no error.</div><div><br></div><div>Any clues to why?<span><font color="#888888"><br><div><br></div><div>-- Howard.<br></div></font></span></div></div>
<br>_______________________________________________<br>
swift-users mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','swift-users@swift.org');" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br>-- <br>-- Howard.<br>