Skip to content

[Foundation] Set correct availability on NSValue.value(of:) #25454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions stdlib/public/Darwin/Foundation/NSValue.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ${ ObjectiveCBridgeableImplementationForNSValue("CGSize") }
${ ObjectiveCBridgeableImplementationForNSValue("CGAffineTransform") }

extension NSValue {
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public func value<StoredType>(of type: StoredType.Type) -> StoredType? {
if StoredType.self is AnyObject.Type {
let encoding = String(cString: objCType)
Expand All @@ -42,11 +42,7 @@ extension NSValue {
}
let allocated = UnsafeMutablePointer<StoredType>.allocate(capacity: 1)
defer { allocated.deallocate() }
if #available(OSX 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *) {
getValue(allocated, size: storedSize)
} else {
getValue(allocated)
}
getValue(allocated, size: storedSize)
return allocated.pointee
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/NSValueBridging.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ nsValueBridging.test("NSValue can only be cast back to its original type") {
}

nsValueBridging.test("NSValue fetching method should be able to convert constructed values safely") {
guard #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) else { return }
guard #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) else { return }

let range = NSRange(location: 17, length: 38)
let value = NSValue(range: range)
Expand Down