Alterplay / APAddressBook

Easy access to iOS address book
MIT License
1.38k stars 193 forks source link

Swift Sample: BaseStorage fail to initiate StorageUpdating delegate #136

Closed InfiniteRandomVariable closed 8 years ago

InfiniteRandomVariable commented 8 years ago

self.delegate is nil in this context from file "BaseStorage.swift", therefore, the data can't update the view.

public weak var delegate : StorageUpdating? self.delegate?.storageDidPerformUpdate(self.currentUpdate!)

File "DTTableViewManager.swift"

public var storage : StorageProtocol = { ... didSet { if let headerFooterCompatibleStorage = storage as? BaseStorage { headerFooterCompatibleStorage.configureForTableViewUsage()

        }
        storage.delegate = self //never call

    }
InfiniteRandomVariable commented 8 years ago

add this below "didSet { if let headerFooterCompatibleStorage = storage as? BaseStorage ..." may solve the problem.

override public init(){
    super.init()

    defer{
        storage.delegate = self
    }

http://stackoverflow.com/questions/25230780/is-it-possible-to-allow-didset-to-be-called-during-initialization-in-swift