-
源碼加翻譯
#import <Foundation/NSArray.h> #import <Foundation/NSDictionary.h> #import <Foundation/NSOrderedSet.h> #import <Foundation/NSSet.h> #import <Foundation/NSException.h> @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<Key>, -<key>, or -is<Key>, 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 <Key>, - <key>或-is <Key>匹配的訪問方法的接收方類。 如果找到了這樣的方法,就會調用它。 如果方法結果的類型是對象指針類型,則返回結果。 如果結果的類型是由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<Key> and -indexIn<Key>OfObject: and -objectIn<Key>AtIndex: (corresponding to the primitive methods defined by the NSOrderedSet class) and also -<key>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<Key>, -indexIn<Key>OfObject:, -objectIn<Key>AtIndex:, and -<key>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<Key>:range: that method will be used when appropriate for best performance. (在Mac OS 10.7中引入)。 否則(沒有找到簡單的訪問器方法),在接收器的類中搜索名稱與模式-countOf <Key>和-indexIn <Key> OfObject:和-objectIn <Key> AtIndex:(對應于原始方法 由NSOrderedSet類定義)以及 - <key> AtIndexes :(對應于 - [NSOrderedSet objectsAtIndexes:])。 如果找到一個count方法和一個indexOf方法以及其他兩種可能方法中的至少一種,則會返回一個響應所有NSOrderedSet方法的集合代理對象。 發送到集合代理對象的每個NSOrderedSet消息將導致-countOf <Key>,-indexIn <Key> OfObject :, -objectIn <Key> AtIndex :,和 - <key> AtIndexes:將消息發送到原始 -valueForKey的接收者。 如果接收方的類也實現了一個可選方法,該方法的名稱與模式-get <Key>: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<Key> and -objectIn<Key>AtIndex: (corresponding to the primitive methods defined by the NSArray class) and (introduced in Mac OS 10.4) also -<key>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<Key>, -objectIn<Key>AtIndex:, and -<key>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<Key>:range: that method will be used when appropriate for best performance. 否則(沒有找到簡單的訪問方法或一組有序集訪問方法),在接收方的類中搜索名稱與模式-countOf <Key>和-objectIn <Key> AtIndex相匹配的方法:(對應于定義的基本方法 通過NSArray類)和(在Mac OS 10.4中引入)也是 - <key> AtIndexes :(對應于 - [NSArray objectsAtIndexes:])。 如果找到一個計數方法和其他兩種可能方法中的至少一種,則會返回一個響應所有NSArray方法的集合代理對象。 發送到集合代理對象的每個NSArray消息都將導致-countOf <Key>,-objectIn <Key> AtIndex :,和 - <key> AtIndexes:消息被發送到-valueForKey:的原始接收者。 如果接收方的類也實現了一個可選方法,該方法的名稱與模式-get <Key>: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<Key>, -enumeratorOf<Key>, and -memberOf<Key>: (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<Key>, -enumeratorOf<Key>, and -memberOf<Key>: messages being sent to the original receiver of -valueForKey:. (在Mac OS 10.4中引入)。 否則(沒有找到簡單的訪問方法或一組有序集或數組訪問方法),搜索接收方的類以獲得名稱與模式-countOf <Key>,-enumeratorOf <Key>和-memberOf匹配的三個方法 <Key> :(對應于由NSSet類定義的原始方法)。 如果找到所有三種這樣的方法,則返回響應所有NSSet方法的集合代理對象。 發送到集合代理對象的每個NSSet消息將導致-countOf <Key>,-enumeratorOf <Key>和-memberOf <Key>:消息被發送到-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 _<key>, _is<Key>, <key>, or is<Key>, 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,則在接收方的類中搜索名稱與模式_ <key>匹配的實例變量,_is <Key >,<key>,或者是<Key>,按照該順序。 如果找到這樣一個實例變量,則返回接收方中實例變量的值,并按照與步驟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<Key>, or -_<key> 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 <key>, _<key>. - 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 <Key>或-_ <key>匹配的訪問方法。如果找到該方法,則調用它,使用相同類型的 轉換為NSNumber或NSValue,如步驟1中所述。從Mac OS 10.3開始,其名稱以下劃線開頭的KVC訪問器方法已被棄用。 - 步驟5中描述的行為是從Mac OS 10.2開始的一種變化,其中實例變量搜索順序為<key>,_ <key>。 - 對于后向二進制兼容性,將在步驟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<Key>:. 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 <Key>:匹配的訪問方法。 如果發現這種方法,則檢查其參數的類型。 如果參數類型不是對象指針類型,但值是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 _<key>, _is<Key>, <key>, or is<Key>, 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,則在接收方的類中搜索名稱與模式_ <key>,_is <Key>,<key>匹配的實例變量或 是<Key>,依次。 如果找到這樣一個實例變量并且它的類型是對象指針類型,那么在實例變量的舊值第一次釋放后,該值將被保留并且結果將在實例變量中進行設置。 如果實例變量的類型是某種其他類型,則它的值在與步驟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<Key>: 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 <key>, _<key>. - 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 <Key>:匹配的方法也會在步驟1中識別。從Mac OS 10.3開始,名稱以下劃線開頭的KVC訪問器方法已被棄用 雖然。 - 對于向后的二進制兼容性,如果接收者類中的-unableToSetNilForKey:的實現不是NSObject的,則在步驟1中調用-unableToSetNilForKey:而不是-setNilValueForKey:。 - 步驟2中描述的行為與-takeValue:forKey:不同,其中實例變量搜索順序為<key>,_ <key>。 - 為了向后兼容-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<Key>: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 <Key>: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<Key>AtIndex: and -removeObjectFrom<Key>AtIndex: (corresponding to the two most primitive methods defined by the NSMutableArray class), and (introduced in Mac OS 10.4) also -insert<Key>:atIndexes: and -remove<Key>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<Key>AtIndex:, -removeObjectFrom<Key>AtIndex:, -insert<Key>:atIndexes:, and -remove<Key>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<Key>AtIndex:withObject: or (introduced in Mac OS 10.4) -replace<Key>AtIndexes:with<Key>: that method will be used when appropriate for best performance. 在接收者的類中搜索名稱與模式-insertObject:in <Key> AtIndex:和-removeObjectFrom <Key> AtIndex:(對應于由NSMutableArray類定義的兩個最原始的方法)中的模式的方法,以及(在Mac中引入的OS 10.4)-insert <Key>:atIndexes:和-remove <Key> AtIndexes :(對應于 - [NSMutableArray insertObjects:atIndexes:]和 - [NSMutableArray removeObjectsAtIndexes :)。如果發現至少有一個插入方法和至少一個刪除方法,則每個發送到集合代理對象的NSMutableArray消息都將導致<Key> AtIndex :, -removeObjectFrom <Key> AtIndex:,-insert < Key>:atIndexes:和-remove <Key> AtIndexes:將消息發送到-mutableArrayValueForKey:的原始接收者。如果接收者的類還實現了名稱與模式-replaceObjectIn <Key> AtIndex:withObject:或(在Mac OS 10.4中引入)相匹配的可選方法 - 使用<Key>替換<Key> 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<Key>:. If such a method is found each NSMutableArray message sent to the collection proxy object will result in a -set<Key>: message being sent to the original receiver of -mutableArrayValueForKey:. 否則(沒有找到一組數組變異方法),在接收者的類中搜索名稱與模式-set <Key>:匹配的訪問方法。 如果發現這樣的方法,則每個發送到集合代理對象的NSMutableArray消息都將導致將-set <Key>:消息發送到-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 _<key> or <key>, 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,則在接收者的類中搜索名稱與模式_ <key>或<key>匹配的實例變量 , 以該順序。 如果找到這樣一個實例變量,則發送到集合代理對象的每個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<Key>: 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描述中隱含的重復性設置<Key>:消息是潛在的性能問題。 為了獲得更好的性能,請執行插入和移除方法,以滿足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<Key>AtIndex: and -removeObjectFrom<Key>AtIndex: (corresponding to the two most primitive methods defined by the NSMutableOrderedSet class), and also -insert<Key>:atIndexes: and -remove<Key>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<Key>AtIndex:, -removeObjectFrom<Key>AtIndex:, -insert<Key>:atIndexes:, and -remove<Key>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<Key>AtIndex:withObject: or -replace<Key>AtIndexes:with<Key>: that method will be used when appropriate for best performance. 在接收者的類中搜索名稱與模式-insertObject:in <Key> AtIndex:和-removeObjectFrom <Key> AtIndex:(對應于由NSMutableOrderedSet類定義的兩個最原始的方法)中的模式名稱相同的方法,以及-insert < Key>:atIndexes:和-remove <Key> AtIndexes :(對應于 - [NSMutableOrderedSet insertObjects:atIndexes:]和 - [NSMutableOrderedSet removeObjectsAtIndexes :)。如果找到至少一個插入方法和至少一個刪除方法,則每個發送到集合代理對象的NSMutableOrderedSet消息都將導致<Key> AtIndex :, -removeObjectFrom <Key> AtIndex:,-insert < Key>:atIndexes:和-remove <Key> AtIndexes:將消息發送到-mutableOrderedSetValueForKey:的原始接收者。如果接收方的類還實現了名稱與模式-replaceObjectIn <Key> AtIndex:withObject:或-replace <Key> AtIndexes:with <Key>相匹配的可選方法:那么將在合適時使用該方法以獲得最佳性能。 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<Key>:. If such a method is found each NSMutableOrderedSet message sent to the collection proxy object will result in a -set<Key>: message being sent to the original receiver of -mutableOrderedSetValueForKey:. 否則(沒有找到有序集合變異方法的集合),搜索接收者的類來尋找名稱與模式-set <Key>:匹配的訪問方法。 如果發現這樣的方法,則每個發送到集合代理對象的NSMutableOrderedSet消息都將導致將-set <Key>:消息發送到-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 _<key> or <key>, 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,則在接收者的類中搜索名稱與模式_ <key>或<key匹配的實例變量 >,按順序。 如果找到這樣一個實例變量,則發送到集合代理對象的每個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<Key>: 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描述中隱含的重復性設置<Key>:消息是潛在的性能問題。 為了獲得更好的性能,請執行插入和移除方法,以滿足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<Key>Object: and -remove<Key>Object: (corresponding to the two primitive methods defined by the NSMutableSet class) and also -add<Key>: and -remove<Key>: (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<Key>Object:, -remove<Key>Object:, -add<Key>:, and -remove<Key>: 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<Key>: or -set<Key>: that method will be used when appropriate for best performance. 在接收者的類中搜索名稱與模式-add <Key> Object:和-remove <Key> Object :(與由NSMutableSet類定義的兩個原始方法相對應)以及-add <Key>的方法:和 -remove <Key> :(對應于 - [NSMutableSet unionSet:]和 - [NSMutableSet minusSet:])。 如果找到至少一個添加方法和至少一個刪除方法,則每個發送到集合代理對象的NSMutableSet消息都將導致-add <Key> Object :, -remove <Key> Object :, -add <Key> :和-remove <Key>:發送到-mutableSetValueForKey:的原始接收者的消息。 如果接收方的類也實現了一個可選方法,該方法的名稱與模式-intersect <Key>:或-set <Key>匹配:在合適的時候會使用該方法以獲得最佳性能。 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<Key>:. If such a method is found each NSMutableSet message sent to the collection proxy object will result in a -set<Key>: message being sent to the original receiver of -mutableSetValueForKey:. 否則(找不到一套設置的變異方法),在接收者的類中搜索名稱與模式-set <Key>:匹配的訪問方法。 如果發現這樣的方法,則每個發送到集合代理對象的NSMutableSet消息都將導致將-set <Key>:消息發送到-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 _<key> or <key>, 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,則在接收者的類中搜索名稱與模式_ <key>或<key>匹配的實例變量 , 以該順序。 如果找到這樣的實例變量,則發送到集合代理對象的每個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<Key>: 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描述中隱含的重復性設置<Key>:消息是潛在的性能問題。 為了獲得更好的性能,請實現符合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<NSString *, id> *)dictionaryWithValuesForKeys:(NSArray<NSString *> *)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<NSString *, id> *)keyedValues; @end @interface NSArray<ObjectType>(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<KeyType, ObjectType>(NSKeyValueCoding) /* Return the result of sending -objectForKey: to the receiver. */ - (nullable ObjectType)valueForKey:(NSString *)key; @end @interface NSMutableDictionary<KeyType, ObjectType>(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<ObjectType>(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<ObjectType>(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
NSKeyValueCoding

CAICAI0IP屬地: 北京
1字數 10,429
©著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
50人點贊

CAICAI0iOS開發,喜歡各種技術。<br><a href="https://github.com/ca...
總資產121共写了3.7W字获得2,720个赞共11个粉丝
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...