- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
所以我在使用 Switch 语句时遇到问题,当我将它与范围一起使用时,我在控制台中收到此“ fatal error :范围结束索引没有有效的后继者”。
var ArrayBytes : [UInt8] = [48 ,48 ,48]
var SuperArrayMensaje : Array = [[UInt8]]()
var num7BM : Array = [UInt8]()
for var Cont27 = 0; Cont27 < 800; Cont27++ {
ArrayBytesReservaSrt = String(Mensaje7BM[Cont27])
switch Mensaje7BM[Cont27] {
case 0...9 :
num7BM = Array(ArrayBytesReservaSrt.utf8)
ArrayBytes.insert(num7BM[0], atIndex: 2)
case 10...99 :
num7BM = Array(ArrayBytesReservaSrt.utf8)
ArrayBytes.insert(num7BM[0], atIndex: 1)
ArrayBytes.insert(num7BM[1], atIndex: 2)
case 100...255 : // --> THE problem is here "EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)"
num7BM = Array(ArrayBytesReservaSrt.utf8)
ArrayBytes.insert(num7BM[0], atIndex: 0)
ArrayBytes.insert(num7BM[1], atIndex: 1)
ArrayBytes.insert(num7BM[2], atIndex: 2)
default : break
}
SuperArrayMensaje.insert(ArrayBytes, atIndex: Cont27)
ArrayBytes = [48 ,48 ,48]
}
最佳答案
问题可以用这个 MCVE 重现:
let u = 255 as UInt8
switch u {
case 0...9: print("one")
case 10...99: print("two")
case 100...255: print("three")
}
在某种程度上,如果我们只是尝试创建一个覆盖此范围的范围变量,我们就会看到问题:
let r = Range<UInt8>(start: 100, end: 256)
这不会编译。首先,我们必须注意 end
Range
的参数构造函数不包含在范围内。
范围 100...255
相当于100..<256
.如果我们尝试构造该范围,则会出现编译错误:
Integer literal '256' overflows when stored into 'UInt8'
我们无法创建一个包括该整数类型的最大值的范围。有问题的是,没有 UInt8
值大于 255
.这是必需的,因为要将某些内容包含在一个范围内,它必须小于 end
。范围的值。也就是说,与 <
相比,它必须返回 true运算符(operator)。而且没有 UInt8
可以进行此声明的值:255 < n
返回真。因此,255
永远不能在 UInt8
类型的范围内.
因此,我们必须找到不同的方法。
作为程序员,我们可以知道我们试图创建的范围表示适合 UInt8
的所有三位十进制数。 ,我们可以只使用 default
这里的案例:
let u = 255 as UInt8
switch u {
case 0...9: print("one")
case 10...99: print("two")
default: print("three")
}
这似乎是最简单的解决方案。我最喜欢这个选项,因为我们不会以 default
结束。我们知道永远不会执行的案例。
如果我们真的明确想要一个捕获来自 100
的所有值的案例至 UInt8
max,我们也可以这样做:
switch u {
case 0...9: print("one")
case 10...99: print("two")
case 100..<255, 255: print("three")
default: print("how did we end up here?")
}
或者像这样:
switch u {
case 0...9: print("one")
case 10...99: print("two")
case 100...255 as ClosedInterval: print("three")
default: print("default")
}
有关 ClosedInterval
的更多阅读, 请参阅 Apple documentation或 Swift doc .
关于swift - fatal error : Range end index has no valid successor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36298549/
当我尝试输入时,我正在关注 Ray Wenderlich ( https://videos.raywenderlich.com/screencasts/545-server-side-swift-wi
我正在使用 javax.validation.Validation 来验证 jpa 实体。我总是针对相同的实体进行验证。 我想知道是对所有验证使用一个 validator 更好,还是每次验证时实例化一
Controller : @RequestMapping(...) public void foo(@Valid Parent p){ } class Parent { @NotNull // j
在 login.phtml 中,validator 和 validate 之间有什么区别 - 有人可以解释下面每一行的含义 function onepageLogin(button)
我有一个 java bean 用于将 JSON 消息发送到 spring @RestController 并且我有 bean 验证设置并使用 @Valid 运行得很好。但我想转移到 Protobuf/
我正在使用 vee-validate 来验证注册表单,我编写了如下代码,
使用 有什么区别属性和 标签? 我应该什么时候使用哪一种? 最佳答案 validator属性允许您引用独立的托管 bean 方法,而不仅仅是像这样的验证器
我们有这个 Alamofire 错误处理: Alamofire.request(.GET, getUrl("mystuff")).responseData { response in guar
以下代码创建了两个单选按钮。每个选项都包含一个日期值,该日期值已成功转换为格式为“yyyy-MM-dd”的标签。一旦我做出选择并单击下一步按钮,我就会收到以下错误“j_idt12:comDateCho
是否有类似的验证: req.checkBody('property', 'should be present').isPresent(); 值本身并不重要。 现在我使用这个解决方案: .isLengt
系列文章: 1、async-validator 源码学习(一):文档翻译 2、async-validator 源码学习笔记(二):目录结构 3、async-validator 源码学习笔记(三):ru
我正在使用 Backbone.Validation插入。我有一个模型可以在服务器端进行唯一性检查。我如何让 backbone.validation 识别错误并运行我设置的回调以显示返回的错误消息? t
我有一个 Knockout.Validation 场景,我认为该场景相当普遍,但尚未通过在网络上搜索和本网站上的各种答案找到解决方案。 我正在验证的属性在 ajax 调用之后才会添加到可观察到的 kn
我是 Knockout JS 的新手。我需要一个验证器来验证用户将在文本框中输入的日期。为此编写了如下代码 ko.validation.rules['date'] = { validator:
如何在 JSF 验证器中比较两个字符串是否相等? if (!settingsBean.getNewPassword().equals(settingsBean.getConfirmPassword()
我有简单的域: package app class Customers { String CUSTOMER String NOTE static mapping = {
我正在使用 ember-validations 来验证表单中的模型。 如果我使用 createRecord 创建记录,则模型的实例已经过验证,因此在用户输入值之前表单已经显示验证错误。 我只想在提交表
我有两种不同的服务:第一个是将对象保存到数据库,第二个是更新现有对象。 我正在对我的对象使用验证约束,例如(@NotBlank、@Size、@Pattern 等),在第一种情况下,我需要验证对象的所有
我有 2 个 ensure - 验证装饰器用于 2 个字段:password 和 retypePassword。我想在填写 retypePassword 字段时检查这两个字段是否相等。 问题是,当我在
I'm aware that it's a bug ,但是在域类上调用 validate() 会覆盖之前放入的任何拒绝: def save = { def assignment = new A
我是一名优秀的程序员,十分优秀!