Skip to content

Commit cb8ec87

Browse files
committed
[SE-0112] Add typed accessors for various error types and keys.
Introduce typed accesses for the error types of AVFoundation, CloudKit, Contacts, and CoreLocation. While here, fix the API notes for the Contacts framework, which had an embarrassingly-wrong file name ;)
1 parent 63f2ec2 commit cb8ec87

File tree

11 files changed

+150
-0
lines changed

11 files changed

+150
-0
lines changed

apinotes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(SWIFT_API_NOTES_INPUTS
44
AudioToolbox
55
CallKit
66
CloudKit
7+
Contacts
78
CoreBluetooth
89
CoreData
910
CoreGraphics
File renamed without changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@_exported import AVFoundation // Clang module
2+
import Foundation
3+
4+
5+
extension AVError {
6+
/// The device name.
7+
public var device: String? {
8+
return userInfo[AVErrorDeviceKey] as? String
9+
}
10+
11+
/// The time.
12+
public var time: CMTime? {
13+
return userInfo[AVErrorTimeKey] as? CMTime
14+
}
15+
16+
/// The file size.
17+
public var fileSize: Int64? {
18+
return (userInfo[AVErrorFileSizeKey] as? NSNumber)?.int64Value
19+
}
20+
21+
/// The process ID number.
22+
public var processID: Int? {
23+
return userInfo[AVErrorPIDKey] as? Int
24+
}
25+
26+
/// Whether the recording successfully finished.
27+
public var recordingSuccessfullyFinished: Bool? {
28+
return userInfo[AVErrorRecordingSuccessfullyFinishedKey] as? Bool
29+
}
30+
31+
/// The media type.
32+
public var mediaType: String? {
33+
return userInfo[AVErrorMediaTypeKey] as? String
34+
}
35+
36+
/// The media subtypes.
37+
public var mediaSubtypes: [Int]? {
38+
return userInfo[AVErrorMediaSubTypeKey] as? [Int]
39+
}
40+
}
41+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_swift_library(swiftAVFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
2+
AVFoundation.swift
3+
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
4+
SWIFT_MODULE_DEPENDS Foundation CoreMedia
5+
FRAMEWORK_DEPENDS AVFoundation)

stdlib/public/SDK/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ endif()
1111
# Please keep this list sorted.
1212
add_subdirectory(AppKit)
1313
add_subdirectory(AssetsLibrary)
14+
add_subdirectory(AVFoundation)
1415
add_subdirectory(CallKit)
16+
add_subdirectory(CloudKit)
17+
add_subdirectory(Contacts)
1518
add_subdirectory(CoreAudio)
1619
add_subdirectory(CoreData)
1720
add_subdirectory(CoreGraphics)
1821
add_subdirectory(CoreImage)
22+
add_subdirectory(CoreLocation)
1923
add_subdirectory(CoreMedia)
2024
add_subdirectory(Dispatch)
2125
add_subdirectory(Foundation)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
add_swift_library(swiftCloudKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
2+
CloudKit.swift
3+
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR
4+
SWIFT_MODULE_DEPENDS Foundation CoreLocation
5+
SWIFT_MODULE_DEPENDS_OSX Contacts
6+
SWIFT_MODULE_DEPENDS_IOS Contacts
7+
FRAMEWORK_DEPENDS_WEAK CloudKit)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@_exported import CloudKit
2+
import Foundation
3+
4+
@available(macOS 10.10, iOS 8.0, *)
5+
extension CKErrorCode {
6+
/// Retrieve partial error results associated by item ID.
7+
public var partialErrorsByItemID: [NSObject : Error]? {
8+
return userInfo[CKPartialErrorsByItemIDKey] as? [NSObject : Error]
9+
}
10+
11+
/// The original CKRecord object that you used as the basis for
12+
/// making your changes.
13+
public var ancestorRecord: CKRecord? {
14+
return userInfo[CKRecordChangedErrorAncestorRecordKey] as? CKRecord
15+
}
16+
17+
/// The CKRecord object that was found on the server. Use this
18+
/// record as the basis for merging your changes.
19+
public var serverRecord: CKRecord? {
20+
return userInfo[CKRecordChangedErrorServerRecordKey] as? CKRecord
21+
}
22+
23+
/// The CKRecord object that you tried to save. This record is based
24+
/// on the record in the CKRecordChangedErrorAncestorRecordKey key
25+
/// but contains the additional changes you made.
26+
public var clientRecord: CKRecord? {
27+
return userInfo[CKRecordChangedErrorClientRecordKey] as? CKRecord
28+
}
29+
30+
/// The number of seconds after which you may retry a request. This
31+
/// key may be included in an error of type
32+
/// `CKErrorServiceUnavailable` or `CKErrorRequestRateLimited`.
33+
public var retryAfterSeconds: Double? {
34+
return userInfo[CKErrorRetryAfterKey] as? Double
35+
}
36+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_swift_library(swiftContacts ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
2+
Contacts.swift
3+
TARGET_SDKS OSX IOS IOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR
4+
SWIFT_MODULE_DEPENDS Foundation
5+
FRAMEWORK_DEPENDS_WEAK Contacts)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
@_exported import Contacts
14+
import Foundation
15+
16+
@available(macOS 10.11, iOS 9.0, *)
17+
extension CNErrorCode {
18+
/// One or more CNContact, CNGroup or CNContainer objects for which
19+
/// the error applies.
20+
public var affectedRecords: [AnyObject]? {
21+
return userInfo[CNErrorUserInfoAffectedRecordsKey] as? [AnyObject]
22+
}
23+
24+
/// The record identifiers to which this error applies.
25+
public var affectedRecordIdentifiers: [String]? {
26+
return userInfo[CNErrorUserInfoAffectedRecordIdentifiersKey] as? [String]
27+
}
28+
29+
/// The key paths associated with a given error. For validation
30+
/// errors this will contain key paths to specific object
31+
/// properties.
32+
public var keyPaths: [String]? {
33+
return userInfo[CNErrorUserInfoKeyPathsKey] as? [String]
34+
}
35+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_swift_library(swiftCoreLocation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
2+
CoreLocation.swift
3+
SWIFT_MODULE_DEPENDS Foundation
4+
FRAMEWORK_DEPENDS CoreLocation)

0 commit comments

Comments
 (0)