Profile
Back to NewsBack
GitHub Trending 10 min
Reader Mode
Ekhoo/Device: Light weight tool for detecting the current device and screen size written in swift.

Ekhoo/Device: Light weight tool for detecting the current device and screen size written in swift.

12 hours ago

!Device

Version</a> License</a> Platform</a> Carthage Compatible</a> Swift Package Manager</a> Twitter</a>

Device detect the current  device model and screen size.

Installation

CocoaPods

Device is available through
CocoaPods. To install it, simply add the following line to your Podfile:
pod "Device", '~> 3.9.0'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Device into your Xcode project using Carthage, specify it in your Cartfile:

github "Ekhoo/Device" ~> 3.9.0

Run carthage update to build the framework and drag the built Device.framework into your Xcode project.

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding Device as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/Ekhoo/Device.git", from: "3.9.0")
]

Usage

iOS

Device version

func myFunc() {
        / Display the device version /
        switch Device.version() {
            / iPhone /
            case .iPhone4:       print("It's an iPhone 4")
            case .iPhone4S:      print("It's an iPhone 4S")
            case .iPhone5:       print("It's an iPhone 5")
            case .iPhone5C:      print("It's an iPhone 5C")
            case .iPhone5S:      print("It's an iPhone 5S")
            case .iPhone6:       print("It's an iPhone 6")
            case .iPhone6S:      print("It's an iPhone 6S")
            case .iPhone6Plus:   print("It's an iPhone 6 Plus")
            case .iPhone6SPlus:  print("It's an iPhone 6 S Plus")
            case .iPhoneSE:      print("It's an iPhone SE")
            case .iPhone7:       print("It's an iPhone 7")
            case .iPhone7Plus:   print("It's an iPhone 7 Plus")
            case .iPhone8:       print("It's an iPhone 8")
            case .iPhone8Plus:   print("It's an iPhone 8 Plus")
            case .iPhoneX:       print("It's an iPhone X")
            case .iPhoneXS:      print("It's an iPhone Xs")
            case .iPhoneXS_Max:  print("It's an iPhone Xs Max")
            case .iPhoneXR:      print("It's an iPhone Xr")
            case .iPhone11:      print("It's an iPhone 11")
            case .iPhone11Pro:   print("It's an iPhone 11 Pro")
            case .iPhone11Pro_Max: print("It's an iPhone 11 Pro Max")
            case .iPhoneSE2:     print("It's an iPhone SE 2nd Gen")
            case .iPhone12Mini:  print("It's an iPhone 12 Mini")
            case .iPhone12:      print("It's an iPhone 12")
            case .iPhone12Pro:   print("It's an iPhone 12 Pro")
            case .iPhone12Pro_Max: print("It's an iPhone 12 Pro Max")
            case .iPhone13Mini:  print("It's an iPhone 13 Mini")
            case .iPhone13:      print("It's an iPhone 13")
            case .iPhone13Pro:   print("It's an iPhone 13 Pro")
            case .iPhone13Pro_Max: print("It's an iPhone 13 Pro Max")
            case .iPhoneSE3:     print("It's an iPhone SE 3rd Gen")
            case .iPhone14:      print("It's an iPhone 14")
            case .iPhone14Plus:  print("It's an iPhone 14 Plus")
            case .iPhone14Pro:   print("It's an iPhone 14 Pro")
            case .iPhone14Pro_Max: print("It's an iPhone 14 Pro Max")
            case .iPhone15:      print("It's an iPhone 15")
            case .iPhone15Plus:  print("It's an iPhone 15 Plus")
            case .iPhone15Pro:   print("It's an iPhone 15 Pro")
            case .iPhone15Pro_Max: print("It's an iPhone 15 Pro Max")
            case .iPhone16:      print("It's an iPhone 16")
            case .iPhone16Plus:  print("It's an iPhone 16 Plus")
            case .iPhone16Pro:   print("It's an iPhone 16 Pro")
            case .iPhone16Pro_Max: print("It's an iPhone 16 Pro Max")
            case .iPhone16e:     print("It's an iPhone 16e")
            case .iPhone17, .iPhone17e, .iPhone17Pro, .iPhone17Pro_Max: print("It's an iPhone 17 series")
            case .iPhoneAir:     print("It's an iPhone Air")
            case .iPhone18Pro, .iPhone18Pro_Max: print("It's an iPhone 18 Pro series")
            case .iPhoneDuo:     print("It's an iPhone Duo")

/ iPad / case .iPad1: print("It's an iPad 1") case .iPad2: print("It's an iPad 2") case .iPad3: print("It's an iPad 3") case .iPad4: print("It's an iPad 4") case .iPad5: print("It's an iPad 5") case .iPad6: print("It's an iPad 6") case .iPad7, .iPad8, .iPad9, .iPad10, .iPadA16: print("It's an iPad") case .iPadAir: print("It's an iPad Air") case .iPadAir2: print("It's an iPad Air 2") case .iPadAir3, .iPadAir4, .iPadAir5: print("It's an iPad Air") case .iPadAirM2_11Inch, .iPadAirM2_13Inch: print("It's an iPad Air M2") case .iPadAirM3_11Inch, .iPadAirM3_13Inch: print("It's an iPad Air M3") case .iPadAirM4_11Inch, .iPadAirM4_13Inch: print("It's an iPad Air M4") case .iPadMini: print("It's an iPad Mini") case .iPadMini2: print("It's an iPad Mini 2") case .iPadMini3: print("It's an iPad Mini 3") case .iPadMini4: print("It's an iPad Mini 4") case .iPadMini5, .iPadMini6, .iPadMini7: print("It's an iPad Mini") case .iPadPro9_7Inch: print("It's an iPad Pro 9.7 Inch") case .iPadPro10_5Inch: print("It's an iPad Pro 10.5 Inch") case .iPadPro11_0Inch, .iPadPro11_0Inch2, .iPadPro11_0Inch3, .iPadPro11_0Inch4: print("It's an iPad Pro 11 Inch") case .iPadPro12_9Inch, .iPadPro12_9Inch2, .iPadPro12_9Inch3, .iPadPro12_9Inch4, .iPadPro12_9Inch5, .iPadPro12_9Inch6: print("It's an iPad Pro 12.9 Inch") case .iPadProM4_11Inch, .iPadProM4_13Inch: print("It's an iPad Pro M4") case .iPadProM5_11Inch, .iPadProM5_13Inch: print("It's an iPad Pro M5")

/ iPod / case .iPodTouch1Gen: print("It's a iPod touch generation 1") case .iPodTouch2Gen: print("It's a iPod touch generation 2") case .iPodTouch3Gen: print("It's a iPod touch generation 3") case .iPodTouch4Gen: print("It's a iPod touch generation 4") case .iPodTouch5Gen: print("It's a iPod touch generation 5") case .iPodTouch6Gen: print("It's a iPod touch generation 6")

/ Simulator / case .Simulator: print("It's a Simulator")

/ Unknown / default: print("It's an unknown device") } }

