Gallery Swift错误没有成员如何使用'init(forAssetCollection:assets :)'已被'init(for:assets :)'取代

时间:2018-06-13 14:24:09

标签: ios swift xcode gallery

我正在为我的学校开发一个应用程序,但不幸的是我无法跟上,因为我有几个错误。请有人帮帮我吗?

以下是代码中错误的图片。 enter image description here

以下是我的错误:

  1. 类型'ViewController'的值没有成员'assetCollectionPlaceholder'
  2. 类型'ViewController'的值没有成员'assetCollectionPlaceholder'
  3. “ViewController”类型的值没有成员“image”
  4. 'init(forAssetCollection:assets :)'已替换为'init(for:assets :)'
  5. 'ViewController'类型的值没有成员'showImages'
  6. 以下是顶部的代码:

    import UIKit
    import Photos
    var image: UIImage!
    var assetCollection: PHAssetCollection!
    var albumFound : Bool = false
    var photosAsset: PHFetchResult<AnyObject>!
    var assetThumbnailSize:CGSize!
    var collection: PHAssetCollection!
    var assetCollectionPlaceholder: PHObjectPlaceholder!
    

    以下是代码:

        func createAlbum() {
            //Get PHFetch Options
            stronglet fetchOptions = PHFetchOptions()
            fetchOptions.predicate = NSPredicate(format: "title = %@", "camcam")
            let collection : PHFetchResult = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: fetchOptions)
            //Check return value - If found, then get the first album out
            if let _: AnyObject = collection.firstObject {
                self.albumFound = true
                assetCollection = collection.firstObject as! PHAssetCollection
            } else {
                //If not found - Then create a new album
                PHPhotoLibrary.shared().performChanges({
                    let createAlbumRequest : PHAssetCollectionChangeRequest = PHAssetCollectionChangeRequest.creationRequestForAssetCollection(withTitle: "camcam")
                   self.assetCollectionPlaceholder = createAlbumRequest.placeholderForCreatedAssetCollection   
                }, completionHandler: { success, error in
                    self.albumFound = success
    
                    if (success) {
                        let collectionFetchResult = PHAssetCollection.fetchAssetCollectionsWithLocalIdentifiers([self.assetCollectionPlaceholder.localIdentifier], options: nil)
                        print(collectionFetchResult)
                        self.assetCollection = collectionFetchResult.firstObject as! PHAssetCollection
                    }
                })
            }
        }
    
        func saveImage(){
            PHPhotoLibrary.shared().performChanges({
                let assetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(atFileURL: self.image)
                let assetPlaceholder = assetRequest.placeholderForCreatedAsset
                let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: self.assetCollection, assets: self.photosAsset as! PHFetchResult<PHAsset>)
                albumChangeRequest!.addAssets([assetPlaceholder!])
            }, completionHandler: { success, error in
                print("added image to album")
                print(error as Any)
    
                self.showImages()
            })
        }
    

0 个答案:

没有答案