• KVO与KVC整理资料


    KVC/KVO

    第wangzz 第http://blog.csdn.net/wzzvictory/article/details/9674431 到⽣生增⼿手wangzzstrive 增等

    第 1你KVC/KVO增看真以 ⾏行 2KVO增对KVC增KVC ⾏行

    KVC/KVO中种开就增Cocoa微NSObject NSKeyValueCoding/NSKeyValueObserving就样就 ⾏行样增KVC/KVO 主⾏行 增KVC/KVOObjective-C⼤大runtime增 只⾏行 ⼼心增KVC/KVO⽽而家增学⾏行

    1KVC
    Key-value coding增全之得⾏行增时map

    经活⾏行⼒力觉⽽而家⽽而两
    ⾏行
    

    2KVO
    Key-value observing增全之得中种⾏行

    还的⾏行MVCCocoa增KVO

    ⾃自modelcontroller⾏行

    KVC

    1KeyKey Path

    KVC⽽而增⽽而第 [java] view plaincopy

    1. #$(id)valueForKey:(NSString$*)key;$$
    2. #$(void)setValue:(id)value$forKey:(NSString$*)key;$$
    3. #$(id)valueForKeyPath:(NSString$*)keyPath;$$
    4. #$(void)setValue:(id)value$forKeyPath:(NSString$*)keyPath;$$

    Key增⽽而⼒力觉⾏行 KeyPath给⼒力动⽽而在 ⼒力觉情⾏行KeyPath address.street⽽而是⽆无 address⽆无street⾏行KeyPath 给⽽而时⼈人⼒力觉⾏行

    2KVC

    ⽽而家增来KVC⽽而增 ⾏行⽽而增来增KVC ⾏行明第KVC⽽而得⾏行 3To-Many 明To-One,Person name增⾏行增Person friendsName增⼦子明Objective-CNSArray增NSSet 增说⾏行 给增第

    有KVC⼦子增⼦子给⼦子⾏行

    开发增后⼀一就
    
    ⽽而⼦子不⾏行
    

    情⼦子第

    [java] view plaincopy

    1. #countOf<Key>$$

    2. //NSArraycount:$$

    3. #objectIn<Key>AtIndex:$$

    4. #<key>AtIndexes:$$

    5. //$NSArray$

      $objectAtIndex:$$objectsAtIndexes:$$

    6. #get<Key>:range:$$

    7. //$NSArray$ $getObjects:range:$$

    8. $$

    9. #insertObject:in<Key>AtIndex:$$

    10. #insert<Key>:atIndexes:$$

    11. //$NSMutableArray$

      $insertObject:atIndex:$$insertObjects:atIndexes:$$

    12. #removeObjectFrom<Key>AtIndex:$$

    13. #remove<Key>AtIndexes:$$

    14. //$NSMutableArray$

      $removeObjectAtIndex:$$removeObjectsAtIndexes:$$

    15. #replaceObjectIn<Key>AtIndex:withObject:$$

    16. #replace<Key>AtIndexes:with<Key>:$$

    17. //$$

    情⼦子第

    [java] view plaincopy

    1. #countOf<Key>$$

    2. //NSArraycount:$$

    3. #objectIn<Key>AtIndex:$$

    4. #<key>AtIndexes:$$

    5. //$NSArray$

      $objectAtIndex:$$objectsAtIndexes:$$

    6. #get<Key>:range:$$

    1. //$NSArray$ $getObjects:range:$$

    2. $$

    3. #insertObject:in<Key>AtIndex:$$

    4. #insert<Key>:atIndexes:$$

    5. //$NSMutableArray$

      $insertObject:atIndex:$$insertObjects:atIndexes:$$

    6. #removeObjectFrom<Key>AtIndex:$$

    7. #remove<Key>AtIndexes:$$

    8. //$NSMutableArray$

      $removeObjectAtIndex:$$removeObjectsAtIndexes:$$

    9. #replaceObjectIn<Key>AtIndex:withObject:$$

    10. #replace<Key>AtIndexes:with<Key>:$$

    11. //$$

    增增 ⽤用都增⾏行得在增友 个就样就增在我⾏行 4Key-Value Validation KVC们KeyValue第

    [java] view plaincopy
    1. #$(BOOL)validateValue:(inout$id$*)ioValue$forKey:

         (NSString$*)inKey$error:(out$NSError$**)outError;$$
    
    很⼀一就第
    

    [java] view plaincopy
    1. #$(BOOL)validate<Key>:error:$$

    name第 [java] view plaincopy

    1. #(BOOL)validateName:(id$*)ioValue$error: (NSError$*$__autoreleasing$*)outError${$$

    2. $$$$//$Implementation$specific$code.$$

    3. $$$$return$...;$$

    4. }$$

    然⾏行
    

    在增KVC之得们增们

    ⾏行真以增CoreData⾏行

    5KVC

    得如着增次⾏行
    

    KVC⾏行KVC得如

    着NSNumberNSValue增⾃自不⾏行

    两增PersonNSIntegerage

    还的得

    KVC真以就想age得第 [java] view plaincopy

    1. [person$setValue:[NSNumber$numberWithInteger:5]$forKey:@"age"];$$

    ageNSNumber增KVCNSNumber也 NSInteger增⽽而家想age得⾏行

    得 增就age得第

    [java] view plaincopy
    1. [person$valueForKey:@"age"];$$

    增NSNumber就age得⾏行

    增NSNumber增NSValue意

    间NSNumber

    NSNumber着第 [java] view plaincopy

    1. +$(NSNumber$*)numberWithChar:(char)value;$$

    2. +$(NSNumber$*)numberWithUnsignedChar:(unsigned$char)value;$$

    3. +$(NSNumber$*)numberWithShort:(short)value;$$

    4. +$(NSNumber$*)numberWithUnsignedShort:(unsigned$short)value;$$

    5. +$(NSNumber$*)numberWithInt:(int)value;$$

    6. +$(NSNumber$*)numberWithUnsignedInt:(unsigned$int)value;$$

    7. +$(NSNumber$*)numberWithLong:(long)value;$$

    8. +$(NSNumber$*)numberWithUnsignedLong:(unsigned$long)value;$$

    9. +$(NSNumber$*)numberWithLongLong:(long$long)value;$$

    10. +$(NSNumber$*)numberWithUnsignedLongLong:(unsigned$long$long)value;$$

    11. +$(NSNumber$*)numberWithFloat:(float)value;$$

    12. +$(NSNumber$*)numberWithDouble:(double)value;$$

    13. +$(NSNumber$*)numberWithBool:(BOOL)value;$$

    14. +$(NSNumber$*)numberWithInteger:

           (NSInteger)value$NS_AVAILABLE(10_5,$2_0);$$
      
    15. +$(NSNumber$*)numberWithUnsignedInteger:

           (NSUInteger)value$NS_AVAILABLE(10_5,$2_0);$$
      

    得着⾏行 NSValue

    NSValue如着增⼦子如第 [java] view plaincopy

    1. +$(NSValue$*)valueWithCGPoint:(CGPoint)point;$$

    2. +$(NSValue$*)valueWithCGSize:(CGSize)size;$$

    3. +$(NSValue$*)valueWithCGRect:(CGRect)rect;$$

    4. +$(NSValue$*)valueWithCGAffineTransform:

           (CGAffineTransform)transform;$$
      
    5. +$(NSValue$*)valueWithUIEdgeInsets:(UIEdgeInsets)insets;$$

    6. +$(NSValue$*)valueWithUIOffset:

           (UIOffset)insets$NS_AVAILABLE_IOS(5_0);$$
      

    6等如会意增如 NSValue增了去第 http://blog.csdn.net/wzzvictory/article/details/8614433 6Collection Operators

    ⼦子⼒力被Key Path增了果valueForKeyPath第 增增valueForKey:情话⽅方⾏行 ⼒力@被⼒力觉增⼀一就要第

    么⼦子⼒力

    么⼦子⼒力@avg增@count增@max增@min增@sum5增要

    增不⾏行
    

    ⼦子第transactions增说Transaction

    两增第payee增amount增date⾏行两

    ⼒力第

    amount什得第 [java] view plaincopy

    1. NSNumber$*transactionAverage$=$[transactions$valueForKeyPath:@"@avg .amount"];$$

    transactions⼦子不第 [java] view plaincopy

    1. NSNumber$*numberOfTransactions$=$[transactions$valueForKeyPath:@"@c ount"];$$

    增@count⼦子⼒力被增

    增⾏行

    ⼒力

    ⼦子⼒力能点增和就在增第
    

    [java] view plaincopy
    1. @distinctUnionOfObjects$$

    2. @unionOfObjects$$ 得NSArray增新三增

    ⽂文⼦子⾏行
    第
    

    [java] view plaincopy

    1. NSArray$*payees$=$[transactions$valueForKeyPath:@"@distinctUnionOfO bjects.payee"];$$

    2. NSArray$*payees$=$[transactions$valueForKeyPath:@"@unionOfObjects.p ayee"];$$

    好机能增好机 ⾏行
    间ArraySet给⼒力 能点增⼦子⽆无⼦子增现上 第

    [java] view plaincopy

    1. //$Create$the$array$that$contains$additional$arrays.$$ 2. self.arrayOfTransactionsArray$=$[NSMutableArray$array];$$ 3. $$$
    4. //$Add$the$array$of$objects$used$in$the$above$examples.$$ 5. [arrayOfTransactionsArray$addObject:transactions];$$
    6. $$$

    1. //$Add$a$second$array$of$objects;$this$array$contains$alternate$val ues.$$

    2. [arrayOfTransactionsArrays$addObject:moreTransactions];$$

    ⽆无⼦子⼦子第arrayOfTransactionsArray 给arrayOfTransactionsArray⽆无⼦子增

    ⼒力第

    [java] view plaincopy

    1. @distinctUnionOfArrays$$ 2. @unionOfArrays$$
    3. @distinctUnionOfSets$$

    ⼦子Arrays增⼦子Sets⾏行Sets 三增@unionOfSets⼒力⾏行

    两第

    [java] view plaincopy
    1. NSArray$*payees$=$[arrayOfTransactionsArrays$valueForKeyPath:@"@uni

    onOfArrays.payee"];$$

    1KVC KVC时⽽而家⾏行⽽而家 增增KVC为⽽而家到⽣生⾏行想 增KVC出情真以第 做这说-<key>-is<key>明得-get<key>⽽而 家增增得⽂文 做这说-set<key>:增想得⾏行-get<key>- set<key>:增⼈人Key⼒力觉增Cocoa 吧⽂文 只增做这-_<key>-_is<key>明得 -_get<key>-_set<key>:⽂文 间⽽而家增⽽而两⾏行两 第<key>_<key>; 增valueForUndefinedKey:setValue:forUndefinedKey: ⾏行很增着⼈人⾏行 2KVC/KVO 之得之得中种着isa-swizzling真以增着runtime ⼤大⾏行上成去第 http://blog.csdn.net/kesalin/article/details/8194240 时中种增⼤大知 增知⼈人中种 setter ⾏行 知⼈人 setter 增之得中 种⾏行想 setter 增⼈人 KVO ⾏行主每 KVO 想就 得增那还的增 KVO ⾏行 知⼈人 class “更”地⾏行 isa 在在才知增

    知增 setter ⼈人 setter增 没之得⾏行增知⼈人 dealloc 学看微⾏行 ⼈人增学两增⾏行 去Objective-C第 http://blog.csdn.net/wzzvictory/article/details/8592492 增isa在在增第Person增 runtime的第NSKVONotifying_Person⾏行 NSKVONotifying_Person⼈人第 set增class增dealloc增_isKVOA⾏行

    class

    ⼈人class⼈人下⾏行

    道第

    [java] view plaincopy
    1. NSLog(@"self#>isa:%@",self#>isa);$$

    2. NSLog(@"self$class:%@",[self$class]);$$ KVO增道第

    [java] view plaincopy
    1. self#>isa:Person$$

    2. self$class:Person$$ KVO增道第

    [java] view plaincopy
    1. self#>isa:NSKVONotifying_Person$$

    2. self$class:Person$$ isa在class新增⾏行

    ⼈人set ⼈人set增set⼼心第

    [java] view plaincopy
    1. #$(void)willChangeValueForKey:(NSString$*)key$$

    2. #$(void)didChangeValueForKey:(NSString$*)key$$ 增didChangeValueForKey:美第

    [java] view plaincopy

    1. #$(void)observeValueForKeyPath:(NSString$*)keyPath$$ 2. $$$$$$$$$$$$$$$$$$$$$$ofObject:(id)object$$
    3. $$$$$$$$$$$$$$$$$$$$$$$$change:(NSDictionary$*)change$$ 4. $$$$$$$$$$$$$$$$$$$$$$$context:(void$*)context$$

    增KVO等 ⽽而家增-setValue:forKey第

    [java] view plaincopy
    1. #$(void)willChangeValueForKey:(NSString$*)key$$

    2. #$(void)didChangeValueForKey:(NSString$*)key$$ 之得对⾃自⽽而增

    起要只增KVO等 增KVO第 1)KVC

    KVC增⽽而家增⽽而家will/ didChangeValueForKey:⽂文 ⽽而家增setValue:forKeywill/ didChangeValueForKey:⾏行

    2)⽽而家 ⼈人⽽而家will/didChangeValueForKey:⾏行 增⽽而家的得增KVO⾏行 3)起要will/didChangeValueForKey:⾏行 增KVO增will/didChangeValueForKey:⾏行 间_isKVOA
    回可要 KVO ⾏行
    1

    两增
    分来 活增AppleScript分来增过⾏行 2
    KVC起增KVO增了去第 http://www.mikeash.com/pyblog/key-value-observing-done-right.html KVO增selectorblock增 让⼈人-addObserver:forKeyPath:options:context:成⾏行 增MAKVONotificationCenter增 github:
    https://github.com/mikeash/MAKVONotificationCenter KVO多增信⾏行

    了第

    http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ KeyValueCoding/Articles/KeyValueCoding.html#//apple_ref/doc/uid/ 10000107-SW1
    http://blog.csdn.net/kesalin/article/details/8194240 

  • 相关阅读:
    Caffe2——C++ 预测(predict)Demo
    Effective C++ 条款06:若不想使用编译器自动生成的函数,就该明确拒绝
    Effective C++ 条款05:了解C++编写并调用哪些函数
    Effective C++ 条款04:确定对象被使用前已经先被初始化
    Effective C++ 条款03:尽可能使用const
    Effective C++ 条款02:尽量以const,enum,inline替换 #define
    使用队列(Queue)解决简单的并发问题
    关于C#中Queue的线程安全问题
    C#多线程编程
    跨线程访问控件的问题和编程方法
  • 原文地址:https://www.cnblogs.com/fengwuqingyang/p/4941578.html
Copyright © 2020-2023  润新知