Device screen size

func myFunc() {
        / Display the device screen size /
        switch Device.size() {
            case .screen3_5Inch:    print("It's a 3.5 inch screen")
            case .screen4Inch:      print("It's a 4 inch screen")
            case .screen4_7Inch:    print("It's a 4.7 inch screen")
            case .screen5_4Inch:    print("It's a 5.4 inch screen")
            case .screen5_5Inch:    print("It's a 5.5 inch screen")
            case .screen5_8Inch:    print("It's a 5.8 inch screen")
            case .screen6_1Inch,
                 .screen6_1Inch_2:  print("It's a 6.1 inch screen")
            case .screen6_3Inch:    print("It's a 6.3 inch screen")
            case .screen6_5Inch:    print("It's a 6.5 inch screen")
            case .screen6_7Inch,
                 .screen6_7Inch_2:  print("It's a 6.7 inch screen")
            case .screen6_9Inch:    print("It's a 6.9 inch screen")
            case .screen7_9Inch:    print("It's a 7.9 inch screen")
            case .screen8_3Inch:    print("It's an 8.3 inch screen")
            case .screen9_7Inch:    print("It's a 9.7 inch screen")
            case .screen10_2Inch:   print("It's a 10.2 inch screen")
            case .screen10_5Inch:   print("It's a 10.5 inch screen")
            case .screen10_9Inch:   print("It's a 10.9 inch screen")
            case .screen11Inch:     print("It's an 11 inch screen")
            case .screen12_9Inch:   print("It's a 12.9 inch screen")
            case .screen13Inch:     print("It's a 13 inch screen")
            default:                print("Unknown size")
        }
}

