MxABC / swiftScan

A barcode and qr code scanner( 二维码 各种码识别,生成,界面效果)
MIT License
1.59k stars 325 forks source link

博主这代码风格得改改了 #80

Open zhaofucheng1129 opened 5 years ago

zhaofucheng1129 commented 5 years ago

能不能用guard和可选绑定代替强制解包? 能不能不要这么多无意义的强制转型?

let stillImageConnection: AVCaptureConnection? = connectionWithMediaType(mediaType: .video, connections: (stillImageOutput?.connections)! as [AnyObject])

open func connectionWithMediaType(mediaType: AVMediaType, connections: [AnyObject]) -> AVCaptureConnection? {
        for connection: AnyObject in connections {
            let connectionTmp: AVCaptureConnection = connection as! AVCaptureConnection

            for port: Any in connectionTmp.inputPorts {
                if (port as AnyObject).isKind(of: AVCaptureInput.Port.self) {
                    let portTmp: AVCaptureInput.Port = port as! AVCaptureInput.Port
                    if portTmp.mediaType == mediaType {
                        return connectionTmp
                    }
                }
            }
        }
        return nil
    }

先把[AVCaptureConnection]强制转成[AnyObject] 再遍历 强制转回 AVCaptureConnection 这是什么操作????

这代码这么多强制操作真的大丈夫???

wooseng commented 5 years ago

这代码写的比较早,可能是当时情况所需,写过的代码,只要没出bug,看都不想看,改更是不可能改的,你懂得