My experience helping take an in house Swift library and making it into an Open Source framework available on GitHub and Package Management repositories like Cocoapods. Any questions or feedback appreciated @madhavajay
2. The Why
• Elmar: Hey checkout this thing I made called
PalauDefaults
• Me: WTF is this? 🤔 🙄 nope 😳
• Elmar: *Tries to explain*
• I hear: Blah blah blah Generics, blah blah Type Safety,
blah blah, monad-flatMap?
• Elmar: Lets Open Source it! 🤔
• Me: 😎
3. The What
• Why GitHub
• What makes a good iOS GitHub repo
• Multi Platform Support
• Testing with Travis CI
• Package Manager Support
• Finishing Touches
4. GitHub is the center of the
open source world!
• Frameworks Libraries and Examples
• Wikis, Issues, Pull Requests, Gists
• APIs, High Availability, The best VCS - Git
• Massive Community
• Even Apple! - github.com/apple/swift
5. Reasons to $ git commit
to the GitHub Community
• You thought of a cool feature to add to your fav repo
• You found a 🐛 in someone’s code and want to rub it in fix
it for them
• You wrote that cool script to automate something and
decided to make someone else’s life suck less!
• Balance your $ git karma ☯ - every time you
$ git pull, without $ git push 🐶🔫 😱
• $ git commit public code makes you a better programmer
7. Developing on iOS with
GitHub rocks!
• branch, code, test!, commit, push, pull request, merge 🍻
• Dependency Management: Cocoapods, Carthage and SPM
• Free CI Testing with Travis CI
• Wiki and GitHub Pages
• MarkDown for README
• Cool Badges like shields.io
• Integrations: JIRA, Travis, Slack, Gitter and More!
8. If there’s a git tree in
the GitHub forest, but
no one clones it; is it
even on GitHub?
Ancient Chinese Proverb:
10. How NOT to do your
README.md
• No Usage or Install Instructions
• No Tests 😱
• No Versioning or Dependency Info
• No Code Syntax Highlighting
• No License and Credits
• = NO $ git clone
14. Anatomy of an
iOS Framework
• Sources (with s) contains files that will be compiled
• Tests, you know… has the tests you better write!
• PM: Package.swift, Project.podspec
• Config: .swiftlint.yml, .travis.yml, .gitignore
• Resources / Fixtures, keep isolated
• Remove all other crud and aim for 2 .plist files,
watchOS currently requires editing .xcodeproj
15. Swift
Supporting Multiple Targets
#if os(OSX)
// test if we can get a default NSColor from a property
func testNSColorDefaultValue() {
let redColor = PalauDefaults.ensuredNSColorValue.value
let redColor2 = PalauDefaults.whenNilledNSColorValue.value
assert(CGColorEqualToColor(redColor!.CGColor,NSColor.redColor().CGColor))
assert(redColor2 == NSColor.redColor())
}
#else
// test if we can get a default UIColor from a property
func testUIColorDefaultValue() {
let redColor = PalauDefaults.ensuredUIColorValue.value
let redColor2 = PalauDefaults.whenNilledUIColorValue.value
// UIColor sometimes returns different versions UIDeviceRGBColorSpace
assert(CGColorEqualToColor(redColor!.CGColor,UIColor.redColor().CGColor))
assert(redColor2 == UIColor.redColor())
}
#endif
16. Swift
Supporting Multiple Targets
* It's not really that hard
• Create a Target for each Platform
• iOS, macOS, tvOS, watchOS (no tests yet)
• Write tests with Platforms in Mind
#if arch(x86_64) || arch(arm64)
func test64bitOnly () {
let reallyBigInt = 9_223_372_036_854_775_807
checkValue(&PalauDefaults.intValue, value: reallyBigInt)
• Add Platform tests to your .travis.yml file
DESTINATION="OS=9.2,name=Apple TV 1080p"
17. Cool things I stole learn't
from other GitHub repos
• .travis.yml for Xcode Testing
• shields.io
• Center your Logo with <p align=“center”><img></p>
• - [x] Cool Checkbox Bullet Points
• ```swift - highlights your swift code
20. Travis CI File
.travis.yml
- Run xcodebuild locally first
- Make sure your shell files are chmod +x
- Name your targets correctly
- Use swiftlint via install.sh script
- Don’t output characters like ⡍⠜⠇⠑
or you might break xcpretty
25. CocoaPods
.podspec
- Test locally using:
pod 'Name', :path => '~/code/Pods/'
- Don’t forget to bump your versions (1 .plist for all)
- $ pod lib lint
- $ git tag ‘1.0.3’; git push —tags
- Wait for Travis CI tests 😎
- $ pod trunk push NAME.podspec
31. Thanks
Munich iOS Meetup
import Thanks
assert(
user.getsPizza == user.starredRepo
)
print("See you on GitHub 😎”)
* This will change VERY soon!
@madhavajay
http://symentis.com/