草庐IT

ios - "unrecognized selector sent to instance"属性 setter

coder 2024-01-23 原文

我有一个继承自 UILocalNotification 的自定义类,它有一个 Store 对象属性(一个继承自 NSObject 的类):

customLocalNotification.h:

@property (strong,nonatomic) Store *store;

但是当我尝试像这样在 viewController 中设置“Store”对象时:

customLocalNotification *notification=[[customLocalNotification alloc] init];
notification.store=store; //Crashes here

编辑:我将使用 userInfo 字典来保存我的 Store 对象,但是当我尝试这样做时它崩溃并出现此错误留言:

2016-02-11 15:55:26.132 App[13861:3606796] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unable to serialize userInfo: Error Domain=NSCocoaErrorDomain Code=3851 "Property list invalid for format: 200 (property lists cannot contain objects of type 'CFType')" UserInfo={NSDebugDescription=Property list invalid for format: 200 (property lists cannot contain objects of type 'CFType')}'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010c196e65 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010bc0fdeb objc_exception_throw + 48
2   UIKit                               0x000000010cbd5ba5 -[UIConcreteLocalNotification userInfo] + 0
3   App                            0x00000001088cb65b -[monitorLocationViewController createNotificationWithStore:andArounders:] + 683
4   App                            0x00000001088cb1ed -[monitorLocationViewController sendNotificationIfNeededForStore:] + 397
5   App                            0x00000001088cb021 -[monitorLocationViewController locationManager:didEnterRegion:] + 145
6   App                            0x00000001088cae9c __68-[monitorLocationViewController locationManager:didUpdateLocations:]_block_invoke + 284
7   CoreFoundation                      0x000000010c0f59ff __51-[__NSSetM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 79
8   CoreFoundation                      0x000000010c0f590a -[__NSSetM enumerateObjectsWithOptions:usingBlock:] + 202
9   App                            0x00000001088cad02 -[monitorLocationViewController locationManager:didUpdateLocations:] + 402
10  CoreLocation                        0x000000010a8c5177 CLClientGetCapabilities + 20882
11  CoreLocation                        0x000000010a8c15d3 CLClientGetCapabilities + 5614
12  CoreLocation                        0x000000010a8bc0cd CLClientInvalidate + 923
13  CoreFoundation                      0x000000010c0c2a1c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
14  CoreFoundation                      0x000000010c0b86a5 __CFRunLoopDoBlocks + 341
15  CoreFoundation                      0x000000010c0b7e02 __CFRunLoopRun + 850
16  CoreFoundation                      0x000000010c0b7828 CFRunLoopRunSpecific + 488
17  GraphicsServices                    0x000000010ed92ad2 GSEventRunModal + 161
18  UIKit                               0x000000010c543610 UIApplicationMain + 171
19  App                            0x00000001088dedef main + 111
20  libdyld.dylib                       0x000000010dbbe92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

有谁知道为什么会崩溃?

谢谢!

最佳答案

UILocalNotifications 旨在包含一些轻量级 数据。也就是说,userInfo 可以包含 property list encodable仅项目。我要补充一点,整个事情并不是为了扔重物而设计的,而只是传递一些上下文信息,你需要在通知到达时处理这些信息(即一些标识符、数字等)。

关于ios - "unrecognized selector sent to instance"属性 setter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35340798/

有关ios - "unrecognized selector sent to instance"属性 setter的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - 如果为空或不验证数值,则使属性默认为 0 - 2

    我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val

  4. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  5. ruby-on-rails - 在混合/模块中覆盖模型的属性访问器 - 2

    我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah

  6. ruby - 多个属性的 update_column 方法 - 2

    我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2

  7. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  8. ruby - Nokogiri 剥离所有属性 - 2

    我有这个html标记:我想得到这个:我如何使用Nokogiri做到这一点? 最佳答案 require'nokogiri'doc=Nokogiri::HTML('')您可以通过xpath删除所有属性:doc.xpath('//@*').remove或者,如果您需要做一些更复杂的事情,有时使用以下方法遍历所有元素会更容易:doc.traversedo|node|node.keys.eachdo|attribute|node.deleteattributeendend 关于ruby-Nokog

  9. ruby-on-rails - Rails 模型——非持久类成员或属性? - 2

    对于Rails模型,是否可以/建议让一个类的成员不持久保存到数据库中?我想将用户最后选择的类型存储在session变量中。由于我无法从我的模型中设置session变量,我想将值存储在一个“虚拟”类成员中,该成员只是将值传递回Controller。你能有这样的类(class)成员吗? 最佳答案 将非持久属性添加到Rails模型就像任何其他Ruby类一样:classUser扩展解释:在Ruby中,所有实例变量都是私有(private)的,不需要在赋值前定义。attr_accessor创建一个setter和getter方法:classUs

  10. ruby-on-rails - 相关表上的范围为 "WHERE ... LIKE" - 2

    我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que

随机推荐