<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                class_getInstanceMethod???? 得到類的實例方法 class_getClassMethod????????? 得到類的類方法 ~~~ /** * Returns a specified instance method for a given class. * * @param cls The class you want to inspect. * @param name The selector of the method you want to retrieve. * * @return The method that corresponds to the implementation of the selector specified by * \e name for the class specified by \e cls, or \c NULL if the specified class or its * superclasses do not contain an instance method with the specified selector. * * @note This function searches superclasses for implementations, whereas \c class_copyMethodList does not. */ OBJC_EXPORT Method class_getInstanceMethod(Class cls, SEL name) __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0); /** * Returns a pointer to the data structure describing a given class method for a given class. * * @param cls A pointer to a class definition. Pass the class that contains the method you want to retrieve. * @param name A pointer of type \c SEL. Pass the selector of the method you want to retrieve. * * @return A pointer to the \c Method data structure that corresponds to the implementation of the * selector specified by aSelector for the class specified by aClass, or NULL if the specified * class or its superclasses do not contain an instance method with the specified selector. * * @note Note that this function searches superclasses for implementations, * whereas \c class_copyMethodList does not. */ OBJC_EXPORT Method class_getClassMethod(Class cls, SEL name) __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0); ~~~ 測試所用Person類: ~~~ #import <Foundation/Foundation.h> @interface Person : NSObject @property(nonatomic, assign) NSInteger age; @property(nonatomic, copy) NSString * name; +(Person *)sharedManager; - (instancetype)init; + (void) printDZ; - (void) printDZL; @end #import "Person.h" @interface Person () @property(nonatomic, strong) NSString * sex; @end @implementation Person +(Person *)sharedManager { ??? static Person *sharedManager; ??? static dispatch_once_t onceTest; ??? dispatch_once(&onceTest, ^{ ??????? sharedManager = [[Person alloc] init]; ??? }); ??? NSLog(@"+ method"); ??? return sharedManager; } - (instancetype)init { ??? self = [super init]; ??? if (self) { ??????? self = [super init]; ??????? self.sex = @"-----------"; ??????? self.age = 19; ??????? self.name = @"sb"; ??? } ??? return self; } + (void)printDZ { ??? NSLog(@"this is a class method"); } - (void)printDZL { ??? NSLog(@"this is a instance method"); } @end ~~~ 測試代碼: ~~~ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. Person * p1 = [[Person alloc] init]; Method m1 = class_getInstanceMethod([p1 class], @selector(printDZL)); Method m2 = class_getClassMethod([Person class], @selector(printDZ)); ??? NSLog(@"測試前:"); ??? [p1 printDZL]; ??? [Person printDZ]; ??? method_exchangeImplementations(m1, m2); ??? NSLog(@"測試后:"); ??? [p1 printDZL]; ??? [Person printDZ]; } ~~~ 輸出: ~~~ 2015-11-04 13:37:08.539 02-runtime[2776:69899] 測試前: 2015-11-04 13:37:08.539 02-runtime[2776:69899] this is a instance method 2015-11-04 13:37:08.539 02-runtime[2776:69899] this is a class method 2015-11-04 13:37:08.540 02-runtime[2776:69899] 測試后: 2015-11-04 13:37:08.540 02-runtime[2776:69899] this is a class method 2015-11-04 13:37:08.540 02-runtime[2776:69899] this is a instance method ~~~ 由輸出可見,方法體交換了,說明class_getInstanceMethod成功得到了實例方法,class_getClassMethod成功得到了類方法 但是當用class_getInstanceMethod來取類方法,用class_getClassMethod來取實例方法時: ~~~ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. Person * p1 = [[Person alloc] init]; // Method m1 = class_getInstanceMethod([p1 class], @selector(printDZL)); // Method m2 = class_getClassMethod([Person class], @selector(printDZ)); Method m1 = class_getInstanceMethod([Person class], @selector(printDZ)); Method m2 = class_getClassMethod([p1 class], @selector(printDZL)); NSLog(@"測試前:"); [p1 printDZL]; [Person printDZ]; method_exchangeImplementations(m1, m2); NSLog(@"測試后:"); [p1 printDZL]; [Person printDZ]; } ~~~ 輸出: ~~~ 2015-11-04 13:38:10.050 02-runtime[2793:70426] 測試前: 2015-11-04 13:38:10.051 02-runtime[2793:70426] this is a instance method 2015-11-04 13:38:10.051 02-runtime[2793:70426] this is a class method 2015-11-04 13:38:10.051 02-runtime[2793:70426] 測試后: 2015-11-04 13:38:10.051 02-runtime[2793:70426] this is a instance method 2015-11-04 13:38:10.051 02-runtime[2793:70426] this is a class method ~~~ 由輸出可見,沒有發生交換,可知這樣是取不到的。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看