我们曾经使用过assign
-1
表示未分配的正整数。
尝试
<code>
return formatter.number(from: stringValue) ?? -1
</code>
并且您可以检查返回值是否大于或等于零。
if(str.asNum >= 0){
//You’re getting the correct conversation here.
}else{
//You’re not getting the correct conversion here.
}
</code>