All Projects → detroit-labs → Orchard

detroit-labs / Orchard

Licence: MIT license
Device identification in Swift and Objective-C for iOS, watchOS, and tvOS.

Programming Languages

objective c
16641 projects - #2 most used programming language
python
139335 projects - #7 most used programming language
swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Orchard

Wwdc
You don't have the time to watch all the WWDC session videos yourself? No problem me and many contributors extracted the gist for you 🥳
Stars: ✭ 2,561 (+16973.33%)
Mutual labels:  tvos, watchos
Outlaw
JSON mapper for macOS, iOS, tvOS, and watchOS
Stars: ✭ 24 (+60%)
Mutual labels:  tvos, watchos
Anydate
Swifty Date & Time API inspired from Java 8 DateTime API.
Stars: ✭ 178 (+1086.67%)
Mutual labels:  tvos, watchos
Fire
🔥A delightful HTTP/HTTPS networking framework for iOS/macOS/watchOS/tvOS platforms written in Swift.
Stars: ✭ 243 (+1520%)
Mutual labels:  tvos, watchos
Htmlkit
An Objective-C framework for your everyday HTML needs.
Stars: ✭ 206 (+1273.33%)
Mutual labels:  tvos, watchos
Apple Runtime Headers
Objective-C runtime headers for Apple's iOS, macOS, tvOS and watchOS frameworks
Stars: ✭ 174 (+1060%)
Mutual labels:  tvos, watchos
Human Interface Guidelines Extras
Community additions to Apple's Human Interface Guidelines
Stars: ✭ 225 (+1400%)
Mutual labels:  tvos, watchos
Mirrordiffkit
Graduation from messy XCTAssertEqual messages.
Stars: ✭ 168 (+1020%)
Mutual labels:  tvos, watchos
Ios Crash Dump Analysis Book
iOS Crash Dump Analysis Book
Stars: ✭ 158 (+953.33%)
Mutual labels:  tvos, watchos
Objc Sdk
LeanCloud Objective-C SDK
Stars: ✭ 186 (+1140%)
Mutual labels:  tvos, watchos
Swiftui Sliders
🚀 SwiftUI Sliders with custom styles
Stars: ✭ 241 (+1506.67%)
Mutual labels:  tvos, watchos
Iso8601
ISO8601 date parser and writer
Stars: ✭ 213 (+1320%)
Mutual labels:  tvos, watchos
Cocoalumberjack
A fast & simple, yet powerful & flexible logging framework for Mac and iOS
Stars: ✭ 12,584 (+83793.33%)
Mutual labels:  tvos, watchos
Futures
Lightweight promises for iOS, macOS, tvOS, watchOS, and Linux
Stars: ✭ 59 (+293.33%)
Mutual labels:  tvos, watchos
Xamarin Macios
Bridges the worlds of .NET with the native APIs of macOS, iOS, tvOS, and watchOS.
Stars: ✭ 2,109 (+13960%)
Mutual labels:  tvos, watchos
L10n Swift
Localization of the application with ability to change language "on the fly" and support for plural form in any language.
Stars: ✭ 177 (+1080%)
Mutual labels:  tvos, watchos
Version
Represent and compare versions via semantic versioning (SemVer) in Swift
Stars: ✭ 160 (+966.67%)
Mutual labels:  tvos, watchos
Mapboxstatic.swift
Static map snapshots with overlays in Swift or Objective-C on iOS, macOS, tvOS, and watchOS
Stars: ✭ 162 (+980%)
Mutual labels:  tvos, watchos
Wwdc Notes
WWDCNotes.com content ✨
Stars: ✭ 183 (+1120%)
Mutual labels:  tvos, watchos
Cache
Swift caching library
Stars: ✭ 210 (+1300%)
Mutual labels:  tvos, watchos

Orchard

Version License Platform

Device identification for iOS, watchOS, and tvOS.

Orchard is a library for iOS, watchOS, and tvOS to identify the device running your code. Built in both Swift and Objective-C variants, the code uses the device model identifier of the system to identify the device.

Use

“But I thought we weren’t supposed to do it like this!”

For most cases, you shouldn’t use the model of the device to control features of your app. Instead of hardcoding which devices support Touch ID or Face ID, use LAContext. Instead of computing layout based on device model, use Auto Layout and size classes.

There are certain instances where it is important to know which device your code is running on. Whether you’re trying to sell accessories for the user’s current device, draw onscreen elements in actual size, or locate device hardware relative to the screen, sometimes you need to know the actual device, and that’s where Orchard comes in.

Objective-C

To use Orchard in Objective-C, use the Orchard category on UIDevice (or WKInterfaceDevice on watchOS) to get an enum value representing the device—either an OrchardiOSDevice, OrchardwatchOSDevice, or OrchardtvOSDevice, depending on the OS. You can then use this value in a switch statement or pass it to other methods, such as OrchardMarketingNameForiOSDevice(), which returns an NSString representing the marketing name for the device (e.g. “iPhone XS Max”). You can see this in the example below:

OrchardiOSDevice device = [UIDevice.currentDevice orchardiOSDevice];

switch (device) {
  case OrchardiOSDeviceiPhoneXSMax:
    NSLog(@"You have an iPhone XS Max!)";
}

Swift

To use Orchard in Swift, use the DeviceIdentity enum. You can obtain the instance representing the current device using the deviceIdentity computed property of UIDevice or WKInterfaceDevice. Instances of the DeviceIdentity enum have a marketingName property that returns the marketing name for the device (e.g. “iPad Pro (12.9-inch) (3rd Generation)”). You can see this in the example below:

let deviceIdentity = UIDevice.current.deviceIdentity

print("I’m an \(deviceIdentity.marketingName ?? "unknown device").")

switch deviceIdentity {
case .iPhone(.iPhone11ProMax), .iPhone(.iPhoneXSMax), .iPhone(.iPhone8Plus),
     .iPhone(.iPhone7Plus), .iPhone(.iPhone6sPlus), .iPhone(.iPhone6Plus),
     .iPad(.iPadPro12_9Inch), .iPad(.iPadPro12_9Inch2),
     .iPad(.iPadPro12_9Inch3), .iPad(.iPadPro12_9Inch4):
    print("You got the big one!")
default: break
}

Mixed-Source Projects

Orchard’s Objective-C code is completely usable from Swift; device names are annotated with NS_SWIFT_NAME and therefore can be used in the above example just as their Swift-native counterparts.

Installation

CocoaPods

Orchard can be installed using CocoaPods. There are two subspecs, Swift and ObjC, so use either of these lines in your Podfile:

pod "Orchard/ObjC"

pod "Orchard/Swift"

Swift Package Manager

The Swift portion of Orchard can be installed using the Swift package manager.

Development

Orchard uses [Swift gyb] to generate both Objective-C and Swift source files. The actual device data is in the Data folder, in TSV format. To add new devices, simply update the TSV file(s) with new device info and rebuild both targets; the source code will be regenerated. Do not modify any file for which there is a corresponding .gyb file, as the builds will overwrite your changes.

To update the generated source files, run the following command:

make generate
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].