菜鸟教程小白 发表于 2022-12-11 19:49:53

swift - 检查一个 Int 值是否大于或等于另一个 Int?值(value)?


                                            <p><div>
            <aside class="s-notice s-notice__info post-notice js-post-notice mb16"role="status">
      <div class="d-flex fd-column fw-nowrap">
            <div class="d-flex fw-nowrap">
                <div class="flex--item wmn0 fl1 lh-lg">
                  <div class="flex--item fl1 lh-lg">
                        <b>这个问题在这里已经有了答案</b>:
                        
                  <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>因为 <code>limit</code> 是一个可选的 <code>Int</code> (<code>Int?</code>) 它可能是 nil 并且不能与 <code>current</code> 直接比较>。所以首先解开可选项来检测和避免处理 nil 的情况,并且只比较非 nil 的情况。</p>

<pre><code>if let limit = self.limit, current &gt;= limit {
    value = amount
} else {
    value = current * 10 + amount
    if value &gt; self.max! {
      value = amount
    }
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于swift - 检查一个 Int 值是否大于或等于另一个 Int?值(value)?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/49167585/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/49167585/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: swift - 检查一个 Int 值是否大于或等于另一个 Int?值(value)?