我有一个函数( 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 。
所以不,不需要检查。