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
[SR-1522] genericization of PHFetchResult makes it unusable with PHPhotoLibraryChangeObserver #44131
Comments
cc @jckarter, @DougGregor |
As a workaround, you can do |
We had a report that the |
Another alternative is to jump up to |
Thanks for the heads up @mattneub. Let me see if I can whip up a fix for both |
@mattneub Are you able to attach your "real" app, or something like it that reproduces the crash? I just gave a naive example a whirl and wasn't able to crash it. |
For reference, I just tried this, and couldn't get it to crash: func test(list: PHCollectionList, change: PHChange) {
let fetched = PHAssetCollection.fetchCollections(in: list, options: nil)
change.changeDetails(for: fetched as! PHFetchResult<AnyObject>)
} |
@jckarter You're right, I'm wrong. The compiler crash was caused by a different bug: we can't subscript a PHFetchResult. I'll file that separately. |
Looks like we have that internally: specifically, accessing a method or property that takes or returns a bridged type based on the generic parameter (like Array, Set, or Dictionary) causes the failure. (Thanks for helping look into this, @rjmccall.) |
Is this resolved, or no longer valid? If either, this should be closed. |
Looks invalid to me. The important one is https://bugs.swift.org/browse/SR-1576 |
Environment
Toolchain: Swift Development Snapshot 2016-05-09 (a), Xcode 7.3.1, iOS 9
Additional Detail from JIRA
md5: ce5be1fe7ca94bd4c8d4af27956a9463
Issue Description:
In Swift 3, PHFetchResult now arrives into Swift as a generic. Unfortunately, this makes it impossible to use. A typical use case is:
1. Call PHAssetCollection.fetchAssetCollections to obtain a PHFetchResult.
2. Store the PHFetchResult for later use.
3. In your PHPhotoLibraryChangeObserver's implementation of photoLibraryDidChange, receive a PHChange object.
4. Call that PHChange object's changeDetails(for:) to find out what changed.
Unfortunately, step 1 yields a PHFetchResult<PHAssetCollection>, whereas step 4 requires a PHFetchResult<AnyObject>. Generics are not covariant (except for specially treated generics like Array), so this conversion is impossible. Thus, the change to a generic has broken existing code.
The text was updated successfully, but these errors were encountered: