Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zhaofucheng1129 opened this issue Aug 5, 2019 · 1 comment
Open

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

zhaofucheng1129 opened this issue Aug 5, 2019 · 1 comment

Comments

@zhaofucheng1129
Copy link

zhaofucheng1129 commented Aug 5, 2019

能不能用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
Copy link
Contributor

wooseng commented Sep 10, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants