Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Giving back with GitHub - Putting the Open Sour...

Giving back with GitHub - Putting the Open Source back in iOS

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

Madhava Jay

May 18, 2016
Tweet

More Decks by Madhava Jay

Other Decks in Technology

Transcript

  1. 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:
  2. The What • Why GitHub • What makes a good

    iOS GitHub repo • Multi Platform Support • Testing with Travis CI • Package Manager Support • Finishing Touches
  3. 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
  4. 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
  5. 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!
  6. If there’s a git tree in the GitHub forest, but

    no one clones it; is it even on GitHub? Ancient Chinese Proverb:
  7. 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
  8. 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
  9. 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
  10. 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"
  11. 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
  12. Travis CI File .travis.yml language: objective-c install: - ./Resources/install_swiftlint.sh env:

    global: - IOS_FRAMEWORK_SCHEME="Palau iOS" - WATCHOS_FRAMEWORK_SCHEME="Palau watchOS" script: - swiftlint - xcodebuild -project "$PROJECT" -scheme "$SCHEME" -sdk "$SDK" - destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO test | xcpretty -c; * Modified for slide
  13. 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
  14. CocoaPods .podspec • Pod::Spec.new do |s| • s.name = "Palau"

    • s.version = "1.0.3" • s.summary = "Palau: NSUserDefaults with Wings!" • s.homepage = "https://github.com/symentis/Palau" • s.screenshots = "palau-logo.png" • s.license = "Apache License, Version 2.0" • s.authors = { "[email protected]" } • s.ios.deployment_target = "8.0" • s.tvos.deployment_target = "9.0" • s.watchos.deployment_target = "2.0" • s.source_files = "Sources/*.swift" * Modified for slide, not v1 compatible
  15. 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
  16. 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/