Device type

func myFunc() {
        / Display the device type /
        switch Device.type() {
            case .iPod:         print("It's an iPod")
            case .iPhone:       print("It's an iPhone")
            case .iPad:         print("It's an iPad")
            case .simulator:    print("It's a Simulated device")
            default:            print("Unknown device type")
        }
}

or

func myFunc() {
        / Display the device type /
        if (Device.isPad()){
            print("It's an iPad")
        }
        else if (Device.type() == .iPhone){
            print("It's an iPhone")
        }
        else if (Device.isPod()){
            print("It's an iPod")
        }
        else if (Device.isSimulator()){
            print("It's a Simulated device")
        }
}

Dynamic Island

func myFunc() {
        / Check for Dynamic Island /
        if Device.hasDynamicIsland {
            print("Device has a Dynamic Island")
        }
}

Simulator Hardware Detection

By default, running on a simulator returns .simulator. Pass detectSimulator: true to inspect the underlying simulated hardware model (e.g. iPhone 16):
func myFunc() {
        let simulatedVersion = Device.version(detectSimulator: true)
        print("Emulated model: \(simulatedVersion)")
        
        let simulatedType = Device.type(detectSimulator: true)
        print("Emulated type: \(simulatedType)")
}

Mac

Mac version

func myFunc() {
        / Display the mac version /
        switch Device.type() {
            case .iMac:         print("It's an iMac")
            case .macBook:      print("It's a MacBook")
            case .macBookAir:   print("It's a MacBook Air")
            case .macBookPro:   print("It's a MacBook Pro")
            default:            print("Unknown device type")
        }
    }

Mac screen size

func myFunc() {
        / Display the mac screen size /
        switch Device.size() {
            case .screen11Inch:     print("It's a 11 inch screen")
            case .screen12Inch:     print("It's a 12 inch screen")
            case .screen13Inch:     print("It's a 13 inch screen")
            case .screen15Inch:     print("It's a 15 inch screen")
            case .screen17Inch:     print("It's a 17 inch screen")
            case .screen21_5Inch:   print("It's a 21.5 inch screen")
            case .screen27Inch:     print("It's a 27 inch screen")
            default:                print("Unknown size")
        }
}

Helpers

func myFunc() {
        / Helpers /
        if Device.size() == Size.screen4Inch {
            print("It's a 4 inch screen")
        }

if Device.size() > Size.screen4_7Inch { print("Your device screen is larger than 4.7 inch") }

if Device.size() < Size.screen4_7Inch { print("Your device screen is smaller than 4.7 inch") }

if Device.size() == Size.screen27Inch { print("It's a 27 inch screen") } if Device.size() > Size.screen15Inch { print("Your mac screen is larger than 15 inch") } if Device.size() < Size.screen15Inch { print("Your mac screen is smaller than 15 inch") }

if Device.isRetina() { print("It's a retina display") } }

Video Tutorial by Alex Nagy (@rebeloper):

  • https://www.youtube.com/watch?v=cTZcOaGgD-E
YouTube</a>

Privacy

Device does not collect any data. We provide this notice to help you fill out
App Privacy Details. Since Device is not using any of privacy required reason API as listed by Apple here xcprivacy manifest is not needed for this SDK.

Author

Lucas Ortis:

Maintenance

Pran Kishore:

License

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

Chat with me