Skip to content

Photos overlay #3613

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 20, 2016
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 apinotes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(SWIFT_API_NOTES_INPUTS
NotificationCenter
ObjectiveC
PassKit
Photos
QuartzCore
QuickLook
SafariServices
Expand Down
12 changes: 12 additions & 0 deletions apinotes/Photos.apinotes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
Name: Photos
Classes:
# The below are methods for which overlays provide better implementations
- Name: PHChange
Methods:
- Selector: 'changeDetailsForObject:'
SwiftPrivate: true
MethodKind: Instance
- Selector: 'changeDetailsForFetchResult:'
SwiftPrivate: true
MethodKind: Instance
1 change: 1 addition & 0 deletions stdlib/public/SDK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_subdirectory(IOKit)
add_subdirectory(Intents)
add_subdirectory(ObjectiveC)
add_subdirectory(OpenCL)
add_subdirectory(Photos)
add_subdirectory(SafariServices)
add_subdirectory(SceneKit)
add_subdirectory(simd)
Expand Down
9 changes: 9 additions & 0 deletions stdlib/public/SDK/Photos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_swift_library(swiftPhotos ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
Photos.swift

TARGET_SDKS IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
SWIFT_MODULE_DEPENDS Foundation CoreLocation CoreImage CoreMedia
SWIFT_MODULE_DEPENDS_IOS UIKit
SWIFT_MODULE_DEPENDS_TVOS UIKit
FRAMEWORK_DEPENDS Photos)

34 changes: 34 additions & 0 deletions stdlib/public/SDK/Photos/Photos.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

@_exported import Photos

// These methods need to be generic, so that the type parameter of the input
// argument is carried through as the type parameter of the return value.
#if os(iOS) || os(tvOS)
@available(iOS 8.0, tvOS 10.0, *)
extension PHChange {
public func changeDetails<
T : PHObject
>(for object: T) -> PHObjectChangeDetails<T>? {
return self.__changeDetails(for: object) as! PHObjectChangeDetails<T>?
}

public func changeDetails<
T : PHObject
>(for fetchResult: PHFetchResult<T>) -> PHFetchResultChangeDetails<T>? {
return self.__changeDetails(
for: fetchResult as! PHFetchResult<AnyObject>
) as! PHFetchResultChangeDetails<T>?
}
}
#endif
42 changes: 42 additions & 0 deletions validation-test/stdlib/PhotosTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// RUN: %target-parse-verify-swift

// REQUIRES: objc_interop
// UNSUPPORTED: OS=watchos
// UNSUPPORTED: OS=macosx

import Photos

if #available(iOS 8.0, tvOS 10.0, *) {
// compile time only validation test for the SDK overlay,
// because PHChange pretty much requires a GUI app
struct GenericPHChangeTest {
let asset: PHAsset!
let collection: PHAssetCollection!
let list: PHCollectionList!
let assetsFetch: PHFetchResult<PHAsset>!
let collectionsFetch: PHFetchResult<PHAssetCollection>!
let listsFetch: PHFetchResult<PHCollectionList>!

func testPHChange(change: PHChange) {
let assetDetails: PHObjectChangeDetails<PHAsset>?
= change.changeDetails(for: asset)
let collectionDetails: PHObjectChangeDetails<PHAssetCollection>?
= change.changeDetails(for: collection)
let listDetails: PHObjectChangeDetails<PHCollectionList>?
= change.changeDetails(for: list)

let assetsFetchDetails: PHFetchResultChangeDetails<PHAsset>?
= change.changeDetails(for: assetsFetch)
let collectionsFetchDetails: PHFetchResultChangeDetails<PHAssetCollection>?
= change.changeDetails(for: collectionsFetch)
let listsFetchDetails: PHFetchResultChangeDetails<PHCollectionList>?
= change.changeDetails(for: listsFetch)
assert(assetDetails != nil)
assert(collectionDetails != nil)
assert(listDetails != nil)
assert(assetsFetchDetails != nil)
assert(collectionsFetchDetails != nil)
assert(listsFetchDetails != nil)
}
}
}