<div dir="ltr">There is a *bug* that the Swift people know about, but you are **meant** to be able to do this:<div><br></div><div><blockquote style="font-size:12.8px;margin:0px 0px 0px 40px;border:none;padding:0px">ModuleA<br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">A.swift</blockquote><span class="gmail-m_8276977146152905134gmail-im"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">public protocol P {</blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">func m() -&gt; String</blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">}<br></blockquote></blockquote></span><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">extension Int: P {</blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">public func m() -&gt; String { <span style="font-size:12.8px">return &quot;AP.m&quot; </span><span style="font-size:12.8px">}</span></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">}<br></blockquote></blockquote></blockquote><blockquote style="font-size:12.8px;margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"></blockquote>ModuleB<br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"></blockquote>B.swift<br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><span class="gmail-m_8276977146152905134gmail-im">public protocol P {<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">func m() -&gt; String</blockquote>}<br></span>extension Int: P {<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">public func m() -&gt; String { <span style="font-size:12.8px">return &quot;BP.m&quot; </span><span style="font-size:12.8px">}</span></blockquote>}<br></blockquote></blockquote></blockquote><blockquote style="font-size:12.8px;margin:0px 0px 0px 40px;border:none;padding:0px">ModuleC<br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">A.swift</blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">import ModuleA</blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">func am(_ i: Int) -&gt; String { return i.m() }<br></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">B.swift<br></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">import ModuleB</blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">func bm(_ i: Int) -&gt; String { return i.m() }<br></blockquote></blockquote></blockquote><blockquote style="font-size:12.8px;margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">main.swift<br></blockquote></blockquote><blockquote style="font-size:12.8px;margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"></blockquote></blockquote>let i = 0<br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"></blockquote></blockquote>print(am(i))<br>print(bm(i))</blockquote></blockquote></blockquote></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">  -- Howard.<br></div></div>
<br><div class="gmail_quote">On 21 June 2017 at 00:02, David Baraff 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"><div style="word-wrap:break-word">I posted this on Apple’s developer forums, and someone suggested trying this here.<div>Basically, see <a href="https://forums.developer.apple.com/thread/80349" target="_blank">https://forums.developer.<wbr>apple.com/thread/80349</a></div><div><br></div><div>but in a nutshell: consider that a widely used class/struct (such as CGPoint) is missing some “obvious” functionality [don’t debate that part, just go with it for now], such as the ability to scale a point by a scalar using * as an operator: so in my awesome library “GeometryBase” I write</div><div><br></div><div>  public func * (left: CGPoint, right: double) -&gt; CGPoint {</div>      return CGPoint(x: right*left.x, y: right*left.y)<br>  }<div><br></div><div>Why public?  Well, of course, because I want to use library GeometryBase in many apps or other libraries, and now this overload exists in only one place.</div><div><br></div><div>But other bright people have the same idea, and now I want to use their libraries.  (some of them in my company, some of them not.)</div><div><br></div><div>And now we’re stuck, because everyone is trying to make up for the same (perceived) lack and everyone wants them public so that they don’t have to keep sticking them in each library they write.</div><div><br></div><div>This is not a made up situation: many people even within one company trying to share code somewhat informally are going to write the same code to make using CGPoint/Size/Rect easier, and now we can’t share anything safely.</div><div><br></div><div>Anybody got some good ideas what to do about this?</div><div><br></div><div>[Same question could apply to adding extensions.]</div><div><br></div></div><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>
<br></blockquote></div><br></div>