Skip to content

[swift-4.0-branch][overlay] Add INRideOption #10917

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
Jul 13, 2017
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
1 change: 1 addition & 0 deletions stdlib/public/SDK/Intents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_swift_library(swiftIntents ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_O
INIntegerResolutionResult.swift
INParameter.swift
INRequestRideIntent.swift
INRideOption.swift
INSaveProfileInCarIntent.swift
INSearchCallHistoryIntent.swift
INSearchForPhotosIntentResponse.swift
Expand Down
54 changes: 54 additions & 0 deletions stdlib/public/SDK/Intents/INRideOption.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

@_exported import Intents
import Foundation

#if os(iOS) || os(watchOS)

// Simply extending the INRideOption type doesn't work due to:
// <rdar://problem/29447066>
// Compiler incorrectly handles combinations of availability declarations on
// independent axes.
internal protocol _INRideOptionMeteredFare {
var __usesMeteredFare: NSNumber? { get set }
}

extension _INRideOptionMeteredFare {
@available(swift, obsoleted: 4)
@nonobjc
public final var usesMeteredFare: NSNumber? {
get {
return __usesMeteredFare
}
set(newUsesMeteredFare) {
__usesMeteredFare = newUsesMeteredFare
}
}

@available(swift, introduced: 4.0)
@nonobjc
public var usesMeteredFare: Bool? {
get {
return __usesMeteredFare?.boolValue
}
set(newUsesMeteredFare) {
__usesMeteredFare = newUsesMeteredFare.map { NSNumber(value: $0) }
}
}
}

@available(iOS 10.0, watchOS 3.2, *)
extension INRideOption : _INRideOptionMeteredFare {
}

#endif
36 changes: 31 additions & 5 deletions test/stdlib/Intents.swift
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
// RUN: %target-run-simple-swift
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
// REQUIRES: executable_test
// REQUIRES: objc_interop

// UNSUPPORTED: OS=watchos
// UNSUPPORTED: OS=tvos

import Intents
import StdlibUnittest

let IntentsTestSuite = TestSuite("Intents")

if #available(OSX 10.12, iOS 10.0, *) {
#if swift(>=4)
let swiftVersion = "4"
#else
let swiftVersion = "3"
#endif

if #available(OSX 10.12, iOS 10.0, watchOS 3.2, *) {

IntentsTestSuite.test("ErrorDomain") {
IntentsTestSuite.test("ErrorDomain/\(swiftVersion)") {
expectEqual("IntentsErrorDomain", INIntentErrorDomain)
}

IntentsTestSuite.test("extension") {
IntentsTestSuite.test("extension/\(swiftVersion)") {
expectEqual("IntentsErrorDomain", INIntentError._nsErrorDomain)
}
}

#if os(iOS)
if #available(iOS 11.0, *) {

IntentsTestSuite.test("INParameter KeyPath") {
IntentsTestSuite.test("INParameter KeyPath/\(swiftVersion)") {
let param = INParameter(keyPath: \INRequestRideIntent.pickupLocation)
expectEqual("pickupLocation", param?.parameterKeyPath)
if let typ = param?.parameterClass {
Expand All @@ -35,7 +42,26 @@ if #available(iOS 11.0, *) {
}
}
}
#endif

#if os(iOS) || os(watchOS)
if #available(iOS 10.0, watchOS 3.2, *) {

IntentsTestSuite.test("INRideOption usesMeteredFare/\(swiftVersion)") {
func f(rideOption: inout INRideOption) {
#if swift(>=4)
rideOption.usesMeteredFare = true
expectType(Bool?.self, &rideOption.usesMeteredFare)
expectTrue(rideOption.usesMeteredFare ?? false)
#else
rideOption.usesMeteredFare = NSNumber(value: true)
expectType(NSNumber?.self, &rideOption.usesMeteredFare)
expectTrue(rideOption.usesMeteredFare?.boolValue ?? false)
#endif
}
}

}
#endif

runAllTests()