单键和keypath之间有什么区别?

时间:2022-03-05 22:30:02

as shown in this page

如本页所示

[self setValue:[NSNumber numberWithInt:intValue] forKey:@"myObject.value"];

The answer was that "of course, it's a key path not a single key", What does that mean?

答案是“当然,这是一条关键路径,而不是一把钥匙”,这是什么意思?

1 个解决方案

#1


10  

A key is a string that identifies a property of an object. A key path is a list of keys separated by dots, used to identify a nested property.

键是一个标识对象属性的字符串。键路径是由点分隔的键列表,用于标识嵌套属性。

Here's an example. If an object person has a property address, which itself has a property town you could get the town value in two steps using keys:

这是一个例子。如果一个对象人有一个属性地址,它本身就有一个属性城镇,你可以使用键分两步获得城镇价值:

id address = [person valueForKey:@"address"];
id town = [address valueForKey:@"town"];

or in one step using a keyPath:

或者使用keyPath一步完成:

id town = [person valueForKeyPath:@"address.town"];

Have a look at Apple's docs on Key-Value Coding for further details.

有关更多详细信息,请查看Apple关于键值编码的文档。

#1


10  

A key is a string that identifies a property of an object. A key path is a list of keys separated by dots, used to identify a nested property.

键是一个标识对象属性的字符串。键路径是由点分隔的键列表,用于标识嵌套属性。

Here's an example. If an object person has a property address, which itself has a property town you could get the town value in two steps using keys:

这是一个例子。如果一个对象人有一个属性地址,它本身就有一个属性城镇,你可以使用键分两步获得城镇价值:

id address = [person valueForKey:@"address"];
id town = [address valueForKey:@"town"];

or in one step using a keyPath:

或者使用keyPath一步完成:

id town = [person valueForKeyPath:@"address.town"];

Have a look at Apple's docs on Key-Value Coding for further details.

有关更多详细信息,请查看Apple关于键值编码的文档。