Skip to content

Commit b49adc2

Browse files
author
Max Moiseev
committed
Update UIKit
Changes simlar to those in AppKit. <rdar://problem/34131288>
1 parent 6cf8f9b commit b49adc2

File tree

3 files changed

+121
-4
lines changed

3 files changed

+121
-4
lines changed

stdlib/public/SDK/UIKit/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ add_swift_library(swiftUIKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVE
66
UIKit.swift
77
UIKit_FoundationExtensions.swift.gyb
88

9-
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
9+
SWIFT_COMPILE_FLAGS ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} -swift-version 4
1010
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
1111
TARGET_SDKS IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR
1212
SWIFT_MODULE_DEPENDS_IOS Darwin CoreFoundation CoreGraphics CoreImage Dispatch Foundation ObjectiveC QuartzCore os # auto-updated

stdlib/public/SDK/UIKit/UIKit.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,52 @@ public func == (lhs: UIOffset, rhs: UIOffset) -> Bool {
5757

5858
extension UIOffset : Equatable {}
5959

60+
//===----------------------------------------------------------------------===//
61+
// Numeric backed types
62+
//===----------------------------------------------------------------------===//
63+
64+
@available(swift 4)
65+
public protocol _UIKitNumericRawRepresentable : RawRepresentable, Comparable where RawValue: Comparable & Numeric {}
66+
67+
extension _UIKitNumericRawRepresentable {
68+
69+
public static func <(lhs: Self, rhs: Self) -> Bool {
70+
return lhs.rawValue < rhs.rawValue
71+
}
72+
73+
public static func +(lhs: Self, rhs: RawValue) -> Self {
74+
return Self(rawValue: lhs.rawValue + rhs)!
75+
}
76+
77+
public static func +(lhs: RawValue, rhs: Self) -> Self {
78+
return Self(rawValue: lhs + rhs.rawValue)!
79+
}
80+
81+
public static func -(lhs: Self, rhs: RawValue) -> Self {
82+
return Self(rawValue: lhs.rawValue - rhs)!
83+
}
84+
85+
public static func -(lhs: Self, rhs: Self) -> RawValue {
86+
return lhs.rawValue - rhs.rawValue
87+
}
88+
89+
public static func +=(lhs: inout Self, rhs: RawValue) {
90+
lhs = Self(rawValue: lhs.rawValue + rhs)!
91+
}
92+
93+
public static func -=(lhs: inout Self, rhs: RawValue) {
94+
lhs = Self(rawValue: lhs.rawValue - rhs)!
95+
}
96+
}
97+
98+
@available(swift 4)
99+
extension UIFont.Weight : _UIKitNumericRawRepresentable {}
100+
101+
#if !os(watchOS)
102+
@available(swift 4)
103+
extension UILayoutPriority : _UIKitNumericRawRepresentable {}
104+
#endif
105+
60106
// These are un-imported macros in UIKit.
61107

62108
//===----------------------------------------------------------------------===//
@@ -247,6 +293,7 @@ extension UIFontTextStyle {
247293

248294
#if !os(watchOS) // UIContentSizeCategory not available on watchOS
249295
extension UIContentSizeCategory {
296+
250297
@available(iOS 11.0, tvOS 11.0, *)
251298
public var isAccessibilityCategory: Bool {
252299
return __UIContentSizeCategoryIsAccessibilityCategory(self)

test/stdlib/UIKit.swift

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
// RUN: %target-run-simple-swift
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: %target-build-swift -swift-version 3 %s -o %t/a.out3 && %target-run %t/a.out3
3+
// RUN: %target-build-swift -swift-version 4 %s -o %t/a.out4 && %target-run %t/a.out4
24
// REQUIRES: executable_test
3-
// REQUIRES: OS=ios
5+
// UNSUPPORTED: OS=macosx
6+
// REQUIRES: objc_interop
47

58
import UIKit
69
import StdlibUnittest
710
import StdlibUnittestFoundationExtras
811

9-
let UIKitTests = TestSuite("UIKit")
12+
#if swift(>=4)
13+
let UIKitTests = TestSuite("UIKit_Swift4")
14+
#else
15+
let UIKitTests = TestSuite("UIKit_Swift3")
16+
#endif
1017

18+
#if !os(watchOS) && !os(tvOS)
1119
private func printDevice(_ o: UIDeviceOrientation) -> String {
1220
var s = "\(o.isPortrait) \(UIDeviceOrientationIsPortrait(o)), "
1321
s += "\(o.isLandscape) \(UIDeviceOrientationIsLandscape(o)), "
@@ -60,6 +68,7 @@ UIKitTests.test("UIInterfaceOrientation") {
6068
expectEqual("false false, true true",
6169
printInterface(.landscapeRight))
6270
}
71+
#endif
6372

6473
UIKitTests.test("UIEdgeInsets") {
6574
let insets = [
@@ -79,6 +88,66 @@ UIKitTests.test("UIOffset") {
7988
checkEquatable(offsets, oracle: { $0 == $1 })
8089
}
8190

91+
UIKitTests.test("UIFont.Weight") {
92+
guard #available(iOS 8.2, *) else { return }
93+
#if swift(>=4) // Swift 4
94+
let regularFontWeight: UIFont.Weight = .regular
95+
96+
expectTrue(regularFontWeight == .regular)
97+
expectTrue(regularFontWeight > .light)
98+
expectTrue(regularFontWeight < .heavy)
99+
expectTrue(regularFontWeight + 0.1 == 0.1 + regularFontWeight)
100+
#else // Swift 3
101+
let regularFontWeight: UIFontWeight = UIFontWeightRegular
102+
103+
expectTrue(regularFontWeight == UIFontWeightRegular)
104+
expectTrue(regularFontWeight > UIFontWeightLight)
105+
expectTrue(regularFontWeight < UIFontWeightHeavy)
106+
expectTrue(regularFontWeight + 0.1 == 0.1 + UIFontWeightRegular)
107+
#endif
108+
}
109+
110+
#if !os(watchOS)
111+
UIKitTests.test("UILayoutPriority") {
112+
#if swift(>=4) // Swift 4
113+
let lowLayoutPriority: UILayoutPriority = .defaultLow
114+
let highLayoutPriority: UILayoutPriority = .defaultHigh
115+
116+
expectTrue(lowLayoutPriority < highLayoutPriority)
117+
118+
expectTrue(lowLayoutPriority + 2.0 == UILayoutPriority(lowLayoutPriority.rawValue + 2.0))
119+
expectTrue(2.0 + lowLayoutPriority == UILayoutPriority(lowLayoutPriority.rawValue + 2.0))
120+
expectTrue(lowLayoutPriority - 2.0 == UILayoutPriority(lowLayoutPriority.rawValue - 2.0))
121+
expectTrue(highLayoutPriority - lowLayoutPriority == highLayoutPriority.rawValue - lowLayoutPriority.rawValue)
122+
123+
expectTrue(lowLayoutPriority + (highLayoutPriority - lowLayoutPriority) == highLayoutPriority)
124+
125+
var mutablePriority = lowLayoutPriority
126+
mutablePriority -= 1.0
127+
mutablePriority += 2.0
128+
expectTrue(mutablePriority == lowLayoutPriority + 1.0)
129+
130+
let priorotyRange = lowLayoutPriority...highLayoutPriority
131+
expectTrue(priorotyRange.contains(.defaultLow))
132+
expectFalse(priorotyRange.contains(.required))
133+
#else // Swift 3
134+
let lowLayoutPriority: UILayoutPriority = UILayoutPriorityDefaultLow
135+
let highLayoutPriority: UILayoutPriority = UILayoutPriorityDefaultHigh
136+
137+
expectTrue(lowLayoutPriority < highLayoutPriority)
138+
139+
expectTrue(2.0 + lowLayoutPriority == lowLayoutPriority + 2.0)
140+
expectTrue(lowLayoutPriority + (highLayoutPriority - lowLayoutPriority) == highLayoutPriority)
141+
142+
var mutablePriority = lowLayoutPriority
143+
mutablePriority -= 1.0
144+
mutablePriority += 2.0
145+
expectTrue(mutablePriority == lowLayoutPriority + 1.0)
146+
#endif
147+
}
148+
#endif
149+
150+
#if !os(watchOS)
82151
class TestChildView : UIView, CustomPlaygroundQuickLookable {
83152
convenience init() {
84153
self.init(frame: CGRect(x: 0, y: 0, width: 10, height: 10))
@@ -95,6 +164,7 @@ UIKitTests.test("CustomPlaygroundQuickLookable") {
95164
"TestChildView custom quicklookable should have been invoked")
96165
}
97166
}
167+
#endif
98168

99169
UIKitTests.test("NSValue bridging") {
100170
expectBridgeToNSValue(UIEdgeInsets(top: 17, left: 38, bottom: 6, right: 79),

0 commit comments

Comments
 (0)