Skip to content

Commit 616f58c

Browse files
author
Max Moiseev
committed
Photos overlay
1 parent 7ac1108 commit 616f58c

File tree

6 files changed

+99
-0
lines changed

6 files changed

+99
-0
lines changed

apinotes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ set(SWIFT_API_NOTES_INPUTS
3232
NotificationCenter
3333
ObjectiveC
3434
PassKit
35+
Photos
3536
QuartzCore
3637
QuickLook
3738
SafariServices

apinotes/Photos.apinotes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
Name: Photos
3+
Classes:
4+
# The below are methods for which overlays provide better implementations
5+
- Name: PHChange
6+
Methods:
7+
- Selector: 'changeDetailsForObject:'
8+
SwiftPrivate: true
9+
MethodKind: Instance
10+
- Selector: 'changeDetailsForFetchResult:'
11+
SwiftPrivate: true
12+
MethodKind: Instance

stdlib/public/SDK/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ add_subdirectory(IOKit)
3030
add_subdirectory(Intents)
3131
add_subdirectory(ObjectiveC)
3232
add_subdirectory(OpenCL)
33+
add_subdirectory(Photos)
3334
add_subdirectory(SafariServices)
3435
add_subdirectory(SceneKit)
3536
add_subdirectory(simd)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
add_swift_library(swiftPhotos ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
2+
Photos.swift
3+
4+
TARGET_SDKS IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
5+
SWIFT_MODULE_DEPENDS Foundation CoreLocation CoreImage CoreMedia
6+
SWIFT_MODULE_DEPENDS_IOS UIKit
7+
SWIFT_MODULE_DEPENDS_TVOS UIKit
8+
FRAMEWORK_DEPENDS Photos)
9+

stdlib/public/SDK/Photos/Photos.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 Photos
14+
15+
// These methods need to be generic, so that the type parameter of the input
16+
// argument is carried through as the type parameter of the return value.
17+
#if os(iOS) || os(tvOS)
18+
@available(iOS 8.0, tvOS 10.0, *)
19+
extension PHChange {
20+
public func changeDetails<
21+
T : PHObject
22+
>(for object: T) -> PHObjectChangeDetails<T>? {
23+
return self.__changeDetails(for: object) as! PHObjectChangeDetails<T>?
24+
}
25+
26+
public func changeDetails<
27+
T : PHObject
28+
>(for fetchResult: PHFetchResult<T>) -> PHFetchResultChangeDetails<T>? {
29+
return self.__changeDetails(
30+
for: fetchResult as! PHFetchResult<AnyObject>
31+
) as! PHFetchResultChangeDetails<T>?
32+
}
33+
}
34+
#endif
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %target-parse-verify-swift
2+
3+
// REQUIRES: objc_interop
4+
// UNSUPPORTED: OS=watchos
5+
// UNSUPPORTED: OS=macosx
6+
7+
import Photos
8+
9+
if #available(iOS 8.0, tvOS 10.0, *) {
10+
// compile time only validation test for the SDK overlay,
11+
// because PHChange pretty much requires a GUI app
12+
struct GenericPHChangeTest {
13+
let asset: PHAsset!
14+
let collection: PHAssetCollection!
15+
let list: PHCollectionList!
16+
let assetsFetch: PHFetchResult<PHAsset>!
17+
let collectionsFetch: PHFetchResult<PHAssetCollection>!
18+
let listsFetch: PHFetchResult<PHCollectionList>!
19+
20+
func testPHChange(change: PHChange) {
21+
let assetDetails: PHObjectChangeDetails<PHAsset>?
22+
= change.changeDetails(for: asset)
23+
let collectionDetails: PHObjectChangeDetails<PHAssetCollection>?
24+
= change.changeDetails(for: collection)
25+
let listDetails: PHObjectChangeDetails<PHCollectionList>?
26+
= change.changeDetails(for: list)
27+
28+
let assetsFetchDetails: PHFetchResultChangeDetails<PHAsset>?
29+
= change.changeDetails(for: assetsFetch)
30+
let collectionsFetchDetails: PHFetchResultChangeDetails<PHAssetCollection>?
31+
= change.changeDetails(for: collectionsFetch)
32+
let listsFetchDetails: PHFetchResultChangeDetails<PHCollectionList>?
33+
= change.changeDetails(for: listsFetch)
34+
assert(assetDetails != nil)
35+
assert(collectionDetails != nil)
36+
assert(listDetails != nil)
37+
assert(assetsFetchDetails != nil)
38+
assert(collectionsFetchDetails != nil)
39+
assert(listsFetchDetails != nil)
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)