我们是否应该对非选项变量进行零检查



我有一个函数( abc),如下所示,当参数通过的是空或零时,我应该丢下错误,我应该检查 nil还是只有空的?

public func abc(forURL serviceUrl:String,serviceID:String, error:inout Error? )throws ->[AnyHashable : Any]{
        guard serviceUrl != nil, !serviceUrl.isEmpty else {
            let argError:Error = MapError.emptyArgumentUrl.error()
            error = argError
            throw argError
        }
        guard !serviceID.isEmpty else {
            let argError:Error = MapError.emptyArgumentServiceId.error()
            error = argError
            throw argError
        }

serviceID不是可选的

这意味着不能是nil

所以不,不需要检查。

最新更新