美文网首页
iOS方法调用

iOS方法调用

作者: Smallwolf_JS | 来源:发表于2021-04-01 12:06 被阅读0次

    If you are calling another class method from inside a class method (of the same class) you can just use[self classMethod]. If however you are in an instance method and you need to call that classes class method you can use[[self class] classMethod]

    
    + (NSArray *)rankString
    
    {
        return @[@"?", @"A", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"J", @"Q", @"K"];
    
    }
    
    
    + (NSUInteger)maxRank
    
    {
    return ([当前类 rankString].count - 1);
    
        //用self也可以正常工作,比如return ([self rankString].count - 1);
    
    }
    

    下面方法可以执行

    NSObject+xxx.h
    
    @interface NSObject (xxx)
    
    - (void)test;
    
    @end
    
    
    NSObject+xxx.m
    
    @implementation NSObject (xxx)
    
    - (void)test {
     
    }
    
    @end
    
    
    Person.h
    
    @interface Person : NSObject
    
    @end
    
    
    Person.m
    
    #import "NSObject+xxx.h"
    
    @implementation Person
    
    + (void)doSomething {
     [self test];
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:iOS方法调用

          本文链接:https://www.haomeiwen.com/subject/nkhwqltx.html