Defines 1.0.2

Defines 1.0.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Nov 2018
SPMSupports SPM

Maintained by Bell App Lab.




Defines 1.0.2

Defines Version License

Platforms Swift support CocoaPods Compatible Carthage compatible Swift Package Manager compatible Twitter

Defines

A collection of runtime checks written in Swift.

In other words, simply do this:

if Defines.Device.isSimulator {
    //Don't ask permission to send push notifications
}

We all know the Apple Way of Doing Things ™, right? Instead of checking for a device, you check for a capability. For instance, instead of checking if a device is an iPod touch and therefore doesn't have a GPS, you check if CoreLocation is available. Or instead of checking for a device's screen size all the time, we should rely on Auto Layout's size classes and all that.

I get it.

But sometimes you just have to have that flag somewhere. Compact and Regular do not capture how preposterous the iPad Pro 12.9" screen's real estate is. So maybe you want to present a little bit more content there. Or maybe you just don't want to ask permissions for push notifications on the Simulator. We've all been there.

So just import Defines and get on with your life.

Note

Please note that Defines does not provide compile-time safety checks. It is merely a collection of static booleans for runtime checks.

In other words, doing this:

let iOS9 = Defines.Version(versionString: "9.0")
if Defines.OS.isiOS && Defines.OS.version = iOS9 {
    //execute code only available on iOS9
}

... will not silence any compiler warnings.

For that, take a look at Checking API Availability and Conditional Compilation Block.

Usage

Just so you get the gist of it.

  • Defines: main point of interaction with this module.
    • Device
      • currentModel : the device model running your code.
      • isSimulator
      • Model: enumeration of model identifiers for all the relevant Apple products since 2008.
      • isAppleTV
      • isAppleWatch
      • isiPad
      • isiPhone
      • isiPod
      • isMac
      • much more
    • Screen: information about the current screen available to your app.
      • bounds: the screen's current bound rect.
      • currentWidth
      • currentHeight
      • maxLength: the greater between width and height.
      • minLength: the lesser between width and height.
      • much more
    • OS: information about the OS running your app.
      • version: describes the version of the OS running your app and makes it easy to compare them.
    • App: your app, mainly reading from Info.plist.
      • name(forClass:): find your app's name.
      • version(forClass:): find your app's version.
    • Version: defines a software version in the format major.minor.patch (build).
  • Bundle:
    • id(forClass:): find your app's bundle id.

Specs

  • iOS 9+
  • watchOS 3+
  • tvOS 9+
  • macOS 10.11+
  • Swift 3.3+

Installation

Cocoapods

pod 'Defines', '~> 1.0'

Then import Defines where needed.

Carthage

github "BellAppLab/Defines" ~> 1.0

Then import Defines where needed.

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/BellAppLab/Defines", from: "1.0")
]

Then import Defines where needed.

Git Submodules

cd toYourProjectsFolder
git submodule add -b submodule --name Defines https://github.com/BellAppLab/Defines.git

Then drag the Definess folder into your Xcode project.

Author

Bell App Lab, [email protected]

Credits

Logo image by Sumana Chamrunworakiat from The Noun Project

License

Defines is available under the MIT license. See the LICENSE file for more info.