简体   繁体   English

模型验证导致iOS应用崩溃

[英]Model validation causes iOS app to crash

I have an object with an attribute in my xcdatamodel that has validation around it (it must be between 0 and 100). 我的xcdatamodel中有一个带有属性的对象,该对象周围具有验证(它必须在0到100之间)。

However, when a value is entered with a value out of range it causes the app to crash when I try to save the object. 但是,当输入的值超出范围时,当我尝试保存对象时,它将导致应用程序崩溃。

Having come from a web development background, I would have expected a DB rollback w/ error message. 由于具有Web开发背景,因此我希望数据库回滚并显示错误消息。

Is a crash normal procedure and is there a way to change this beside checking every value before a save? 是正常的崩溃过程,除了在保存之前检查每个值之外,是否可以更改此过程?

There is no DB as such when writing an iOS App from scratch. 从头开始编写iOS应用程序时,没有这样的数据库。 You have several options on how to store your data - one of them being Core Data, which has a SQL backend to it. 您有几种关于如何存储数据的选择-其中之一是Core Data,该数据具有SQL后端。

Error handling is something you have to do yourself, too. 错误处理也是您自己必须做的事情。 If you're only expecting values from 0 to 100 you need to handle values out side of that range too. 如果仅期望0到100之间的值,则还需要处理超出该范围的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM