从“[AVCaptureDevice]”到“[AVCaptureDevice]”的条件转换总是成功的。黄色警告
Conditional cast from '[AVCaptureDevice]' to '[AVCaptureDevice]' always succeeds. Yellow warning
我有这段代码,它发出黄色警告。我不知道如何编码,所以黄色警告消失了。从 Swift-2 -> 3 -> 4 转换后尝试清理我的代码。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//On iPad Mini this returns 760 x 1024 = correct
//On the iPhone SE, this returns 320x568 = correct
print("Width: \(screenWidth)")
print("Height: \(screenHeight)")
//=======================
captureSession.sessionPreset = AVCaptureSession.Preset.high
if #available(iOS 10.0, *) {
if let devices = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera, for: AVMediaType.video, position: .back) {
print("Device name: \(devices.localizedName)")
}
} else {
}
if let devices = AVCaptureDevice.devices() as? [AVCaptureDevice] {
// Loop through all the capture devices on this phone
for device in devices {
print("Device name: \(device.localizedName)")
// Make sure this particular device supports video
if (device.hasMediaType(AVMediaType.video)) {
// Finally check the position and confirm the back camera
if(device.position == AVCaptureDevice.Position.back) {
captureDevice = device
if captureDevice != nil {
print("Capture device found")
beginSession()
}
}
}
}
}
}
错误消息说您有条件地将非可选类型转换为冗余的可选类型。
⌥-单击 devices
以检查其声明
class func devices() -> [AVCaptureDevice]
所以很简单
let devices = AVCaptureDevice.devices()
// Loop through all the capture devices on this phone
for device in devices { ...
我有这段代码,它发出黄色警告。我不知道如何编码,所以黄色警告消失了。从 Swift-2 -> 3 -> 4 转换后尝试清理我的代码。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//On iPad Mini this returns 760 x 1024 = correct
//On the iPhone SE, this returns 320x568 = correct
print("Width: \(screenWidth)")
print("Height: \(screenHeight)")
//=======================
captureSession.sessionPreset = AVCaptureSession.Preset.high
if #available(iOS 10.0, *) {
if let devices = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera, for: AVMediaType.video, position: .back) {
print("Device name: \(devices.localizedName)")
}
} else {
}
if let devices = AVCaptureDevice.devices() as? [AVCaptureDevice] {
// Loop through all the capture devices on this phone
for device in devices {
print("Device name: \(device.localizedName)")
// Make sure this particular device supports video
if (device.hasMediaType(AVMediaType.video)) {
// Finally check the position and confirm the back camera
if(device.position == AVCaptureDevice.Position.back) {
captureDevice = device
if captureDevice != nil {
print("Capture device found")
beginSession()
}
}
}
}
}
}
错误消息说您有条件地将非可选类型转换为冗余的可选类型。
⌥-单击 devices
以检查其声明
class func devices() -> [AVCaptureDevice]
所以很简单
let devices = AVCaptureDevice.devices()
// Loop through all the capture devices on this phone
for device in devices { ...