Skip to content

Update swift master to build with Xcode 10 beta 6, macOS 10.14, iOS 12, tvOS 12, and watchOS 5 SDKs #18731

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
Aug 15, 2018
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ supported host development operating systems.

#### macOS

To build for macOS, you need [Xcode 10 beta 5](https://developer.apple.com/xcode/downloads/).
To build for macOS, you need [Xcode 10 beta 6](https://developer.apple.com/xcode/downloads/).
The required version of Xcode changes frequently, and is often a beta release.
Check this document or the host information on <https://ci.swift.org> for the
current required version.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/SDK/Intents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_swift_library(swiftIntents ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_O
INSetProfileInCarIntent.swift
INSetRadioStationIntent.swift
INSetSeatSettingsInCarIntent.swift
INShortcut.swift
INStartPhotoPlaybackIntentResponse.swift
INStartWorkoutIntent.swift
NSStringIntents.swift
Expand Down
122 changes: 122 additions & 0 deletions stdlib/public/SDK/Intents/INShortcut.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 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)

@available(iOS 12.0, watchOS 5.0, *)
public enum INShortcut : ReferenceConvertible {
public typealias ReferenceType = INShortcutReference

case intent(INIntent)
case userActivity(NSUserActivity)

init(from objcShortcut: INShortcutReference) {
if let intent = objcShortcut.intent {
self = .intent(intent)
} else if let userActivity = objcShortcut.userActivity {
self = .userActivity(userActivity)
} else {
fatalError("INShortcutReference object must have either intent or userActivity")
}
}
}

// Convenience initializers, to mimic the ObjC initializer API
@available(iOS 12.0, watchOS 5.0, *)
public extension INShortcut {
public init?(intent: INIntent) {
// use the ObjC initializer, to re-use its validation of the intent
guard let ref = INShortcutReference(intent: intent) else { return nil }
self.init(from: ref)
}
public init(userActivity: NSUserActivity) {
self = .userActivity(userActivity)
}
}

// Convenience properties, to mimic the ObjC API
@available(iOS 12.0, watchOS 5.0, *)
public extension INShortcut {
public var intent: INIntent? {
guard case let .intent(intent) = self else { return nil }
return intent
}
public var userActivity: NSUserActivity? {
guard case let .userActivity(userActivity) = self else { return nil }
return userActivity
}
}

@available(iOS 12.0, watchOS 5.0, *)
extension INShortcut : CustomStringConvertible {
public var description: String {
return reference.description
}
}

@available(iOS 12.0, watchOS 5.0, *)
extension INShortcut : CustomDebugStringConvertible {
public var debugDescription: String {
return reference.debugDescription
}
}

@available(iOS 12.0, watchOS 5.0, *)
extension INShortcut : Hashable {
public func hash(into hasher: inout Hasher) {
reference.hash(into: &hasher)
}
}

@available(iOS 12.0, watchOS 5.0, *)
extension INShortcut : Equatable {}

@available(iOS 12.0, watchOS 5.0, *)
private extension INShortcut {
fileprivate var reference: INShortcutReference {
switch self {
case .intent(let intent):
return INShortcutReference(intent: intent)!
case .userActivity(let userActivity):
return INShortcutReference(userActivity: userActivity)
}
}
}

@available(iOS 12.0, watchOS 5.0, *)
extension INShortcut : _ObjectiveCBridgeable {
@_semantics("convertToObjectiveC")
public func _bridgeToObjectiveC() -> INShortcutReference {
return self.reference
}

public static func _forceBridgeFromObjectiveC(_ source: INShortcutReference, result: inout INShortcut?) {
if !_conditionallyBridgeFromObjectiveC(source, result: &result) {
fatalError("Unable to bridge \(_ObjectiveCType.self) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ source: INShortcutReference, result: inout INShortcut?) -> Bool {
result = INShortcut(from: source)
return true
}

public static func _unconditionallyBridgeFromObjectiveC(_ source: INShortcutReference?) -> INShortcut {
guard let src = source else { fatalError("Missing source") }
return INShortcut(from: src)
}
}

#endif
85 changes: 85 additions & 0 deletions test/stdlib/Intents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,91 @@ if #available(iOS 11.0, *) {
}
#endif

#if os(iOS) || os(watchOS)
if #available(iOS 12.0, watchOS 5.0, *) {

// helper functions to build test data
func buildIntent(_ identifier: String) -> INIntent {
let person = INPerson(personHandle: INPersonHandle(value: "123-456-7890", type: .phoneNumber), nameComponents: nil, displayName: "test person \(identifier)", image: nil, contactIdentifier: nil, customIdentifier: "testPerson \(identifier)")
return INSendMessageIntent(recipients: [person], content: "test content \(identifier)", speakableGroupName: INSpeakableString(spokenPhrase: "test group \(identifier)"), conversationIdentifier: nil, serviceName: "test service \(identifier)", sender: person)
}
func buildUserActivity(_ identifier: String) -> NSUserActivity {
return NSUserActivity(activityType: "test activity \(identifier)")
}

IntentsTestSuite.test("INShortcutOverlay/is enum/\(swiftVersion)") {
// INIntent
let originalIntent = buildIntent("A")
let shortcutWithIntent: INShortcut = .intent(originalIntent)
switch shortcutWithIntent {
case .intent(let intent):
expectEqual(intent, originalIntent)
case .userActivity:
expectUnreachable()
}
// test convenince properties
expectEqual(shortcutWithIntent.intent, originalIntent)
expectEqual(shortcutWithIntent.userActivity, nil)
// test convenince init
expectEqual(INShortcut(intent: originalIntent), shortcutWithIntent)

// NSUserActivity
let originalUserActivity = buildUserActivity("A")
let shortcutWithNSUA: INShortcut = .userActivity(originalUserActivity)
switch shortcutWithNSUA {
case .intent:
expectUnreachable()
case .userActivity(let userActivity):
expectEqual(userActivity, originalUserActivity)
}
// test convenince properties
expectEqual(shortcutWithNSUA.intent, nil)
expectEqual(shortcutWithNSUA.userActivity, originalUserActivity)
// test convenince init
expectEqual(INShortcut(userActivity: originalUserActivity), shortcutWithNSUA)
}

IntentsTestSuite.test("INShortcutOverlay/conformances/\(swiftVersion)") {
let intentA = buildIntent("A")
let shortcutIntentA: INShortcut = .intent(intentA)
let shortcutIntentA2: INShortcut = .intent(intentA)
let shortcutIntentB: INShortcut = .intent(buildIntent("B"))
let userActivityA = buildUserActivity("A")
let shortcutUserActivityA: INShortcut = .userActivity(userActivityA)
let shortcutUserActivityA2: INShortcut = .userActivity(userActivityA)
let shortcutUserActivityB: INShortcut = .userActivity(buildUserActivity("B"))

// Equatable
expectEqual(shortcutIntentA, shortcutIntentA2)
expectNotEqual(shortcutIntentA, shortcutIntentB)
expectEqual(shortcutUserActivityA, shortcutUserActivityA2)
expectNotEqual(shortcutUserActivityA, shortcutUserActivityB)
expectNotEqual(shortcutIntentA, shortcutUserActivityA)

// Hashable
// expectEqual(shortcutIntentA.hashValue, shortcutIntentA.hashValue)
// expectEqual(shortcutUserActivityA.hashValue, shortcutUserActivityA.hashValue)

// Strings
let _: String = shortcutIntentA.description
let _: String = shortcutIntentA.debugDescription
}

// Make sure the shortcut property of INVoiceShortcut is imported as the overlay enum type
IntentsTestSuite.test("INShortcutOverlay/INVoiceShortcut propertyIsEnum/\(swiftVersion)") {
// NOTE: we can't actually run this one becuase we can't easily create an INVoiceShortcut, but at least type-check it
func f(voiceShortcut: INVoiceShortcut) {
switch voiceShortcut.shortcut {
case .intent(let intent):
print("got intent \(intent)")
case .userActivity(let userActivity):
print("got userActivity \(userActivity)")
}
}
}
}
#endif

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

Expand Down