id值= [[错误userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey]到Swift

时间:2014-08-11 16:08:33

标签: objective-c swift

我正在尝试在swift中构建一个相机应用程序,我在互联网上搜索了一些代码并找到了这行代码。

(void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error {

NSLog(@"didFinishRecordingToOutputFileAtURL - enter");

BOOL RecordedSuccessfully = YES;
if ([error code] != noErr)
{
    // A problem occurred: Find out if the recording was successful.
    id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
    if (value)
    {
        RecordedSuccessfully = [value boolValue];
    }
}
...

如何在swift中编写 id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];

我尝试:

value = error.userInfo[AVErrorRecordingSuccessfullyFinishedKey]

但它显示了这个错误:'NSString无法转换为'DictionaryIndex'

1 个答案:

答案 0 :(得分:0)

所以,你可以用这种方式编写这行代码:

var value: AnyObject! = error.userInfo[AVErrorRecordingSuccessfullyFinishedKey]

UPD:

根据此警告,您正在使用小于5的xCode测试版:

  

' NSString无法转换为' DictionaryIndex'

更新它!