<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">Thanks, Kenny. I found that self is dynamic. Despite the original type of variable. See below code, `test` variable. It was Foo type, but it can be Bar as well.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default" style="font-family:georgia,serif"><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,0,0);white-space:pre"><span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline;color:rgb(170,13,145)">class</span> <span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline;color:rgb(92,38,153)">Foo</span> </span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">{
</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,0,0);white-space:pre"><span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline;color:rgb(170,13,145)">func</span> <span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline">printType</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline;color:rgb(92,38,153)">()</span></span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre"> {
</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(92,38,153);white-space:pre">print</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">(type(of:</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(170,13,145);white-space:pre">self</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">))
}
</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,0,0);white-space:pre"><span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline;color:rgb(170,13,145)">func</span> <span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline">printSelf</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline;color:rgb(92,38,153)">()</span></span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre"> {
</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(92,38,153);white-space:pre">print</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">(</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(170,13,145);white-space:pre">self</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">)
}
}
</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,0,0);white-space:pre"><span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline;color:rgb(170,13,145)">class</span> <span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline;color:rgb(92,38,153)">Bar</span>:<span class="" style="margin:0px;padding:0px;border:0px;font-family:inherit;font-style:inherit;line-height:inherit;vertical-align:baseline;color:rgb(92,38,153)">Foo</span> </span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">{
}
</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(170,13,145);white-space:pre">let</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre"> foo = </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(92,38,153);white-space:pre">Foo</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">()
foo.printType() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,106,0);white-space:pre">// Foo</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">
foo.printSelf() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,106,0);white-space:pre">// Foo</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">
</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(170,13,145);white-space:pre">let</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre"> bar = </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(92,38,153);white-space:pre">Bar</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">()
bar.printType() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,106,0);white-space:pre">// Bar</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">
bar.printSelf() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,106,0);white-space:pre">// Bar</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">
</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(170,13,145);white-space:pre">var</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre"> test = </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(92,38,153);white-space:pre">Foo</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">()
test.printType() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,106,0);white-space:pre">// Foo</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">
test.printSelf() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,106,0);white-space:pre">// Foo</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">
test = </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(92,38,153);white-space:pre">Bar</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">()
test.printType() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,106,0);white-space:pre">// Bar</span><span style="color:rgb(0,0,0);font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;font-size:11px;white-space:pre">
test.printSelf() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,106,0);white-space:pre">// Bar</span><br></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default" style="font-family:georgia,serif"><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,'Andale Mono','lucida console','Courier New',monospace;line-height:inherit;font-size:11px;vertical-align:baseline;color:rgb(0,106,0);white-space:pre"><br></span></div></blockquote><span style="white-space:pre"><div class="gmail_default" style="display:inline"><font face="georgia, serif" color="#000000">So now I think that self should always be Self type.</font></div><font face="Menlo, Monaco, Andale Mono, lucida console, Courier New, monospace" style="color:rgb(0,106,0);font-size:11px"><br></font></span><div><span style="white-space:pre"><div class="gmail_default" style="display:inline"><font face="georgia, serif" color="#000000"><br></font></div></span></div><div><span style="white-space:pre"><div class="gmail_default" style="display:inline"><font face="georgia, serif" color="#000000">Zhaoxin</font></div></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 28, 2016 at 2:05 PM, Kenny Leung via swift-users <span dir="ltr"><<a href="mailto: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">There is no magic happening here. Rather, I think it’s a misunderstanding of what -> Self means. Self is a placeholder for “the current type”, just like self is a placeholder for “the current instance”. So when you declare -> Self, the correct thing to do is an instance of Self, which is self.<br>
<br>
You can see this if you replace Self with String.<br>
<br>
protocol Foo {<br>
func instance() -> String<br>
}<br>
<br>
class Bar: Foo {<br>
func instance() -> String {<br>
return “blah"<br>
}<br>
}<br>
<br>
-Kenny<br>
<div><div class="h5"><br>
<br>
> On Aug 27, 2016, at 7:05 AM, Zhao Xin via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
><br>
> See the code:<br>
><br>
> protocol Foo {<br>
> func instance() -> Self<br>
> }<br>
><br>
> class Bar: Foo {<br>
> func instance() -> Self {<br>
> return self // Declaration: let `self`: Self<br>
> }<br>
> func other() {<br>
> let i = self // Declaration: let `self`: Bar<br>
> }<br>
> }<br>
><br>
> How does it happen?<br>
><br>
> Zhaoxin<br>
</div></div>> ______________________________<wbr>_________________<br>
> swift-users mailing list<br>
> <a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br>
______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
</blockquote></div><br></div>