2015-08-18 29 views
0

我想在用户选择对象所在的行后重新分配嵌套值。我基本上重建一个阅读收据功能。它不断抛出一个错误,说“表达是不可转让”当我使用这个:重新分配嵌套键值

[[self.conversations objectAtIndex:indexPath.row] valueForKeyPath:@"recipientRead"] = true; 

和它说:“物业‘recipientRead’在类型的对象‘身份证’未找到”当我使用这个:

self.conversations[indexPath.row].recipientRead = true; 

我该如何访问此索引行的此对象并为其分配新变量?

这是我的谈话对象的样子:

conversations = (
"<Convo: 0x174117970, objectId: kq1H963zwX, localId: (null)> {\n leanId = 7FvjCFbVcv;\n messageBody = Test;\n recipientDisplayName = Ian;\n recipientId = SXeTdhJcRn;\n recipientRead = 0;\n senderDisplayName = user2;\n senderId = rBi8XjVxx5;\n senderRead = 1;\n timeStamp = \"2015-08-18 14:31:48\";\n}", 
"<Convo: 0x17410e340, objectId: 4VAkXEJK4i, localId: (null)> {\n leanId = maLdMRcsRS;\n messageBody = \"Test 555\";\n recipientDisplayName = Ian;\n recipientId = SXeTdhJcRn;\n senderDisplayName = user2;\n senderId = rBi8XjVxx5;\n timeStamp = \"2015-08-16 15:38:19\";\n}", 
"<Convo: 0x17010f9c0, objectId: Sbct8LnaMg, localId: (null)> {\n leanId = tOYG4Einld;\n messageBody = Test;\n recipientDisplayName = Ian;\n recipientId = SXeTdhJcRn;\n senderDisplayName = user2;\n senderId = rBi8XjVxx5;\n timeStamp = \"2015-08-16 15:32:45\";\n}", 
+0

很难知道,因为你不会说'valueForKeyPath:@“recipientRead”'获取了什么类型的东西。你的意思是'setValue:forKeyPath:'? – matt

+0

哇哇。谢谢马特。有没有办法将此类型强制转换为int类型,因为它现在抛出“Int'隐式转换为'id'不允许使用ARC”? – icscott

+0

首先,没有'true'这样的东西。你应该使用'YES'。其次,“YES”不是一个对象。你必须使用'@ YES'。 – matt

回答

0

这是因为.DOT符号需要强类型,因为它不是在你的例子指定

ClassName *conversation = self.conversations[indexPath.row]; 
conversation.recipientRead = YES; 

您只需使用自己的类名;)