Amit Erandole
Amit Erandole

Reputation: 12281

ALAssetsGroup! is not a subtype of 'ALAssetsGroup'

I have a loadAlbums method in my app that loads assets using a singleton instance of the AssetsLibrary. Here is my code so far:

func loadAlbums(){
    let library = IAAssetsLibraryDefaultInstance

    library.enumerateGroupsWithTypes(ALAssetsGroupAll as ALAssetsGroupType,
        usingBlock: {(group:ALAssetsGroup, stop:Bool) in
            if group {
                self.albums.append(group)
            }
            else {
                self.tableView.performSelectorOnMainThread("reloadData", withObject: nil, waitUntilDone: true)
            }
        }, failureBlock: { (error:NSError) in println("Problem loading albums: \(error)") })

}

The error I am getting is at the beginning of the usingBlock line. The compiler says:

ALAssetsGroup! is not a subtype of 'ALAssetsGroup'

What does this mean? How do I fix this?

Upvotes: 0

Views: 195

Answers (1)

Jiaaro
Jiaaro

Reputation: 76928

your block is expecting an ALAssetsGroup for the group argument, but it's being passed a an argument with type ALAssetsGroup! (an implicitly unwrapped optional).

The big difference is that the value you're being passed can be nil, but the type you're expected can not be nil

just change your signature to

{(group:ALAssetsGroup!, stop:Bool) in
  …
}

your code is already checking if group is nil, so that should be the only change you need to make

Upvotes: 1

Related Questions