Skip to content

Commit 7b3e9f4

Browse files
Update to Swift 5 and clear up build warnings
1 parent e9c7db0 commit 7b3e9f4

4 files changed

Lines changed: 20 additions & 27 deletions

File tree

Source/UIDevice+deviceModel.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import UIKit
1010

1111
public extension UIDevice {
12-
13-
public var deviceModel: UIDeviceModel {
12+
var deviceModel: UIDeviceModel {
1413
return UIDeviceModel.current
1514
}
16-
1715
}

Source/UIDeviceModel.swift

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public enum UIDeviceModel {
2727
case iPadMini2
2828
case iPadMini3
2929
case iPadMini4
30-
30+
3131
/// Also known as iPhone 2G
3232
case iPhone
3333
case iPhone3G
@@ -50,44 +50,40 @@ public enum UIDeviceModel {
5050
case iPhoneXS
5151
case iPhoneXSMax
5252
case iPhoneXR
53-
53+
5454
case iPodTouch
5555
case iPodTouch2
5656
case iPodTouch3
5757
case iPodTouch4
5858
case iPodTouch5
5959
case iPodTouch6
60-
60+
6161
indirect case simulator(UIDeviceModel)
6262
/// Device is not yet known or implemented
6363
case unknown(String)
64-
6564
}
6665

6766
public extension UIDeviceModel {
68-
69-
public var unwrapIfSimulator: UIDeviceModel {
67+
var unwrapIfSimulator: UIDeviceModel {
7068
return UIDeviceModel.unwrapIfSimulator(self)
7169
}
72-
73-
static private func unwrapIfSimulator(_ device: UIDeviceModel) -> UIDeviceModel {
70+
71+
private static func unwrapIfSimulator(_ device: UIDeviceModel) -> UIDeviceModel {
7472
if case let .simulator(model) = device {
7573
return model
7674
}
7775
return device
7876
}
79-
8077
}
8178

8279
// MARK: - Mapping from Identifier
8380

8481
extension UIDeviceModel {
85-
8682
static var current: UIDeviceModel {
8783
return mapToDevice(identifier: identifier)
8884
}
89-
90-
static private var identifier: String = {
85+
86+
private static var identifier: String = {
9187
var systemInfo = utsname()
9288
uname(&systemInfo)
9389
let mirror = Mirror(reflecting: systemInfo.machine)
@@ -97,8 +93,8 @@ extension UIDeviceModel {
9793
}
9894
return identifier
9995
}()
100-
101-
static private func mapToDevice(identifier: String) -> UIDeviceModel {
96+
97+
private static func mapToDevice(identifier: String) -> UIDeviceModel {
10298
switch identifier {
10399
case "iPad1,1": return .iPad
104100
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4": return .iPad2
@@ -118,7 +114,7 @@ extension UIDeviceModel {
118114
case "iPad7,5", "iPad7,6": return .iPad6
119115
case "iPad8,1", "iPad8,2", "iPad8,3", "iPad8,4": return .iPadPro11Inch
120116
case "iPad8,5", "iPad8,6", "iPad8,7", "iPad8,8": return .iPadPro12Inch3
121-
117+
122118
case "iPhone1,1": return .iPhone
123119
case "iPhone1,2": return .iPhone3G
124120
case "iPhone2,1": return .iPhone3GS
@@ -140,18 +136,16 @@ extension UIDeviceModel {
140136
case "iPhone11,2": return .iPhoneXS
141137
case "iPhone11,4", "iPhone11,6": return .iPhoneXSMax
142138
case "iPhone11,8": return .iPhoneXR
143-
139+
144140
case "iPod1,1": return .iPodTouch
145141
case "iPod2,1": return .iPodTouch2
146142
case "iPod3,1": return .iPodTouch3
147143
case "iPod4,1": return .iPodTouch4
148144
case "iPod5,1": return .iPodTouch5
149145
case "iPod7,1": return .iPodTouch6
150-
146+
151147
case "i386", "x86_64": return .simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))
152148
default: return .unknown(identifier)
153149
}
154150
}
155-
156151
}
157-

UIDeviceModel.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "UIDeviceModel"
3-
s.version = "1.1.0"
3+
s.version = "2.0.0"
44
s.summary = "A µframework to detect the device model."
55
s.description = <<-DESC
66
A µframework to detect the device model provided through an extension of UIDevice. It also allows detection of the simulator and the device model it is simulating.
@@ -14,5 +14,5 @@ Pod::Spec.new do |s|
1414

1515
s.source = { :git => "https://github.com/theoriginalbit/UIDeviceModel.git", :tag => "#{s.version}" }
1616
s.source_files = "Source", "Source/**/*.{h,swift}"
17-
s.swift_version = "4.2"
17+
s.swift_version = "5.0"
1818
end

UIDeviceModel.xcodeproj/project.pbxproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
TargetAttributes = {
116116
237B01AC216CCD9C00816AC8 = {
117117
CreatedOnToolsVersion = 10.0;
118-
LastSwiftMigration = 1000;
118+
LastSwiftMigration = 1020;
119119
};
120120
};
121121
};
@@ -125,6 +125,7 @@
125125
hasScannedForEncodings = 0;
126126
knownRegions = (
127127
en,
128+
Base,
128129
);
129130
mainGroup = 237B01A3216CCD9C00816AC8;
130131
productRefGroup = 237B01AE216CCD9C00816AC8 /* Products */;
@@ -302,7 +303,7 @@
302303
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
303304
SKIP_INSTALL = YES;
304305
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
305-
SWIFT_VERSION = 4.2;
306+
SWIFT_VERSION = 5.0;
306307
TARGETED_DEVICE_FAMILY = "1,2";
307308
};
308309
name = Debug;
@@ -327,7 +328,7 @@
327328
PRODUCT_BUNDLE_IDENTIFIER = com.theoriginalbit.UIDeviceModel;
328329
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
329330
SKIP_INSTALL = YES;
330-
SWIFT_VERSION = 4.2;
331+
SWIFT_VERSION = 5.0;
331332
TARGETED_DEVICE_FAMILY = "1,2";
332333
};
333334
name = Release;

0 commit comments

Comments
 (0)