<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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">{
    </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre"> {
        </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">(type(of:</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">))
    }
    
    </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre"> {
        </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">(</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">)
    }
}

</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">{
    
}

</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre"> foo = </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">()
foo.printType() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">
foo.printSelf() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">

</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre"> bar = </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">()
bar.printType() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">
bar.printSelf() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">

</span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre"> test = </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">()
test.printType() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">
test.printSelf() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">

test = </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">()
test.printType() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,monospace;font-size:11px;white-space:pre">
test.printSelf() </span><span class="" style="margin:0px;padding:0px;border:0px;font-family:Menlo,Monaco,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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,&#39;Andale Mono&#39;,&#39;lucida console&#39;,&#39;Courier New&#39;,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">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</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 -&gt; Self means. Self is a placeholder for “the current type”, just like self is a placeholder for “the current instance”. So when you declare -&gt; 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() -&gt; String<br>
}<br>
<br>
class Bar: Foo {<br>
    func instance() -&gt; String {<br>
       return “blah&quot;<br>
    }<br>
}<br>
<br>
-Kenny<br>
<div><div class="h5"><br>
<br>
&gt; On Aug 27, 2016, at 7:05 AM, Zhao Xin via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; See the code:<br>
&gt;<br>
&gt; protocol Foo {<br>
&gt;     func instance() -&gt; Self<br>
&gt; }<br>
&gt;<br>
&gt; class Bar: Foo {<br>
&gt;     func instance() -&gt; Self {<br>
&gt;         return self // Declaration: let `self`: Self<br>
&gt;     }<br>
&gt;     func other() {<br>
&gt;         let i = self // Declaration: let `self`: Bar<br>
&gt;     }<br>
&gt; }<br>
&gt;<br>
&gt; How does it happen?<br>
&gt;<br>
&gt; Zhaoxin<br>
</div></div>&gt; ______________________________<wbr>_________________<br>
&gt; swift-users mailing list<br>
&gt; <a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
&gt; <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>