latestObjectのタイプを確認したいと思います。ここではいくつかのコードがあります:取り出したオブジェクトがSwiftのImageまたはVideoであるかチェックしてください
if let asset = allMedia.lastObject as? PHAsset {
switch asset.mediaType {
case .Image:
print("Image")
case .Video:
print("Video")
case .Audio:
print("Audio")
default:
print("Unknown")
}
}
PHFetchResult
に含まれる各要素は、(この場合)PHAsset
です:
allMedia = PHAsset.fetchAssetsWithOptions(fetchOptions)
let allPhotos = PHAsset.fetchAssetsWithMediaType(.Image, options: fetchOptions)
let allVideo = PHAsset.fetchAssetsWithMediaType(.Video, options: fetchOptions)
print("Found \(allMedia.count) media")
print("Found \(allPhotos.count) images")
print("Found \(allVideo.count) videos")
let latestObject: AnyObject! = allMedia.lastObject
// How to check what type latestObject is?
// I think something with mediaType but how is it exactly going?
チェック:1)http://stackoverflow.com/questions/31582717/how-to-check-a-file-is-video-or-image 2)http://stackoverflow.com/questions/17145844/ iphone-how-to-the-file-is-a-directory-audio-video-or-image – sohil