我正在使用AVCaptureDeviceInput類,它是Swift中AVFoundation的一部分。 iniitializer拋出一個異常,我想找出異常的原因。應該有一個NSError對象給出信息。雨燕調用API參考文檔是:從Swift 3調用基礎類的Objective-C替代實現
Declaration
init(device: AVCaptureDevice!) throws
Parameters
device
The device from which to capture input.
outError
If an error occurs during initialization, upon return contains an NSError object describing the problem.
Xcode不是讓我第二個參數給我的電話加入到AVCaptureDeviceInput(device: device!)
。在我看來,有關outError參數的文檔是錯誤的。
API參考也有一個Objective-C的定義如下:
Declaration
- (instancetype)initWithDevice:(AVCaptureDevice *)device
error:(NSError **)outError;
Parameters
device
The device from which to capture input.
outError
If an error occurs during initialization, upon return contains an NSError object describing the problem.
Return Value
An input initialized to use device.
我見過的示例代碼在線返回的NSError,但它在斯威夫特2.有沒有一種方法我可以得到在Swift 3中?
請參閱我的在線書籍:http://www.apeth.com/swiftBook/ch05.html#_throwing_and_catching_errors討論如何對應Objective-C錯誤:(NSError **)outError'結構該部分的結尾。 – matt