Skip to content

Commit fb55fc3

Browse files
authored
[redux][Foundation] Fix availability of NSValue.value(of:) (#25179)
* [Foundation] Fix availability of NSValue.value(of:) (cherry picked from commit fbe5563) * [Foundation] NSValue.value(of:): Reinstate runtime OS version check
1 parent d543dd9 commit fb55fc3

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

stdlib/public/Darwin/Foundation/NSValue.swift.gyb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ${ ObjectiveCBridgeableImplementationForNSValue("CGSize") }
2424
${ ObjectiveCBridgeableImplementationForNSValue("CGAffineTransform") }
2525

2626
extension NSValue {
27+
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
2728
public func value<StoredType>(of type: StoredType.Type) -> StoredType? {
2829
if StoredType.self is AnyObject.Type {
2930
let encoding = String(cString: objCType)
@@ -42,12 +43,12 @@ extension NSValue {
4243
let allocated = UnsafeMutablePointer<StoredType>.allocate(capacity: 1)
4344
defer { allocated.deallocate() }
4445
if #available(OSX 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *) {
45-
getValue(allocated, size: storedSize)
46-
} else {
47-
getValue(allocated)
48-
}
46+
getValue(allocated, size: storedSize)
47+
} else {
48+
getValue(allocated)
49+
}
4950
return allocated.pointee
5051
}
5152
return nil
5253
}
53-
}
54+
}

test/stdlib/NSValueBridging.swift.gyb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ nsValueBridging.test("NSValue can only be cast back to its original type") {
9292
}
9393

9494
nsValueBridging.test("NSValue fetching method should be able to convert constructed values safely") {
95+
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
96+
9597
let range = NSRange(location: 17, length: 38)
9698
let value = NSValue(range: range)
9799
expectEqual(value.value(of: NSRange.self)?.location, range.location)

0 commit comments

Comments
 (0)