Reputation: 938
I'm trying to access photos stored in macOS Photos app and have this code in ViewController class.
import Cocoa
import Photos
class vcSecond: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
let identifiers = PHPhotoLibrary.localIdentifiers(PHPhotoLibrary())
let assets = PHAsset.fetchAssets(withLocalIdentifiers: identifiers, options: fetchOptions)
print(assets.count)
}
}
and I'm struggled with getting of localIdentifiers for fetchAssets method. XCode gives me error "Cannot convert value of type '([PHCloudIdentifier]) -> [String]' to expected argument type '[String]'". There are many code samples availbale for iOS but much lees for macOS. Is anyone willing to share some codes and/or provide any hints? Thanks.
Upvotes: 0
Views: 983
Reputation: 1292
Well if all you are trying to do is access the photos then to open the Photo app just add this code snippet to your controller
override func viewDidLoad() {
super.viewDidLoad()
NSWorkspace.shared.open(URL(fileURLWithPath: "/Applications/Photos.app"))
}
Also, see this thread: How to get all PHAssets from MacOS's Photo Library
Upvotes: 0