我正在尝试在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
答案 0 :(得分: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)")
}
}
}