Skip to content

Commit 923468b

Browse files
Kyle ZhaoMax Moiseev
authored andcommitted
[overlay] Add INRideOption
<rdar://problem/32935297>
1 parent 0114f86 commit 923468b

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

stdlib/public/SDK/Intents/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_swift_library(swiftIntents ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_O
1010
INIntegerResolutionResult.swift
1111
INParameter.swift
1212
INRequestRideIntent.swift
13+
INRideOption.swift
1314
INSaveProfileInCarIntent.swift
1415
INSearchCallHistoryIntent.swift
1516
INSearchForPhotosIntentResponse.swift
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
@_exported import Intents
14+
import Foundation
15+
16+
#if os(iOS) || os(watchOS)
17+
18+
// Simply extending the INRideOption type doesn't work due to:
19+
// <rdar://problem/29447066>
20+
// Compiler incorrectly handles combinations of availability declarations on
21+
// independent axes.
22+
internal protocol _INRideOptionMeteredFare {
23+
var __usesMeteredFare: NSNumber? { get set }
24+
}
25+
26+
extension _INRideOptionMeteredFare {
27+
@available(swift, obsoleted: 4)
28+
@nonobjc
29+
public final var usesMeteredFare: NSNumber? {
30+
get {
31+
return __usesMeteredFare
32+
}
33+
set(newUsesMeteredFare) {
34+
__usesMeteredFare = newUsesMeteredFare
35+
}
36+
}
37+
38+
@available(swift, introduced: 4.0)
39+
@nonobjc
40+
public var usesMeteredFare: Bool? {
41+
get {
42+
return __usesMeteredFare?.boolValue
43+
}
44+
set(newUsesMeteredFare) {
45+
__usesMeteredFare = newUsesMeteredFare.map { NSNumber(value: $0) }
46+
}
47+
}
48+
}
49+
50+
@available(iOS 10.0, watchOS 3.2, *)
51+
extension INRideOption : _INRideOptionMeteredFare {
52+
}
53+
54+
#endif

test/stdlib/Intents.swift

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
// RUN: %target-run-simple-swift
2+
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
3+
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
24
// REQUIRES: executable_test
35
// REQUIRES: objc_interop
46

5-
// UNSUPPORTED: OS=watchos
67
// UNSUPPORTED: OS=tvos
78

89
import Intents
910
import StdlibUnittest
1011

1112
let IntentsTestSuite = TestSuite("Intents")
1213

13-
if #available(OSX 10.12, iOS 10.0, *) {
14+
#if swift(>=4)
15+
let swiftVersion = "4"
16+
#else
17+
let swiftVersion = "3"
18+
#endif
19+
20+
if #available(OSX 10.12, iOS 10.0, watchOS 3.2, *) {
1421

15-
IntentsTestSuite.test("ErrorDomain") {
22+
IntentsTestSuite.test("ErrorDomain/\(swiftVersion)") {
1623
expectEqual("IntentsErrorDomain", INIntentErrorDomain)
1724
}
1825

19-
IntentsTestSuite.test("extension") {
26+
IntentsTestSuite.test("extension/\(swiftVersion)") {
2027
expectEqual("IntentsErrorDomain", INIntentError._nsErrorDomain)
2128
}
2229
}
2330

2431
#if os(iOS)
2532
if #available(iOS 11.0, *) {
2633

27-
IntentsTestSuite.test("INParameter KeyPath") {
34+
IntentsTestSuite.test("INParameter KeyPath/\(swiftVersion)") {
2835
let param = INParameter(keyPath: \INRequestRideIntent.pickupLocation)
2936
expectEqual("pickupLocation", param?.parameterKeyPath)
3037
if let typ = param?.parameterClass {
@@ -35,7 +42,26 @@ if #available(iOS 11.0, *) {
3542
}
3643
}
3744
}
45+
#endif
3846

47+
#if os(iOS) || os(watchOS)
48+
if #available(iOS 10.0, watchOS 3.2, *) {
49+
50+
IntentsTestSuite.test("INRideOption usesMeteredFare/\(swiftVersion)") {
51+
func f(rideOption: inout INRideOption) {
52+
#if swift(>=4)
53+
rideOption.usesMeteredFare = true
54+
expectType(Bool?.self, &rideOption.usesMeteredFare)
55+
expectTrue(rideOption.usesMeteredFare ?? false)
56+
#else
57+
rideOption.usesMeteredFare = NSNumber(value: true)
58+
expectType(NSNumber?.self, &rideOption.usesMeteredFare)
59+
expectTrue(rideOption.usesMeteredFare?.boolValue ?? false)
60+
#endif
61+
}
62+
}
63+
64+
}
3965
#endif
4066

4167
runAllTests()

0 commit comments

Comments
 (0)