-
源码加翻译
#import
#import #import #import #import @class NSError, NSString; NS_ASSUME_NONNULL_BEGIN /* The exception that is thrown when a key value coding operation fails. The exception's user info dictionary will contain at least two entries: - @"NSTargetObjectUserInfoKey": the receiver of the failed KVC message. - @"NSUnknownUserInfoKey": the key that was used in the failed KVC message. 当键值编码操作失败时引发的异常。异常的用户信息字典将包含至少两个条目: @“nstargetobjectuserinfokey”:失败的KVC消息接收器。 @“nsunknownuserinfokey”:关键是用失败的KVC消息。 The actual value of this constant string is "NSUnknownKeyException," to match the exceptions that are thrown by KVC methods that were deprecated in Mac OS 10.3. 这个常量字符串的实际价值是“nsunknownkeyexception,”匹配的KVC方法是在Mac OS 10.3被抛出的异常。 */ FOUNDATION_EXPORT NSExceptionName const NSUndefinedKeyException; typedef NSString * NSKeyValueOperator NS_STRING_ENUM; /* Strings for the names of array operators supported by key-value coding. Only these string declarations are new in Mac OS 10.4. The actual support for array operators appeared in Mac OS 10.3. The values of these do not include "@" prefixes. 键值编码支持的数组运算符名称的字符串。只有这些字符串声明在Mac OS 10.4中是新的。对数组操作符的实际支持出现在Mac OS 10.3中。这些值不包括“@”前缀。 */ FOUNDATION_EXPORT NSKeyValueOperator const NSAverageKeyValueOperator; FOUNDATION_EXPORT NSKeyValueOperator const NSCountKeyValueOperator; FOUNDATION_EXPORT NSKeyValueOperator const NSDistinctUnionOfArraysKeyValueOperator; FOUNDATION_EXPORT NSKeyValueOperator const NSDistinctUnionOfObjectsKeyValueOperator; FOUNDATION_EXPORT NSKeyValueOperator const NSDistinctUnionOfSetsKeyValueOperator; FOUNDATION_EXPORT NSKeyValueOperator const NSMaximumKeyValueOperator; FOUNDATION_EXPORT NSKeyValueOperator const NSMinimumKeyValueOperator; FOUNDATION_EXPORT NSKeyValueOperator const NSSumKeyValueOperator; FOUNDATION_EXPORT NSKeyValueOperator const NSUnionOfArraysKeyValueOperator; FOUNDATION_EXPORT NSKeyValueOperator const NSUnionOfObjectsKeyValueOperator; FOUNDATION_EXPORT NSKeyValueOperator const NSUnionOfSetsKeyValueOperator; @interface NSObject(NSKeyValueCoding) /* Return YES if -valueForKey:, -setValue:forKey:, -mutableArrayValueForKey:, -storedValueForKey:, -takeStoredValue:forKey:, and -takeValue:forKey: may directly manipulate instance variables when sent to instances of the receiving class, NO otherwise. The default implementation of this property returns YES. 如果-valueForKey :, -setValue:forKey :, -mutableArrayValueForKey :, -storedValueForKey:,-takeStoredValue:forKey :,和-takeValue:forKey:可以在发送到接收类的实例时直接操作实例变量,否则返回YES。 此属性的默认实现返回YES。 */ @property (class, readonly) BOOL accessInstanceVariablesDirectly; /* Given a key that identifies an attribute or to-one relationship, return the attribute value or the related object. Given a key that identifies a to-many relationship, return an immutable array or an immutable set that contains all of the related objects. 给定一个标识属性或一对一关系的关键字,返回属性值或相关对象。 给定一个标识一对多关系的关键字,返回一个包含所有相关对象的不可变数组或不可变集合。 The default implementation of this method does the following: 此方法的默认实现执行以下操作: 1. Searches the class of the receiver for an accessor method whose name matches the pattern -get , - , or -is , in that order. If such a method is found it is invoked. If the type of the method's result is an object pointer type the result is simply returned. If the type of the result is one of the scalar types supported by NSNumber conversion is done and an NSNumber is returned. Otherwise, conversion is done and an NSValue is returned (new in Mac OS 10.5: results of arbitrary type are converted to NSValues, not just NSPoint, NRange, NSRect, and NSSize). 按照该顺序搜索名为与模式-get , - 或-is 匹配的访问方法的接收方类。 如果找到了这样的方法,就会调用它。 如果方法结果的类型是对象指针类型,则返回结果。 如果结果的类型是由NSNumber转换完成并支持NSNumber的标量类型之一。 否则,转换完成并返回一个NSValue(在Mac OS 10.5中新增:任意类型的结果将转换为NSValues,而不仅仅是NSPoint,NRange,NSRect和NSSize)。 2 (introduced in Mac OS 10.7). Otherwise (no simple accessor method is found), searches the class of the receiver for methods whose names match the patterns -countOf and -indexIn OfObject: and -objectIn AtIndex: (corresponding to the primitive methods defined by the NSOrderedSet class) and also - AtIndexes: (corresponding to -[NSOrderedSet objectsAtIndexes:]). If a count method and an indexOf method and at least one of the other two possible methods are found, a collection proxy object that responds to all NSOrderedSet methods is returned. Each NSOrderedSet message sent to the collection proxy object will result in some combination of -countOf , -indexIn OfObject:, -objectIn AtIndex:, and - AtIndexes: messages being sent to the original receiver of -valueForKey:. If the class of the receiver also implements an optional method whose name matches the pattern -get :range: that method will be used when appropriate for best performance. (在Mac OS 10.7中引入)。 否则(没有找到简单的访问器方法),在接收器的类中搜索名称与模式-countOf 和-indexIn OfObject:和-objectIn AtIndex:(对应于原始方法 由NSOrderedSet类定义)以及 - AtIndexes :(对应于 - [NSOrderedSet objectsAtIndexes:])。 如果找到一个count方法和一个indexOf方法以及其他两种可能方法中的至少一种,则会返回一个响应所有NSOrderedSet方法的集合代理对象。 发送到集合代理对象的每个NSOrderedSet消息将导致-countOf ,-indexIn OfObject :, -objectIn AtIndex :,和 - AtIndexes:将消息发送到原始 -valueForKey的接收者。 如果接收方的类也实现了一个可选方法,该方法的名称与模式-get :range匹配:在合适的时候会使用该方法以获得最佳性能。 3. Otherwise (no simple accessor method or set of ordered set access methods is found), searches the class of the receiver for methods whose names match the patterns -countOf and -objectIn AtIndex: (corresponding to the primitive methods defined by the NSArray class) and (introduced in Mac OS 10.4) also - AtIndexes: (corresponding to -[NSArray objectsAtIndexes:]). If a count method and at least one of the other two possible methods are found, a collection proxy object that responds to all NSArray methods is returned. Each NSArray message sent to the collection proxy object will result in some combination of -countOf , -objectIn AtIndex:, and - AtIndexes: messages being sent to the original receiver of -valueForKey:. If the class of the receiver also implements an optional method whose name matches the pattern -get :range: that method will be used when appropriate for best performance. 否则(没有找到简单的访问方法或一组有序集访问方法),在接收方的类中搜索名称与模式-countOf 和-objectIn AtIndex相匹配的方法:(对应于定义的基本方法 通过NSArray类)和(在Mac OS 10.4中引入)也是 - AtIndexes :(对应于 - [NSArray objectsAtIndexes:])。 如果找到一个计数方法和其他两种可能方法中的至少一种,则会返回一个响应所有NSArray方法的集合代理对象。 发送到集合代理对象的每个NSArray消息都将导致-countOf ,-objectIn AtIndex :,和 - AtIndexes:消息被发送到-valueForKey:的原始接收者。 如果接收方的类也实现了一个可选方法,该方法的名称与模式-get :range匹配:在合适的时候会使用该方法以获得最佳性能。 4 (introduced in Mac OS 10.4). Otherwise (no simple accessor method or set of ordered set or array access methods is found), searches the class of the receiver for a threesome of methods whose names match the patterns -countOf , -enumeratorOf , and -memberOf : (corresponding to the primitive methods defined by the NSSet class). If all three such methods are found a collection proxy object that responds to all NSSet methods is returned. Each NSSet message sent to the collection proxy object will result in some combination of -countOf , -enumeratorOf , and -memberOf : messages being sent to the original receiver of -valueForKey:. (在Mac OS 10.4中引入)。 否则(没有找到简单的访问方法或一组有序集或数组访问方法),搜索接收方的类以获得名称与模式-countOf ,-enumeratorOf 和-memberOf匹配的三个方法 :(对应于由NSSet类定义的原始方法)。 如果找到所有三种这样的方法,则返回响应所有NSSet方法的集合代理对象。 发送到集合代理对象的每个NSSet消息将导致-countOf ,-enumeratorOf 和-memberOf :消息被发送到-valueForKey:的原始接收者。 5. Otherwise (no simple accessor method or set of collection access methods is found), if the receiver's class' +accessInstanceVariablesDirectly property returns YES, searches the class of the receiver for an instance variable whose name matches the pattern _ , _is , , or is , in that order. If such an instance variable is found, the value of the instance variable in the receiver is returned, with the same sort of conversion to NSNumber or NSValue as in step 1. 否则(找不到简单的访问方法或集合访问方法集),如果接收方的类+ accessInstanceVariablesDirectly属性返回YES,则在接收方的类中搜索名称与模式_ 匹配的实例变量,_is , ,或者是 ,按照该顺序。 如果找到这样一个实例变量,则返回接收方中实例变量的值,并按照与步骤1中相同的NSNumber或NSValue转换。 6. Otherwise (no simple accessor method, set of collection access methods, or instance variable is found), invokes -valueForUndefinedKey: and returns the result. The default implementation of -valueForUndefinedKey: raises an NSUndefinedKeyException, but you can override it in your application. 否则(找不到简单的访问器方法,集合访问方法集或实例变量),调用-valueForUndefinedKey:并返回结果。 -valueForUndefinedKey的默认实现引发了NSUndefinedKeyException,但是您可以在应用程序中覆盖它。 Compatibility notes: - For backward binary compatibility, an accessor method whose name matches the pattern -_get , or -_ is searched for between steps 1 and 3. If such a method is found it is invoked, with the same sort of conversion to NSNumber or NSValue as in step 1. KVC accessor methods whose names start with underscores were deprecated as of Mac OS 10.3 though. - The behavior described in step 5 is a change from Mac OS 10.2, in which the instance variable search order was , _ . - For backward binary compatibility, -handleQueryWithUnboundKey: will be invoked instead of -valueForUndefinedKey: in step 6, if the implementation of -handleQueryWithUnboundKey: in the receiver's class is not NSObject's. 兼容性说明: - 对于后向二进制兼容性,在步骤1和步骤3之间搜索名称与模式-_get 或-_ 匹配的访问方法。如果找到该方法,则调用它,使用相同类型的 转换为NSNumber或NSValue,如步骤1中所述。从Mac OS 10.3开始,其名称以下划线开头的KVC访问器方法已被弃用。 - 步骤5中描述的行为是从Mac OS 10.2开始的一种变化,其中实例变量搜索顺序为 ,_ 。 - 对于后向二进制兼容性,将在步骤6中调用-handleQueryWithUnboundKey:而不是-valueForUndefinedKey:如果接收器类中的-handleQueryWithUnboundKey:的实现不是NSObject的。 */ - (nullable id)valueForKey:(NSString *)key; /* Given a value and a key that identifies an attribute, set the value of the attribute. Given an object and a key that identifies a to-one relationship, relate the object to the receiver, unrelating the previously related object if there was one. Given a collection object and a key that identifies a to-many relationship, relate the objects contained in the collection to the receiver, unrelating previously related objects if there were any. 给定一个标识属性的值和关键字,设置该属性的值。 给定一个对象和一个标识一对一关系的关键字,将对象与接收者关联起来,如果有对象,则不关联以前相关的对象。 给定一个集合对象和一个标识一对多关系的关键字,将集合中包含的对象与接收方关联起来,如果有关系的话,就不需要关联以前相关的对象。 The default implementation of this method does the following: 此方法的默认实现执行以下操作: 1. Searches the class of the receiver for an accessor method whose name matches the pattern -set :. If such a method is found the type of its parameter is checked. If the parameter type is not an object pointer type but the value is nil -setNilValueForKey: is invoked. The default implementation of -setNilValueForKey: raises an NSInvalidArgumentException, but you can override it in your application. Otherwise, if the type of the method's parameter is an object pointer type the method is simply invoked with the value as the argument. If the type of the method's parameter is some other type the inverse of the NSNumber/NSValue conversion done by -valueForKey: is performed before the method is invoked. 在接收方的类中搜索名称与模式-set :匹配的访问方法。 如果发现这种方法,则检查其参数的类型。 如果参数类型不是对象指针类型,但值是nil -setNilValueForKey:被调用。 -setNilValueForKey:的默认实现会引发NSInvalidArgumentException,但您可以在应用程序中覆盖它。 否则,如果方法参数的类型是对象指针类型,则只需使用该值作为参数来调用该方法。 如果方法参数的类型是某种其他类型,则在调用方法之前执行由-valueForKey:所完成的NSNumber / NSValue转换的反转。 2. Otherwise (no accessor method is found), if the receiver's class' +accessInstanceVariablesDirectly property returns YES, searches the class of the receiver for an instance variable whose name matches the pattern _ , _is , , or is , in that order. If such an instance variable is found and its type is an object pointer type the value is retained and the result is set in the instance variable, after the instance variable's old value is first released. If the instance variable's type is some other type its value is set after the same sort of conversion from NSNumber or NSValue as in step 1. 否则(找不到访问方法),如果接收方的类+ accessInstanceVariablesDirectly属性返回YES,则在接收方的类中搜索名称与模式_ ,_is , 匹配的实例变量或 是 ,依次。 如果找到这样一个实例变量并且它的类型是对象指针类型,那么在实例变量的旧值第一次释放后,该值将被保留并且结果将在实例变量中进行设置。 如果实例变量的类型是某种其他类型,则它的值在与步骤1中的NSNumber或NSValue类似的转换后进行设置。 3. Otherwise (no accessor method or instance variable is found), invokes -setValue:forUndefinedKey:. The default implementation of -setValue:forUndefinedKey: raises an NSUndefinedKeyException, but you can override it in your application. 否则(找不到访问方法或实例变量),调用-setValue:forUndefinedKey :. -setValue:forUndefinedKey的默认实现会引发NSUndefinedKeyException,但您可以在应用程序中覆盖它。 Compatibility notes: - For backward binary compatibility with -takeValue:forKey:'s behavior, a method whose name matches the pattern -_set : is also recognized in step 1. KVC accessor methods whose names start with underscores were deprecated as of Mac OS 10.3 though. - For backward binary compatibility, -unableToSetNilForKey: will be invoked instead of -setNilValueForKey: in step 1, if the implementation of -unableToSetNilForKey: in the receiver's class is not NSObject's. - The behavior described in step 2 is different from -takeValue:forKey:'s, in which the instance variable search order is , _ . - For backward binary compatibility with -takeValue:forKey:'s behavior, -handleTakeValue:forUnboundKey: will be invoked instead of -setValue:forUndefinedKey: in step 3, if the implementation of -handleTakeValue:forUnboundKey: in the receiver's class is not NSObject's. 兼容性说明: - 对于与-takeValue:forKey:的行为的后向二进制兼容性,名称与模式-_set :匹配的方法也会在步骤1中识别。从Mac OS 10.3开始,名称以下划线开头的KVC访问器方法已被弃用 虽然。 - 对于向后的二进制兼容性,如果接收者类中的-unableToSetNilForKey:的实现不是NSObject的,则在步骤1中调用-unableToSetNilForKey:而不是-setNilValueForKey:。 - 步骤2中描述的行为与-takeValue:forKey:不同,其中实例变量搜索顺序为 ,_ 。 - 为了向后兼容-takeValue:forKey:的行为,-handleTakeValue:forUnboundKey:将被调用,而不是-setValue:forUndefinedKey:在步骤3中,如果接收者类中的-handleTakeValue:forUnboundKey:的实现不是NSObject的。 */ - (void)setValue:(nullable id)value forKey:(NSString *)key; /* Given a pointer to a value pointer, a key that identifies an attribute or to-one relationship, and a pointer to an NSError pointer, return a value that is suitable for use in subsequent -setValue:forKey: messages sent to the same receiver. If no validation is necessary, return YES without altering *ioValue or *outError. If validation is necessary and possible, return YES after setting *ioValue to an object that is the validated version of the original value, but without altering *outError. If validation is necessary but not possible, return NO after setting *outError to an NSError that encapsulates the reason that validation was not possible, but without altering *ioValue. The sender of the message is never given responsibility for releasing ioValue or outError. 给定一个指向值指针的指针,一个标识一个属性或一对一关系的关键字,以及一个指向NSError指针的指针,返回一个适用于发送到同一个接收器的后续-setValue:forKey:消息的值。 如果不需要验证,则返回YES而不更改* ioValue或* outError。 如果验证是必要且可能的,则在将* ioValue设置为原始值的验证版本的对象后返回YES,但不会更改* outError。 如果需要验证但不可能,则在将* outError设置为封装验证不可行的原因的NSError之后返回NO,但不会更改* ioValue。 消息的发送者从未被赋予释放ioValue或outError的责任。 The default implementation of this method searches the class of the receiver for a validator method whose name matches the pattern -validate :error:. If such a method is found it is invoked and the result is returned. If no such method is found, YES is returned. 此方法的默认实现将在接收方的类中搜索名称与pattern -validate :error:匹配的验证方法。 如果发现这样的方法,则调用它并返回结果。 如果没有找到这样的方法,则返回YES。 */ - (BOOL)validateValue:(inout id _Nullable * _Nonnull)ioValue forKey:(NSString *)inKey error:(out NSError **)outError; /* Given a key that identifies an _ordered_ to-many relationship, return a mutable array that provides read-write access to the related objects. Objects added to the mutable array will become related to the receiver, and objects removed from the mutable array will become unrelated. 给定一个标识一个_ordered_对多关系的关键字,返回一个可变数组,它提供对相关对象的读写访问权限。 添加到可变数组的对象将与接收者相关,并且从可变数组中移除的对象将变得不相关。 The default implementation of this method recognizes the same simple accessor methods and array accessor methods as -valueForKey:'s, and follows the same direct instance variable access policies, but always returns a mutable collection proxy object instead of the immutable collection that -valueForKey: would return. It also: 此方法的默认实现可识别与-valueForKey:相同的简单访问方法和数组访问方法,并遵循相同的直接实例变量访问策略,但始终返回可变集合代理对象,而不是不可变集合,即-valueForKey: 会返回。 它也是: 1. Searches the class of the receiver for methods whose names match the patterns -insertObject:in AtIndex: and -removeObjectFrom AtIndex: (corresponding to the two most primitive methods defined by the NSMutableArray class), and (introduced in Mac OS 10.4) also -insert :atIndexes: and -remove AtIndexes: (corresponding to -[NSMutableArray insertObjects:atIndexes:] and -[NSMutableArray removeObjectsAtIndexes:). If at least one insertion method and at least one removal method are found each NSMutableArray message sent to the collection proxy object will result in some combination of -insertObject:in AtIndex:, -removeObjectFrom AtIndex:, -insert :atIndexes:, and -remove AtIndexes: messages being sent to the original receiver of -mutableArrayValueForKey:. If the class of the receiver also implements an optional method whose name matches the pattern -replaceObjectIn AtIndex:withObject: or (introduced in Mac OS 10.4) -replace AtIndexes:with : that method will be used when appropriate for best performance. 在接收者的类中搜索名称与模式-insertObject:in AtIndex:和-removeObjectFrom AtIndex:(对应于由NSMutableArray类定义的两个最原始的方法)中的模式的方法,以及(在Mac中引入的OS 10.4)-insert :atIndexes:和-remove AtIndexes :(对应于 - [NSMutableArray insertObjects:atIndexes:]和 - [NSMutableArray removeObjectsAtIndexes :)。如果发现至少有一个插入方法和至少一个删除方法,则每个发送到集合代理对象的NSMutableArray消息都将导致 AtIndex :, -removeObjectFrom AtIndex:,-insert < Key>:atIndexes:和-remove AtIndexes:将消息发送到-mutableArrayValueForKey:的原始接收者。如果接收者的类还实现了名称与模式-replaceObjectIn AtIndex:withObject:或(在Mac OS 10.4中引入)相匹配的可选方法 - 使用 替换 AtIndexes:将使用该方法适当时可获得最佳性能。 2. Otherwise (no set of array mutation methods is found), searches the class of the receiver for an accessor method whose name matches the pattern -set :. If such a method is found each NSMutableArray message sent to the collection proxy object will result in a -set : message being sent to the original receiver of -mutableArrayValueForKey:. 否则(没有找到一组数组变异方法),在接收者的类中搜索名称与模式-set :匹配的访问方法。 如果发现这样的方法,则每个发送到集合代理对象的NSMutableArray消息都将导致将-set :消息发送到-mutableArrayValueForKey:的原始接收者。 3. Otherwise (no set of array mutation methods or simple accessor method is found), if the receiver's class' +accessInstanceVariablesDirectly property returns YES, searches the class of the receiver for an instance variable whose name matches the pattern _ or , in that order. If such an instance variable is found, each NSMutableArray message sent to the collection proxy object will be forwarded to the instance variable's value, which therefore must typically be an instance of NSMutableArray or a subclass of NSMutableArray. 否则(没有找到一组数组变异方法或简单的访问器方法),如果接收者的类+ accessInstanceVariablesDirectly属性返回YES,则在接收者的类中搜索名称与模式_ 或 匹配的实例变量 , 以该顺序。 如果找到这样一个实例变量,则发送到集合代理对象的每个NSMutableArray消息都将被转发给实例变量的值,因此它通常必须是NSMutableArray的实例或NSMutableArray的子类。 4. Otherwise (no set of array mutation methods, simple accessor method, or instance variable is found), returns a mutable collection proxy object anyway. Each NSMutableArray message sent to the collection proxy object will result in a -setValue:forUndefinedKey: message being sent to the original receiver of -mutableArrayValueForKey:. The default implementation of -setValue:forUndefinedKey: raises an NSUndefinedKeyException, but you can override it in your application. 否则(找不到数组变量方法,简单访问器方法或实例变量),无论如何返回可变集合代理对象。 发送到集合代理对象的每个NSMutableArray消息将导致将-setValue:forUndefinedKey:消息发送到-mutableArrayValueForKey:的原始接收方。 -setValue:forUndefinedKey的默认实现会引发NSUndefinedKeyException,但您可以在应用程序中覆盖它。 Performance note: the repetitive -set : messages implied by step 2's description are a potential performance problem. For better performance implement insertion and removal methods that fulfill the requirements for step 1 in your KVC-compliant class. For best performance implement a replacement method too. 性能注意事项:步骤2描述中隐含的重复性设置 :消息是潜在的性能问题。 为了获得更好的性能,请执行插入和移除方法,以满足KVC兼容课程中步骤1的要求。 为获得最佳性能,也要实施替换方法。 */ - (NSMutableArray *)mutableArrayValueForKey:(NSString *)key; /* Given a key that identifies an _ordered_ and uniquing to-many relationship, return a mutable ordered set that provides read-write access to the related objects. Objects added to the mutable ordered set will become related to the receiver, and objects removed from the mutable ordered set will become unrelated. 给定一个标识_ordered_和uniquing对多关系的关键字,返回一个可变的有序集合,它提供对相关对象的读写访问权限。 添加到可变顺序集中的对象将与接收方相关,并且从可变顺序集中移除的对象将变得不相关。 The default implementation of this method recognizes the same simple accessor methods and ordered set accessor methods as -valueForKey:'s, and follows the same direct instance variable access policies, but always returns a mutable collection proxy object instead of the immutable collection that -valueForKey: would return. It also: 此方法的默认实现可识别与-valueForKey:相同的简单访问方法和有序集访问方法,并遵循相同的直接实例变量访问策略,但始终返回可变集合代理对象,而不是不可变集合--valueForKey :会返回。 它也是: 1. Searches the class of the receiver for methods whose names match the patterns -insertObject:in AtIndex: and -removeObjectFrom AtIndex: (corresponding to the two most primitive methods defined by the NSMutableOrderedSet class), and also -insert :atIndexes: and -remove AtIndexes: (corresponding to -[NSMutableOrderedSet insertObjects:atIndexes:] and -[NSMutableOrderedSet removeObjectsAtIndexes:). If at least one insertion method and at least one removal method are found each NSMutableOrderedSet message sent to the collection proxy object will result in some combination of -insertObject:in AtIndex:, -removeObjectFrom AtIndex:, -insert :atIndexes:, and -remove AtIndexes: messages being sent to the original receiver of -mutableOrderedSetValueForKey:. If the class of the receiver also implements an optional method whose name matches the pattern -replaceObjectIn AtIndex:withObject: or -replace AtIndexes:with : that method will be used when appropriate for best performance. 在接收者的类中搜索名称与模式-insertObject:in AtIndex:和-removeObjectFrom AtIndex:(对应于由NSMutableOrderedSet类定义的两个最原始的方法)中的模式名称相同的方法,以及-insert < Key>:atIndexes:和-remove AtIndexes :(对应于 - [NSMutableOrderedSet insertObjects:atIndexes:]和 - [NSMutableOrderedSet removeObjectsAtIndexes :)。如果找到至少一个插入方法和至少一个删除方法,则每个发送到集合代理对象的NSMutableOrderedSet消息都将导致 AtIndex :, -removeObjectFrom AtIndex:,-insert < Key>:atIndexes:和-remove AtIndexes:将消息发送到-mutableOrderedSetValueForKey:的原始接收者。如果接收方的类还实现了名称与模式-replaceObjectIn AtIndex:withObject:或-replace AtIndexes:with 相匹配的可选方法:那么将在合适时使用该方法以获得最佳性能。 2. Otherwise (no set of ordered set mutation methods is found), searches the class of the receiver for an accessor method whose name matches the pattern -set :. If such a method is found each NSMutableOrderedSet message sent to the collection proxy object will result in a -set : message being sent to the original receiver of -mutableOrderedSetValueForKey:. 否则(没有找到有序集合变异方法的集合),搜索接收者的类来寻找名称与模式-set :匹配的访问方法。 如果发现这样的方法,则每个发送到集合代理对象的NSMutableOrderedSet消息都将导致将-set :消息发送到-mutableOrderedSetValueForKey:的原始接收者。 3. Otherwise (no set of ordered set mutation methods or simple accessor method is found), if the receiver's class' +accessInstanceVariablesDirectly property returns YES, searches the class of the receiver for an instance variable whose name matches the pattern _ or , in that order. If such an instance variable is found, each NSMutableOrderedSet message sent to the collection proxy object will be forwarded to the instance variable's value, which therefore must typically be an instance of NSMutableOrderedSet or a subclass of NSMutableOrderedSet. 否则(找不到有序集合变异方法或简单存取方法集合),如果接收者的类+ accessInstanceVariablesDirectly属性返回YES,则在接收者的类中搜索名称与模式_ 或 ,按顺序。 如果找到这样一个实例变量,则发送到集合代理对象的每个NSMutableOrderedSet消息都将被转发给实例变量的值,因此它通常必须是NSMutableOrderedSet的实例或NSMutableOrderedSet的子类。 4. Otherwise (no set of ordered set mutation methods, simple accessor method, or instance variable is found), returns a mutable collection proxy object anyway. Each NSMutableOrderedSet message sent to the collection proxy object will result in a -setValue:forUndefinedKey: message being sent to the original receiver of -mutableOrderedSetValueForKey:. The default implementation of -setValue:forUndefinedKey: raises an NSUndefinedKeyException, but you can override it in your application. 否则(找不到有序集变异方法集,简单访问器方法或实例变量),总之返回一个可变集合代理对象。 发送到集合代理对象的每个NSMutableOrderedSet消息将导致将-setValue:forUndefinedKey:消息发送到-mutableOrderedSetValueForKey:的原始接收者。 -setValue:forUndefinedKey的默认实现会引发NSUndefinedKeyException,但您可以在应用程序中覆盖它。 Performance note: the repetitive -set : messages implied by step 2's description are a potential performance problem. For better performance implement insertion and removal methods that fulfill the requirements for step 1 in your KVC-compliant class. For best performance implement a replacement method too. 性能注意事项:步骤2描述中隐含的重复性设置 :消息是潜在的性能问题。 为了获得更好的性能,请执行插入和移除方法,以满足KVC兼容课程中步骤1的要求。 为获得最佳性能,也要实施替换方法。 */ - (NSMutableOrderedSet *)mutableOrderedSetValueForKey:(NSString *)key API_AVAILABLE(macos(10.7), ios(5.0), watchos(2.0), tvos(9.0)); /* Given a key that identifies an _unordered_ and uniquing to-many relationship, return a mutable set that provides read-write access to the related objects. Objects added to the mutable set will become related to the receiver, and objects removed from the mutable set will become unrelated. 给定一个标识_unordered_和uniquing to-many关系的关键字,返回一个可变集合,它提供对相关对象的读写访问权限。 添加到可变集合中的对象将与接收器相关,并且从可变集合中移除的对象将变得不相关。 The default implementation of this method recognizes the same simple accessor methods and set accessor methods as -valueForKey:'s, and follows the same direct instance variable access policies, but always returns a mutable collection proxy object instead of the immutable collection that -valueForKey: would return. It also: 此方法的默认实现识别相同的简单访问方法并将访问方法设置为-valueForKey:,并遵循相同的直接实例变量访问策略,但始终返回可变集合代理对象,而不是不可变集合--valueForKey: 会返回。 它也是: 1. Searches the class of the receiver for methods whose names match the patterns -add Object: and -remove Object: (corresponding to the two primitive methods defined by the NSMutableSet class) and also -add : and -remove : (corresponding to -[NSMutableSet unionSet:] and -[NSMutableSet minusSet:]). If at least one addition method and at least one removal method are found each NSMutableSet message sent to the collection proxy object will result in some combination of -add Object:, -remove Object:, -add :, and -remove : messages being sent to the original receiver of -mutableSetValueForKey:. If the class of the receiver also implements an optional method whose name matches the pattern -intersect : or -set : that method will be used when appropriate for best performance. 在接收者的类中搜索名称与模式-add Object:和-remove Object :(与由NSMutableSet类定义的两个原始方法相对应)以及-add 的方法:和 -remove :(对应于 - [NSMutableSet unionSet:]和 - [NSMutableSet minusSet:])。 如果找到至少一个添加方法和至少一个删除方法,则每个发送到集合代理对象的NSMutableSet消息都将导致-add Object :, -remove Object :, -add :和-remove :发送到-mutableSetValueForKey:的原始接收者的消息。 如果接收方的类也实现了一个可选方法,该方法的名称与模式-intersect :或-set 匹配:在合适的时候会使用该方法以获得最佳性能。 2. Otherwise (no set of set mutation methods is found), searches the class of the receiver for an accessor method whose name matches the pattern -set :. If such a method is found each NSMutableSet message sent to the collection proxy object will result in a -set : message being sent to the original receiver of -mutableSetValueForKey:. 否则(找不到一套设置的变异方法),在接收者的类中搜索名称与模式-set :匹配的访问方法。 如果发现这样的方法,则每个发送到集合代理对象的NSMutableSet消息都将导致将-set :消息发送到-mutableSetValueForKey:的原始接收方。 3. Otherwise (no set of set mutation methods or simple accessor method is found), if the receiver's class' +accessInstanceVariablesDirectly property returns YES, searches the class of the receiver for an instance variable whose name matches the pattern _ or , in that order. If such an instance variable is found, each NSMutableSet message sent to the collection proxy object will be forwarded to the instance variable's value, which therefore must typically be an instance of NSMutableSet or a subclass of NSMutableSet. 否则(没有找到设置的变异方法或简单的访问器方法),如果接收者的类+ accessInstanceVariablesDirectly属性返回YES,则在接收者的类中搜索名称与模式_ 或 匹配的实例变量 , 以该顺序。 如果找到这样的实例变量,则发送到集合代理对象的每个NSMutableSet消息都将被转发给实例变量的值,因此该值通常必须是NSMutableSet的实例或NSMutableSet的子类。 4. Otherwise (no set of set mutation methods, simple accessor method, or instance variable is found), returns a mutable collection proxy object anyway. Each NSMutableSet message sent to the collection proxy object will result in a -setValue:forUndefinedKey: message being sent to the original receiver of -mutableSetValueForKey:. The default implementation of -setValue:forUndefinedKey: raises an NSUndefinedKeyException, but you can override it in your application. 否则(找不到任何集合变异方法,简单访问器方法或实例变量),无论如何返回可变集合代理对象。 发送到集合代理对象的每个NSMutableSet消息将导致将-setValue:forUndefinedKey:消息发送到-mutableSetValueForKey:的原始接收方。 -setValue:forUndefinedKey的默认实现会引发NSUndefinedKeyException,但您可以在应用程序中覆盖它。 Performance note: the repetitive -set : messages implied by step 2's description are a potential performance problem. For better performance implement methods that fulfill the requirements for step 1 in your KVC-compliant class. 性能注意事项:步骤2描述中隐含的重复性设置 :消息是潜在的性能问题。 为了获得更好的性能,请实现符合KVC兼容课程中步骤1要求的方法。 */ - (NSMutableSet *)mutableSetValueForKey:(NSString *)key; /* Key-path-taking variants of like-named methods. The default implementation of each parses the key path enough to determine whether or not it has more than one component (key path components are separated by periods). If so, -valueForKey: is invoked with the first key path component as the argument, and the method being invoked is invoked recursively on the result, with the remainder of the key path passed as an argument. If not, the like-named non-key-path-taking method is invoked. 类似命名方法的关键路径变体。 它们的默认实现分析足够的关键路径以确定它是否包含多个组件(关键路径组件由句点分隔)。 如果是这样,则使用第一个键路径组件作为参数调用-valueForKey:,并且对结果递归调用正在调用的方法,并将其余的键路径作为参数进行传递。 如果不是,则调用类似名称的非键路径获取方法。 */ - (nullable id)valueForKeyPath:(NSString *)keyPath; - (void)setValue:(nullable id)value forKeyPath:(NSString *)keyPath; - (BOOL)validateValue:(inout id _Nullable * _Nonnull)ioValue forKeyPath:(NSString *)inKeyPath error:(out NSError **)outError; - (NSMutableArray *)mutableArrayValueForKeyPath:(NSString *)keyPath; - (NSMutableOrderedSet *)mutableOrderedSetValueForKeyPath:(NSString *)keyPath API_AVAILABLE(macos(10.7), ios(5.0), watchos(2.0), tvos(9.0)); - (NSMutableSet *)mutableSetValueForKeyPath:(NSString *)keyPath; /* Given that an invocation of -valueForKey: would be unable to get a keyed value using its default access mechanism, return the keyed value using some other mechanism. The default implementation of this method raises an NSUndefinedKeyException. You can override it to handle properties that are dynamically defined at run-time. 鉴于-valueForKey:的调用将无法使用其默认访问机制获取键控值,请使用其他机制返回键控值。 此方法的默认实现会引发NSUndefinedKeyException。 您可以覆盖它以处理在运行时动态定义的属性。 */ - (nullable id)valueForUndefinedKey:(NSString *)key; /* Given that an invocation of -setValue:forKey: would be unable to set the keyed value using its default mechanism, set the keyed value using some other mechanism. The default implementation of this method raises an NSUndefinedKeyException. You can override it to handle properties that are dynamically defined at run-time. 鉴于-setValue:forKey:的调用将无法使用其默认机制来设置键控值,请使用其他一些机制来设置键控值。 此方法的默认实现会引发NSUndefinedKeyException。 您可以覆盖它以处理在运行时动态定义的属性。 */ - (void)setValue:(nullable id)value forUndefinedKey:(NSString *)key; /* Given that an invocation of -setValue:forKey: would be unable to set the keyed value because the type of the parameter of the corresponding accessor method is an NSNumber scalar type or NSValue structure type but the value is nil, set the keyed value using some other mechanism. The default implementation of this method raises an NSInvalidArgumentException. You can override it to map nil values to something meaningful in the context of your application. 鉴于-setValue:forKey:的调用将无法设置键控值,因为相应访问器方法的参数类型是NSNumber标量类型或NSValue结构类型,但值为零,请使用某些键设置键值 其他机制。 此方法的默认实现引发NSInvalidArgumentException。 您可以覆盖它以将零值映射到应用程序上下文中有意义的内容。 */ - (void)setNilValueForKey:(NSString *)key; /* Given an array of keys, return a dictionary containing the keyed attribute values, to-one-related objects, and/or collections of to-many-related objects. Entries for which -valueForKey: returns nil have NSNull as their value in the returned dictionary. 给定一个键数组,返回一个包含键控属性值,一对一关联对象和/或多对象相关对象集合的字典。 -valueForKey:返回nil的条目在返回的字典中具有NSNull作为它们的值。 */ - (NSDictionary *)dictionaryWithValuesForKeys:(NSArray *)keys; /* Given a dictionary containing keyed attribute values, to-one-related objects, and/or collections of to-many-related objects, set the keyed values. Dictionary entries whose values are NSNull result in -setValue:nil forKey:key messages being sent to the receiver. 给定一个包含键控属性值,一对一关联对象和/或多对象相关对象集合的字典,设置键控值。 值为NSNull的字典条目导致-setValue:nil forKey:键消息被发送到接收方。 */ - (void)setValuesForKeysWithDictionary:(NSDictionary *)keyedValues; @end @interface NSArray (NSKeyValueCoding) /* Return an array containing the results of invoking -valueForKey: on each of the receiver's elements. The returned array will contain NSNull elements for each instance of -valueForKey: returning nil. 在每个接收者的元素上返回一个包含调用-valueForKey:的结果的数组。 返回的数组将包含-valueForKey的每个实例的NSNull元素:返回nil。 */ - (id)valueForKey:(NSString *)key; /* Invoke -setValue:forKey: on each of the receiver's elements. */ - (void)setValue:(nullable id)value forKey:(NSString *)key; @end @interface NSDictionary (NSKeyValueCoding) /* Return the result of sending -objectForKey: to the receiver. */ - (nullable ObjectType)valueForKey:(NSString *)key; @end @interface NSMutableDictionary (NSKeyValueCoding) /* Send -setObject:forKey: to the receiver, unless the value is nil, in which case send -removeObjectForKey:. */ - (void)setValue:(nullable ObjectType)value forKey:(NSString *)key; @end @interface NSOrderedSet (NSKeyValueCoding) /* Return an ordered set containing the results of invoking -valueForKey: on each of the receiver's members. The returned ordered set might not have the same number of members as the receiver. The returned ordered set will not contain any elements corresponding to instances of -valueForKey: returning nil, nor will it contain duplicates. 返回包含每个接收者成员调用-valueForKey:的结果的有序集合。 返回的有序集可能与接收方的成员数不相同。 返回的有序集不包含任何对应于-valueForKey实例的元素:返回nil,也不包含重复项。 */ - (id)valueForKey:(NSString *)key API_AVAILABLE(macos(10.7), ios(5.0), watchos(2.0), tvos(9.0)); /* Invoke -setValue:forKey: on each of the receiver's members. */ - (void)setValue:(nullable id)value forKey:(NSString *)key API_AVAILABLE(macos(10.7), ios(5.0), watchos(2.0), tvos(9.0)); @end @interface NSSet (NSKeyValueCoding) /* Return a set containing the results of invoking -valueForKey: on each of the receiver's members. The returned set might not have the same number of members as the receiver. The returned set will not contain any elements corresponding to instances of -valueForKey: returning nil (in contrast with -[NSArray(NSKeyValueCoding) valueForKey:], which may put NSNulls in the arrays it returns). 返回包含调用-valueForKey:在每个接收者成员上的结果的集合。 返回的集合可能没有与接收方相同的成员数量。 返回的集合将不包含任何对应于-valueForKey实例的元素:返回nil(与 - NSArray(NSKeyValueCoding)valueForKey:]相反,这可能会将NSNull放入返回的数组中)。 */ - (id)valueForKey:(NSString *)key; /* Invoke -setValue:forKey: on each of the receiver's members. */ - (void)setValue:(nullable id)value forKey:(NSString *)key; @end #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) @interface NSObject(NSDeprecatedKeyValueCoding) /* Methods that were deprecated in Mac OS 10.4. */ + (BOOL)useStoredAccessor API_DEPRECATED("Legacy KVC API", macos(10.0,10.4), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0)); - (nullable id)storedValueForKey:(NSString *)key API_DEPRECATED("Legacy KVC API", macos(10.0,10.4), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0)); - (void)takeStoredValue:(nullable id)value forKey:(NSString *)key API_DEPRECATED("Legacy KVC API", macos(10.0,10.4), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0)); /* Methods that were deprecated in Mac OS 10.3. Use the new, more consistently named, methods declared above instead. 在Mac OS 10.3中不推荐使用的方法。 使用上面声明的新的更一致命名的方法。 */ - (void)takeValue:(nullable id)value forKey:(NSString *)key API_DEPRECATED("Legacy KVC API", macos(10.0,10.3), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0)); - (void)takeValue:(nullable id)value forKeyPath:(NSString *)keyPath API_DEPRECATED("Legacy KVC API", macos(10.0,10.3), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0)); - (nullable id)handleQueryWithUnboundKey:(NSString *)key API_DEPRECATED("Legacy KVC API", macos(10.0,10.3), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0)); - (void)handleTakeValue:(nullable id)value forUnboundKey:(NSString *)key API_DEPRECATED("Legacy KVC API", macos(10.0,10.3), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0)); - (void)unableToSetNilForKey:(NSString *)key API_DEPRECATED("Legacy KVC API", macos(10.0,10.3), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0)); - (NSDictionary *)valuesForKeys:(NSArray *)keys API_DEPRECATED("Legacy KVC API", macos(10.0,10.3), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0)); - (void)takeValuesFromDictionary:(NSDictionary *)properties API_DEPRECATED("Legacy KVC API", macos(10.0,10.3), ios(2.0,2.0), watchos(2.0,2.0), tvos(9.0,9.0)); @end #endif NS_ASSUME_NONNULL_END