<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">See below code.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(4,51,255)"><span style="font-variant-ligatures:no-common-ligatures">protocol</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> Foo {</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">func</span><span style="font-variant-ligatures:no-common-ligatures"> bar()</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(4,51,255)"><span style="font-variant-ligatures:no-common-ligatures">extension</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Foo</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> {</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">func</span><span style="font-variant-ligatures:no-common-ligatures"> bar() {</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(180,38,26)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">print</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures">"I am bar."</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> }</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">class</span><span style="font-variant-ligatures:no-common-ligatures"> A:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Foo</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">func</span><span style="font-variant-ligatures:no-common-ligatures"> output() {</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">print</span><span style="font-variant-ligatures:no-common-ligatures">(type(of:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">self</span><span style="font-variant-ligatures:no-common-ligatures">)) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,0)">// prints "B".</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,143,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">self</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">bar</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">() </span><span style="font-variant-ligatures:no-common-ligatures">// prints "I am bar."</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> (self </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">as</span><span style="font-variant-ligatures:no-common-ligatures">! </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">B</span><span style="font-variant-ligatures:no-common-ligatures">).</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">bar</span><span style="font-variant-ligatures:no-common-ligatures">() </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,143,0)">// prints "I am B."</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> }</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">class</span><span style="font-variant-ligatures:no-common-ligatures"> B:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">A</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">func</span><span style="font-variant-ligatures:no-common-ligatures"> bar() {</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">print</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(180,38,26)">"I am B."</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> }</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">let</span><span style="font-variant-ligatures:no-common-ligatures"> b = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">B</span><span style="font-variant-ligatures:no-common-ligatures">()</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(52,149,175)"><span style="font-variant-ligatures:no-common-ligatures">b</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures">output</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">()</span></p><p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(52,149,175)"><br></p><p style="margin:0px;line-height:normal"><font color="#000000" face="georgia, serif">I thought `self.bar()` would do the same as `(self as! B).bar()`. It didn't. In my opinion, `type(of:self) is B.type`, so they should be the same, shouldn't they?</font></p><p style="margin:0px;line-height:normal"><font color="#000000" face="georgia, serif"><br></font></p><p style="margin:0px;line-height:normal"><font color="#000000" face="georgia, serif">Zhaoxin</font></p></div></div>