2016-03-03 203 views
1

實施PHPhotoLibraryChangeObserver協議我想設置我的AssetService爲changeObserver,但我得到了如下因素的錯誤:在迅速

Error:(8, 14) type 'AssetService' does not conform to protocol 'PHPhotoLibraryChangeObserver'

雖然photoLibraryDidChange是唯一需要的方法。這裏是我的代碼:

import UIKit 
import Photos 

public class AssetService : PHPhotoLibraryChangeObserver { 

    public init() { 

     // here I do some other stuff 
     PHPhotoLibrary.sharedPhotoLibrary().registerChangeObserver(self) 
    } 

    public func photoLibraryDidChange(changeInstance: PHChange) { 
     dispatch_async(dispatch_get_main_queue(), { 

     }) 
    } 
} 

回答

1

我認爲你需要從NSObject的,才能在PhotoFramework使用它

因此,您也需要重載init,並添加super.init()

import UIKit 
import Photos 

public class AssetService : NSObject, PHPhotoLibraryChangeObserver { 
    public override init() { 
     super.init() 
     // here I do some other stuff 
     PHPhotoLibrary.sharedPhotoLibrary().registerChangeObserver(self) 
    } 

    public func photoLibraryDidChange(changeInstance: PHChange) { 
     dispatch_async(dispatch_get_main_queue(), { 

     }) 
    } 
} 
延長

希望這將解決這個問題

0

在雨燕3.0的寄存器實際上看起來現在這個樣子:

func photoLibraryDidChange(_ changeInstance: PHChange) { 
    DispatchQueue.main.async { 

    } 
} 

public override init() { 
    super.init() 
    PHPhotoLibrary.shared().register(self) 
} 

其他一切都在Bart Schoon's answer