1

我正在尝试用 Swift 重写下面的代码。但是在 Swift 中,itemSelections说它必须是 [AnyObject] 类型。有没有办法解决这个问题?谢谢

Adobe 代码

- (void)showFileChooser {

[[AdobeUXAssetBrowser sharedBrowser] popupFileBrowser:^(AdobeSelectionAssetArray *itemSelections) {
NSLog(@"Selected a file");
for(id item in itemSelections) {

AdobeAsset *it = ((AdobeSelectionAsset *)item).selectedItem;

NSLog(@"File name %@", it.name);
}
...

快速转换

AdobeUXAssetBrowser.sharedBrowser().popupFileBrowser({ (itemSelections:[AnyObject]!) -> Void in
4

1 回答 1

1

这应该有效:

AdobeUXAssetBrowser.sharedBrowser().popupFileBrowser({ (itemSelections) in
    if let itemSelectionsAssets = itemSelections as? [AdobeSelectionAsset] {
        for itemSelectionAsset in itemSelectionsAssets {
            let item = itemSelectionAsset.selectedItem
            println("File name: \(item.name)")
        }
    }
}
于 2015-03-07T07:09:45.827 回答