Skip to content

Commit

Permalink
Merge pull request #24802 from apple/revert-24498-nsvalue-availability
Browse files Browse the repository at this point in the history
Revert "[Foundation] Fix availability of NSValue.value(of:)"
  • Loading branch information
beccadax authored May 15, 2019
2 parents c141c48 + dce879f commit 8ba2997
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 6 additions & 3 deletions stdlib/public/Darwin/Foundation/NSValue.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ ${ ObjectiveCBridgeableImplementationForNSValue("CGSize") }
${ ObjectiveCBridgeableImplementationForNSValue("CGAffineTransform") }

extension NSValue {
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
public func value<StoredType>(of type: StoredType.Type) -> StoredType? {
if StoredType.self is AnyObject.Type {
let encoding = String(cString: objCType)
Expand All @@ -42,9 +41,13 @@ extension NSValue {
}
let allocated = UnsafeMutablePointer<StoredType>.allocate(capacity: 1)
defer { allocated.deallocate() }
getValue(allocated, size: storedSize)
if #available(OSX 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *) {
getValue(allocated, size: storedSize)
} else {
getValue(allocated)
}
return allocated.pointee
}
return nil
}
}
}
2 changes: 0 additions & 2 deletions test/stdlib/NSValueBridging.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ 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 }

let range = NSRange(location: 17, length: 38)
let value = NSValue(range: range)
expectEqual(value.value(of: NSRange.self)?.location, range.location)
Expand Down

0 comments on commit 8ba2997

Please sign in to comment.