Swiftpack.co - Package - bojan/Thingy

Thingy

A modern device detection and querying library.

Build Status GitHub license Carthage compatible SPM CocoaPods compatible

Documentation

Features

  • [x] Swift 4 support
  • [x] Modern syntax
  • [x] Documentation
  • [x] Device detection
  • [x] Device family detection
  • [x] Device screens
  • [x] Simulator detection
  • [x] Simple querying

Requirements

Installation

Swift Packager Manager (SPM)

Create a Package.swift file, and add this snippet:

import PackageDescription

let package = Package(
    name: "HelloWorld",
    dependencies: [
        .Package(url: "https://github.com/bojan/Thingy.git", "2.0.2")
    ]
)

Carthage

Add this to your Cartfile:

github "bojan/Thingy"

CocoaPods

Add this to your Podfile

pod 'Thingy'

Manually

Add the repository as a submodule to your project.

git submodule add https://github.com/bojan/Thingy.git Vendor/Thingy

Open the newly created folder in Finder and drag Thingy.xcodeproj to your project.

In your project's settings, select your target and under General > Embedded Binaries, add the framework depending on the target OS (iOS, watchOS or tvOS).

Usage

Import the module where needed:

import Thingy

Device properties

Inspect the current device:


let myDevice = Device()

// Compare models or product families
if myDevice.family == .tv {
    print("This is an Apple TV device.")
}

if myDevice.model != .iPhone7Plus {
    print("This is NOT an iPhone 7 Plus.")
}

// Pretty printed device properties

print(myDevice.family.marketingName) // e.g. iPad
print(myDevice.model.marketingName) // e.g. iPhone 7 Plus
print(myDevice.productLine.marketingName) // e.g. Air

Model comparison

let myDevice = Device()

do {
    let result = try myDevice.isEqual(to: Thingy.iPadPro12Inch)
}
catch {
    print("The devices are incompatible.")
}

do {
    let result = try myDevice.isOlder(than: Thingy.iPadPro10Inch)
}
catch {
    print("The devices are incompatible.")
}

Device size

let myDevice = Device()

if myDevice.display == .screen10_5Inch {
    print("This is the 10.5in iPad Pro.")
}

Contributions

All contributions and suggestions are welcome and very much appreciated.

Should you have a feature request or a problem that you may experience, feel free to open an issue.

If you are willing to contribute by adding a feature or squashing a bug or two, please submit a pull request.

Author

Bojan Dimovski

License

Thingy is available under the MIT license. Check the LICENSE file for more info.

Github

link
Stars: 34
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

2.0.1 - Mar 2, 2018

Display sizes can now be compared using standard comparison operators <, >, ==, <=, >=.

2.0.0 - Nov 2, 2017

  • Swift 4.0 support
  • Xcode 9.0 support

1.0.3 - Nov 2, 2017

  • Add the fall 2017 devices:
    • iPhone 8
    • iPhone 8 Plus
    • iPhone X
    • Apple Watch Series 3
    • Apple TV 4K
  • Extend the display capabilities with information about the color space and True Tone support.

1.0.0-alpha.1 - Jul 25, 2017

  • First alpha.
  • Note: missing device querying and comparison.

1.0.2 - Jul 25, 2017

  • Fixed the issues with the target OSs.
  • Fixed a crash when running on real devices.