Skip to content

Commit 4a27a3e

Browse files
authored
Merge pull request #10581 from moiseev/inparameter-4-p3
[swift-4.0-branch-06-23-2017][overlay] Introducing INParameter
2 parents d567b5e + 4f564c7 commit 4a27a3e

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

stdlib/public/SDK/Intents/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_swift_library(swiftIntents ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_O
88
INGetCarLockStatusIntentResponse.swift
99
INGetCarPowerLevelStatusIntentResponse.swift
1010
INIntegerResolutionResult.swift
11+
INParameter.swift
1112
INRequestRideIntent.swift
1213
INSaveProfileInCarIntent.swift
1314
INSearchCallHistoryIntent.swift
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
@available(iOS 11.0, watchOS 4.0, *)
18+
extension INParameter {
19+
@nonobjc
20+
public convenience init?<Root, Value>(keyPath: KeyPath<Root, Value>) {
21+
if let aClass = Root.self as? AnyClass, let keyPathString = keyPath._kvcKeyPathString {
22+
self.init(for: aClass, keyPath: keyPathString)
23+
} else {
24+
return nil
25+
}
26+
}
27+
}
28+
#endif

test/stdlib/Intents.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,21 @@ if #available(OSX 10.12, iOS 10.0, *) {
2121
}
2222
}
2323

24+
#if os(iOS)
25+
if #available(iOS 11.0, *) {
26+
27+
IntentsTestSuite.test("INParameter KeyPath") {
28+
let param = INParameter(keyPath: \INRequestRideIntent.pickupLocation)
29+
expectEqual("pickupLocation", param?.parameterKeyPath)
30+
if let typ = param?.parameterClass {
31+
expectEqual(INRequestRideIntent.self, typ)
32+
}
33+
else {
34+
expectUnreachable()
35+
}
36+
}
37+
}
38+
39+
#endif
40+
2441
runAllTests()

0 commit comments

Comments
 (0)