简体   繁体   English

如果使用核心数据(布尔类型的属性),则应用崩溃

[英]App is crashing if using Core Data (attribute of type boolean)

I addded a new attribute (of type boolean) into my core data model and my data.swift class. 我在核心数据模型和data.swift类中添加了一个新属性(布尔类型)。 I try to run my app after I added the attribute. 添加属性后,我尝试运行我的应用程序。 All works fine. 一切正常。 Now I try to work with the new attribute. 现在,我尝试使用新属性。 I wrote some code, which work is working with the attribute. 我写了一些代码,该代码正在使用该属性。 Now I tried a 2nd time to run the app. 现在,我尝试了第二次运行该应用程序。 It's crashing. 崩溃了 Does someone knows why? 有人知道为什么吗?

A Bool is not an object, so it can't be managed. Bool不是对象,因此无法管理。 Instead, set the property to an NSNumber . 而是将属性设置为NSNumber

NSNumber has a property called boolValue that you can get and set to use it as a boolean. NSNumber有一个名为boolValue的属性,您可以获取并将其设置为布尔值。

Your problem is that your new DataModel isn't the same as you used when you created the datastore. 您的问题是新的DataModel与创建数据存储时使用的新DataModel不同。

So you have to delete your app from your simulator. 因此,您必须从模拟器中删除您的应用程序。 Then start your app again an it should work. 然后再次启动您的应用程序,它应该可以工作。

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

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