Whenever I call this method on the PHPhotoLibrary class I get a warning which I've included below. I've tried looking in the Apple forums, Stack Overflow etc. and nobody seems to mention this issue that I can find. Is this warning unavoidable or am I using the API wrong? I can reproduce this trivially in a simple untitled project.
Warning: Retain cycle risk: client-side managed object fetch on long-lived context for entity Asset, on context named: PHPhotoLibrary (inode=19657147) .Generic, consider using -[PHPhotoLibrary performAndWaitOnAutoResettingLibraryWithName:workBlock:] or +[PLDatabaseContext newShortLivedLibraryWithName:bundle:]...work, or using a dictionary result type, or suppressing this warning using 'clientSideLongLivedFetchWarningsSuppressed').
STEPS TO REPRODUCE
- Create a new untitled App project in Xcode.
- Set a photo library usage privacy description in the Info for the project target
- Replace ContentView.swift with the code included below.
- Make sure there is at least one photo in the photo library on the target device. A simulator is fine.
- Run the app
- Click the Get Cloud ID button, respond to the authorization dialog
- Click the Get Cloud ID button again
- Look in Xcode and see the warning
import SwiftUI
import Playgrounds
import Photos
struct ContentView: View {
var body: some View {
Button( action: getCloudID ) {
Text("Get Cloud ID")
}
.padding()
}
private func getCloudID() {
var fetchOptions = PHFetchOptions()
fetchOptions.fetchLimit = 1
let assetResult = PHAsset.fetchAssets(with: .image, options: fetchOptions)
var localIds = [String]()
assetResult.enumerateObjects() {
asset, _, _ in
localIds.append(asset.localIdentifier)
}
let mappings = PHPhotoLibrary.shared().cloudIdentifierMappings(forLocalIdentifiers: localIds )
for mapping in mappings {
debugPrint("cloud ID \(mapping.value)")
}
}
}
`