//
// main.m
// OC_06类的扩展
//
// Created by lanou3g on 17/8/2.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "NSString+SayHi.h"
#import "NSString+Captical.h"
int main(int argc, const char * argv[]) {
[@"包包" sayHi];
NSString *string = [@"liying" firstCharacter];
NSLog(@"%@",string);
NSString *string1 = [@"liying" changeCaptical];
NSLog(@"%@",string1);
return 0;
}
//
// NSString+SayHi.h
// OC_06类的扩展
//
// Created by lanou3g on 17/8/2.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (SayHi)
- (void)sayHi;
@end
//
// NSString+SayHi.m
// OC_06类的扩展
//
// Created by lanou3g on 17/8/2.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import "NSString+SayHi.h"
@implementation NSString (SayHi)
- (void)sayHi {
NSLog(@"我是%@,我是一个字符串",self);
}
@end
//
// NSString+Captical.h
// OC_06类的扩展
//
// Created by lanou3g on 17/8/2.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (Captical)
- (NSString *)changeCaptical;
- (NSString *)firstCharacter;
@end
//
// NSString+Captical.m
// OC_06类的扩展
//
// Created by lanou3g on 17/8/2.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import "NSString+Captical.h"
@implementation NSString (Captical)
- (NSString *)changeCaptical {
return [self capitalizedString];
}
- (NSString *)firstCharacter {
if (self.length > 0) {
return [[self substringToIndex:1] uppercaseString];
}
NSLog(@"空字符串别凑热闹");
return nil;
}
@end
//
// Person.h
// OC_06类的扩展
//
// Created by lanou3g on 17/8/2.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Person : NSObject
@end
//
// Person.m
// OC_06类的扩展
//
// Created by lanou3g on 17/8/2.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import "Person.h"
@interface Person ()
@property (nonatomic, retain) NSString *age;
@end
@implementation Person
- (instancetype)init {
self = [super init];
if (self) {
//私有方法通常是通过其他方法间接调用的,目的是将某一部分的代码封装起来,方便多次使用
[self sayHi];
}
return self;
}
//没在.h中声明的都是私有方法
- (void)sayHi {
NSLog(@"baobaodabaobao");
}
@end