31
Giving back with GitHub Putting the Open Source back in iOS @madhavajay

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

Embed Size (px)

Citation preview

Page 1: Giving back with GitHub - Putting the Open Source back in iOS

Giving back with GitHub

Putting the Open Source back in iOS

@madhavajay

Page 2: Giving back with GitHub - Putting the Open Source back in iOS

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: 😎

Page 3: Giving back with GitHub - Putting the Open Source back in iOS

The What

• Why GitHub

• What makes a good iOS GitHub repo

• Multi Platform Support

• Testing with Travis CI

• Package Manager Support

• Finishing Touches

Page 4: Giving back with GitHub - Putting the Open Source back in iOS

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

Page 5: Giving back with GitHub - Putting the Open Source back in iOS

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

Page 6: Giving back with GitHub - Putting the Open Source back in iOS

You want your profile to suck less!

Page 7: Giving back with GitHub - Putting the Open Source back in iOS

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!

Page 8: Giving back with GitHub - Putting the Open Source back in iOS

If there’s a git tree in the GitHub forest, but no one clones it; is it

even on GitHub?

Ancient Chinese Proverb:

Page 9: Giving back with GitHub - Putting the Open Source back in iOS

How NOT to do your README.md

Page 10: Giving back with GitHub - Putting the Open Source back in iOS

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

Page 11: Giving back with GitHub - Putting the Open Source back in iOS

These are not the Repos

you are looking for

Page 12: Giving back with GitHub - Putting the Open Source back in iOS

Imitation is the sincerest form of flattery

Page 13: Giving back with GitHub - Putting the Open Source back in iOS

Anatomy of an iOS Framework

Page 14: Giving back with GitHub - Putting the Open Source back in iOS

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

Page 15: Giving back with GitHub - Putting the Open Source back in iOS

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

Page 16: Giving back with GitHub - Putting the Open Source back in iOS

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"

Page 17: Giving back with GitHub - Putting the Open Source back in iOS

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

Page 18: Giving back with GitHub - Putting the Open Source back in iOS

Travis CI File .travis.ymllanguage: 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

Page 19: Giving back with GitHub - Putting the Open Source back in iOS

Xcode Project Target Setup

* Modified for slide

Page 20: Giving back with GitHub - Putting the Open Source back in iOS

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

Page 21: Giving back with GitHub - Putting the Open Source back in iOS

build passing: Поехали!

Page 22: Giving back with GitHub - Putting the Open Source back in iOS

Carthage Share Schemes

Page 23: Giving back with GitHub - Putting the Open Source back in iOS

Carthage Product Name

Page 24: Giving back with GitHub - Putting the Open Source back in iOS

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

Page 25: Giving back with GitHub - Putting the Open Source back in iOS

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

Page 26: Giving back with GitHub - Putting the Open Source back in iOS

CocoaPods Quality Index

* Modified for slide, not v1 compatible

< Sure… 😂

Page 27: Giving back with GitHub - Putting the Open Source back in iOS

SPM Swift Package Manager

Page 28: Giving back with GitHub - Putting the Open Source back in iOS

SPM Package.swift

import PackageDescription

let package = Package( name: "Palau" )

* This will change VERY soon!

Page 29: Giving back with GitHub - Putting the Open Source back in iOS

Cool Badges shields.io

* Modified for slide

https://travis-ci.org/symentis/Palau.svg?branch=master

https://img.shields.io/cocoapods/v/Palau.svg

https://img.shields.io/badge/Carthage-compatible-4BC51D.svg

https://img.shields.io/cocoapods/p/Palau.svg

https://img.shields.io/badge/pure-swift-ff3f26.svg

https://img.shields.io/badge/[email protected]

https://img.shields.io/badge/[email protected]

Page 30: Giving back with GitHub - Putting the Open Source back in iOS

Star if you Liked this

* This will change VERY soon!

Page 31: Giving back with GitHub - Putting the Open Source back in iOS

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/