<div dir="ltr">Wow, thanks for all the details around here<br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 22, 2015 at 2:01 PM, Christos Vasilakis <span dir="ltr">&lt;<a href="mailto:cvasilak@gmail.com" target="_blank">cvasilak@gmail.com</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">Hi team,<div><br></div><div>a little heads up on an issue that I‘ve been looking the last days, on how to proper support both an Obj-C and a Swift library (in-parallel) on Cocoapods. There was a discussion on the cocoapods issues tracker[1] basically around two ideas:</div><div><br></div><div>a) being a separate project, with a new name plus utilising Swift specific language propers.</div><div>b) having one project, utilising cocoapods subspec mechanism to include specific files per spec requested. In a nutshell users will employ in their Podfile something of a form:</div><div><br></div><div>—</div><div>pod “MyFooBarLibrary/Objc’    (objective-c) </div><div>or</div><div>pod “ MyFooBarLibrary/Swift’   (Swift)</div><div>—</div><div><br></div><div>Solution (b) was intrigued and went on to discover more, since I haven’t used before the subspec mechanism and was a good opportunity to learn. The issue mentioned two projects, QueryKit[2] and ReactiveCocoa[3] (their Swift branch) that utilise this mechanism, so I dive in trying to see how it works. </div><div><br></div><div>My realisations:</div><div>a) both projects are designed with ‘Swift first’ approach, employing _some_ &#39;Objective-C code’  to ease the interaction in a mixed project e.g Objective-C code calling the ‘Swift’ library, see [4] where the author describes more details on this.</div><div>b) since ‘Swift first’, both produce frameworks where they can be integrated either in objective-c or swift language projects, no ‘static-library’ targets.</div><div>c) both are designed for iOS &gt;= 8.0</div></div></blockquote><div><br></div><div>ouch - what do they do for iOS7 ? </div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>To make it short and from my understanding,  the projects are _not_ designed around the idea of: take either the Objective-C or the Swift port in you project, but instead employ an Objective-C subspec to “ease” the interaction in a mixed environment, aka Objective-C code calling the Swift library.</div><div><br></div><div>Regardless and to better understand, I did some testing with our push-sdk:</div><div><br></div><div>a) having a single Swift Project employing both the objective-c code and Swift code</div><div>b) having a .workspace with a) Obj-c xcodeproj, b) Swift xcodeproj.</div><div><br></div><div>In both cases, this mixed approaches, at the end caused issues and wasn’t able to generate a proper solution. Issues around a) cocoapods &#39;pod install’ steps, b) tests on the library are done with two different dependencies c) various other integration issues…</div><div><br></div><div>It’s my sense, the most clean way is to go with separate libraries, that is solution (a) described above (a solution proposed also from @orta [5]) This has the added benefit of cleaner &#39;logistics’ that is: commit history, releases, static/framework library generations etc etc.</div></div></blockquote><div><br></div><div>+1000 :-) When reading, I was actually wondering about these logistics :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>But there is one issue if we go with separate approach:  _cocoapods naming_, that is how to properly separate between the two.</div><div><br></div><div>Currently searching for AeroGear-Push in <a href="http://cocoapods.org" target="_blank">cocoapods.org</a> site we get the following:</div><div><br></div><div><img height="133" width="497" src="cid:047C6EAB-E73D-49C9-A294-9AE377832A74"></div><div><br></div><div><br></div><div>In my cocoapods PR [6] I went with the approach to name the ‘Swift’ equivalent library as &#39;AeroGear-Push-Swift’, so the same searching above will reveal:</div><div><br></div><div>—</div><div>AeroGear-Push</div><div>AeroGear-Push-Swift</div><div>—</div><div><br></div><div>Some of you have already noticed, that the ‘hyphen’ character as a podspec name doesn’t work well with a Swift Project, cause the podspec name is used as the name of the final #import statement the user does. That is the following import statement doesn’t work:</div><div><br></div><div>—</div><div>import AeroGear-Push-Swift</div><div>—</div><div><br></div><div>Solving this, there are two approaches:</div><div><br></div><div>a) rename both library podspecs : Objective-C to -&gt; AeroGearPush and Swift to -&gt; AeroGearPushSwift</div><div>b) continue the same naming, but use the new ‘module_name’  podspec directive in the Swift project(added in cocoapods [6]) to specify the final module name the user will use on the import. That is the approach I have taken in my PR[6]</div></div></blockquote><div><br></div><div>+1 on b), using the module_name - nice addon to CocoaPods</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>If we go with (b) the entries will look like this:</div><div><br></div><div>——</div><div>Obj-c:  (no changes needed)</div><div><br></div><div>Podfile: pod &#39;AeroGear-Push’</div><div><br></div><div>Class:   #import &lt;AeroGearPush/AeroGearPush.h&gt;</div><div><br></div><div><br></div><div>Swift:</div><div><br></div><div>Podfile:  pod &#39;AeroGear-Push-Swift’</div><div><br></div><div>Class:    import “AeroGearPush”  (notice _no_ ‘Swift’ postfix is needed cause of the ‘module_name’ override)</div><div><br></div><div>——</div><div><br></div><div>I am fine with both albeit more towards (b) mostly not to break existing ‘pod installs’ the users may use and since support with the ‘module_name’ directive is provided from cocoapods.  Current PR[6] goes with this approach.</div><div><br></div><div>Let me know your comments and suggestions</div><div><br></div><div>Thanks</div><div>Christos</div><div><br></div><div>[1] <a href="https://github.com/CocoaPods/CocoaPods/issues/3016" target="_blank">https://github.com/CocoaPods/CocoaPods/issues/3016</a></div><div>[2] <a href="https://github.com/QueryKit/QueryKit" target="_blank">https://github.com/QueryKit/QueryKit</a></div><div>[3] <a href="https://github.com/ReactiveCocoa/ReactiveCocoa/tree/swift-development" target="_blank">https://github.com/ReactiveCocoa/ReactiveCocoa/tree/swift-development</a></div><div>[4] <a href="https://github.com/CocoaPods/CocoaPods/issues/3016#issuecomment-69092100" target="_blank">https://github.com/CocoaPods/CocoaPods/issues/3016#issuecomment-69092100</a></div><div>[5] <a href="https://github.com/CocoaPods/CocoaPods/issues/3016#issuecomment-69073109" target="_blank">https://github.com/CocoaPods/CocoaPods/issues/3016#issuecomment-69073109</a></div><div>[6] <a href="https://github.com/aerogear/aerogear-ios-push/pull/41" target="_blank">https://github.com/aerogear/aerogear-ios-push/pull/41</a></div><div>[7] <a href="http://blog.cocoapods.org/Pod-Authors-Guide-to-CocoaPods-Frameworks/" target="_blank">http://blog.cocoapods.org/Pod-Authors-Guide-to-CocoaPods-Frameworks/</a></div></div><br>_______________________________________________<br>
aerogear-dev mailing list<br>
<a href="mailto:aerogear-dev@lists.jboss.org" target="_blank">aerogear-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Matthias Wessendorf <br><br>blog: <a href="http://matthiaswessendorf.wordpress.com/" target="_blank">http://matthiaswessendorf.wordpress.com/</a><br>sessions: <a href="http://www.slideshare.net/mwessendorf" target="_blank">http://www.slideshare.net/mwessendorf</a><br>twitter: <a href="http://twitter.com/mwessendorf" target="_blank">http://twitter.com/mwessendorf</a></div>
</div></div>