-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicholas Maccharoli
committed
Aug 7, 2017
0 parents
commit f827ace
Showing
26 changed files
with
1,606 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## Build generated | ||
build/ | ||
DerivedData/ | ||
|
||
## macOS filesystem specific | ||
.DS_Store | ||
|
||
## Various settings | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata/ | ||
|
||
## Other | ||
*.moved-aside | ||
*.xccheckout | ||
*.xcscmblueprint | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
# CocoaPods | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
# Pods/ | ||
|
||
# Carthage | ||
# | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/#source-control | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots | ||
fastlane/test_output | ||
|
||
# Code Injection | ||
# | ||
# After new code Injection tools there's a generated folder /iOSInjectionProject | ||
# https://github.com/johnno1962/injectionforxcode | ||
|
||
iOSInjectionProject/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
disabled_rules: | ||
- cyclomatic_complexity | ||
- compiler_protocol_init | ||
- force_cast | ||
- colon | ||
- comma | ||
- control_statement | ||
- identifier_name | ||
- large_tuple | ||
opt_in_rules: | ||
- empty_count | ||
included: | ||
- Sources/ | ||
line_length: 150 | ||
file_length: | ||
warning: 500 | ||
error: 1200 | ||
reporter: "xcode" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: objective-c | ||
osx_image: xcode8.3 | ||
xcode_project: UIDeviceComplete.xcodeproj | ||
xcode_scheme: UIDeviceComplete | ||
|
||
script: | ||
- xcodebuild test -scheme UIDeviceComplete -sdk iphonesimulator -destination 'OS=10.3.1,name=iPhone 7 Plus' | ||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
`UIDeviceComplete` adheres to [Semantic Versioning](http://semver.org/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Nicholas Maccharoli | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Package.swift | ||
// Copyright (c) 2017 Nicholas Maccharoli | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "UIDeviceComplete" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# UIDeviceComplete | ||
UIDevice extensions that fill in the missing pieces. | ||
|
||
[![Build Status](https://travis-ci.org/Nirma/UIDeviceComplete.svg?branch=master)](https://travis-ci.org/Nirma/UIDeviceComplete) | ||
![Swift 3.1](https://img.shields.io/badge/Swift-3.1.1-orange.svg) | ||
![CodeCov](https://img.shields.io/codecov/c/github/Nirma/UIDeviceComplete.svg) | ||
[![CocoaPods compatible](https://img.shields.io/cocoapods/v/UIDeviceComplete.svg)](#cocoapods) | ||
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) | ||
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager) | ||
[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org) | ||
|
||
# Intro | ||
`UIDeviceComplete` is an iOS library intended to be a collection of extensions to `UIDevice` | ||
that provide functionality that `UIDevice` currently lacks like determining which iOS device | ||
you have (i.e iPhone SE, iPad Pro, iPhone7 etc) | ||
|
||
# Features | ||
- [x] Detect specific device like iPhone 7, iPhone SE or iPad Pro | ||
- [x] Get screen size of device in inches | ||
- [x] Get iOS Device family (iPod, iPhone or iPad) | ||
|
||
### Dont see a feature you need? | ||
Feel free to open an Issue requesting the feature you want or send over a pull request! | ||
|
||
# Use | ||
All of the extensions are called off of the `dc` variable ***stands for ([UI]DeviceComplete)*** object that this | ||
library extends onto `UIDevice` that way native methods of `UIDevice` and methods of this library can | ||
easily be seen, also lowering the possibility of naming conflicts. | ||
|
||
|
||
### Detecting iOS Device models | ||
|
||
```Swift | ||
let device = UIdevice.current.dc.deviceModel | ||
|
||
switch device { | ||
case .iPhone6Plus, .iPhone7Plus: | ||
print("Lots of screen realestate eh?") | ||
case .iPhoneSE, .iPhone5, iPhone5S: | ||
print("Less iPhone is more iPhone...") | ||
case .iPadPro: | ||
print("Why?") | ||
default: | ||
print("Not sure what this is...") | ||
} | ||
``` | ||
### Detecting iOS Device Screen Size (Inches) | ||
|
||
Screen size can be be queried with the following computed property returning a simple `Double` | ||
that represents the screen size in inches: | ||
|
||
```swift | ||
let screenSize: Double = UIDevice.current.dc.screen.inches | ||
|
||
if screenSize <= 4.0 { | ||
print("Modest screen size; not so modest price tag") | ||
} else if screenSize >= 5.5 { | ||
print("Plus is always a plus") | ||
} else { | ||
print("Chances are this is an iPad or an iPhone (Texas Edition).") | ||
} | ||
``` | ||
|
||
### Detecting iOS Device Family | ||
|
||
If the type of device family is all you are after i.e iPhone or iPad and the specific model | ||
is not important then `DeviceFamily` might be what you need. | ||
|
||
```Swift | ||
let deviceFamily = UIdevice.current.dc.deviceFamily | ||
|
||
switch deviceFamily { | ||
case .iPhone: | ||
print("...phone home?") | ||
case .iPad: | ||
print("when it comes to screen size; more is more") | ||
case .iPod: | ||
print("Why not?") | ||
default: | ||
print("No family...") | ||
} | ||
``` | ||
|
||
## Installation | ||
|
||
#### Carthage | ||
|
||
If you use Carthage to manage your dependencies, simply add | ||
UIFontComplete to your `Cartfile`: | ||
|
||
``` | ||
github "Nirma/UIDeviceComplete" | ||
``` | ||
|
||
If you use Carthage to build your dependencies, make sure you have added `UIDeviceComplete.framework` to the "_Linked Frameworks and Libraries_" section of your target, and have included `UIDeviceComplete.framework` in your Carthage framework copying build phase. | ||
|
||
#### CocoaPods | ||
|
||
If you use CocoaPods to manage your dependencies, simply add | ||
this line to your `Podfile`: | ||
|
||
``` | ||
pod 'UIDeviceComplete' | ||
``` | ||
|
||
|
||
## Contributing to this project | ||
**Contributions are highly welcome** | ||
|
||
If there is something you wish to fix about the project, | ||
propose to add to the project or any other kind of enhancement please feel free to send over a pull request | ||
or open an issue for this project. | ||
|
||
## License | ||
|
||
UIDeviceComplete is released under the MIT license. [See LICENSE](https://github.com/Nirma/UIDeviceComplete/blob/master/LICENSE) for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// DeviceFamily.swift | ||
// | ||
// Copyright (c) 2017 Nicholas Maccharoli | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
public enum DeviceFamily: String { | ||
|
||
case iPhone | ||
case iPod | ||
case iPad | ||
case simulator | ||
case unknown | ||
|
||
public init(rawValue: String) { | ||
switch rawValue { | ||
case "iPhone": | ||
self = .iPhone | ||
case "iPod": | ||
self = .iPod | ||
case "iPad": | ||
self = .iPad | ||
case "x86_64", "i386": | ||
self = .simulator | ||
default: | ||
self = .unknown | ||
} | ||
} | ||
} |
Oops, something went wrong.