本文介绍了无法使用类型为((String?)'的参数列表调用类型为'Double'的初始化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
amount?.characters.count <= 0
let am = Double(amount)
我有两个问题:
let amount:String? = amountTF.text
出现错误:
Binary operator '<=' cannot be applied to operands of type 'String.CharacterView.IndexDistance?' (aka 'Optional<Int>') and 'In
出现错误:
Cannot invoke initializer for type 'Double' with an argument list of type '(String?)'我不知道该怎么解决.
推荐答案amount?.count <= 0,此处金额是可选的.您必须确保它不是nil.
amount?.count <= 0 here amount is optional. You have to make sure it not nil.
let amount:String? = amountTF.text if let amountValue = amount, amountValue.count <= 0 { }amountValue.count <= 0仅在amount不为零时被调用.
amountValue.count <= 0 will only be called if amount is not nil.
与此let am = Double(amount)相同的问题. amount是可选的.
Same issue for this let am = Double(amount). amount is optional.
if let amountValue = amount, let am = Double(amountValue) { // am }更多推荐
无法使用类型为((String?)'的参数列表调用类型为'Double'的初始化程序
发布评论