Foundation部分扩展
2018-04-30 本文已影响45人
师傅我坚持不住了
WKCFoundation
Some base on Foundation
pod 'WKCFoundation'
#import <WKCFoundation/WKCFoundation.h>
NSObject+extension
- 各属性
NSArray *propertyList = [UIViewController propertyList];
NSArray *methodList = [UIViewController methodList]; NSString *appVersion = [NSObject appVersion];
NSString *className = [UIViewController className]; NSString *superClaaName = [UIViewController superClassName];
- BlockKVO
[self.view wkc_addObserver:self forKeyPath:@"fram" options:NSKeyValueObservingOptionNew context:nil withBlock:^(NSDictionary *change, void *context) { id object = [change objectForKey:NSKeyValueChangeNewKey]; }];
NSDictionary+extension
- 快速遍历字典
NSDictionary *dic = @{@"测试1":@"你",@"测试2":@"我"};
[dic each:^(id key, id value) {
}];
[dic eachKey:^(id key) {
}];
[dic eachValue:^(id value) {
}];
- 转json字符串.
NSString *json = [dic jsonString];
NSArray+extension
- 快速遍历数组
NSArray *array = @[@"你",@"我",@"他",@"我"];
[array each:^(id object) {
}];
[array eachWithIndex:^(id object, NSUInteger index) {
}];
- 过滤.
NSArray *filterArray = [array filter:^BOOL(id object) {
return [object isEqualToString:@"我"];
}];
- 排序.
NSArray *sortArray = [array sortWithType:NSArraySortTypeAsc];
NSSet+extension
- 快速遍历集合.
NSSet *set = [NSSet setWithObjects:@"你",@"我",@"她", nil];
[set each:^(id object) {
}];
[set eachWithIndex:^(id object, int index) {
}];
NSData+extension
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
/**压缩*/
NSData *zipedData = [data zipped];
/**解压缩*/
NSData *gezipedData = [zipedData Gezipped];
NSString+extension
- 字符串判断
/** 是否全是数字 */
@property (nonatomic, assign, readonly) BOOL isAllNumber;
/** 是含有中文 */
@property (nonatomic, assign, readonly) BOOL isHaveChinese;
/** 是否是QQ账号 */
@property (nonatomic, assign, readonly) BOOL isQQ;
/** 是否是iP地址 */
@property (nonatomic, assign, readonly) BOOL isIPAddress;
/** 是否是手机号 */
@property (nonatomic, assign ,readonly) BOOL isPhoneNumber;
/** 密码正则-是否为两种以及以上的字符 */
@property (nonatomic, assign ,readonly) BOOL isKindMoreThanTwo;
/** 是否为昵称 */
@property (nonatomic, assign, readonly) BOOL isNickName;
/** 是否为验证码 */
@property (nonatomic, assign ,readonly) BOOL isVerificationCode;
/** 是否为有效邮箱 */
@property (nonatomic, assign, readonly) BOOL isEmail;
/**是否为全英文*/
@property (nonatomic, assign ,readonly) BOOL isEnglish;
/**是否为数字、字母和汉字*/
@property (nonatomic, assign, readonly) BOOL isWordsAndNumbers;
/**是否为小数*/
@property (nonatomic, assign, readonly) BOOL isPointNumber;
/**判断是否含特殊字符*/
@property (nonatomic, assign, readonly) BOOL isSpecialChar;
/** 是否为纳信号 */
@property (nonatomic, assign, readonly) BOOL isNXNUMBER;
/**是否包含表情符号*/
@property (nonatomic, assign, readonly) BOOL isContainsEmoji;
- 字符串处理.
/**获取首字母*/
@property (nonatomic, copy, readonly) NSString * firstChar;
/**汉字转拼音,并且无中间空格*/
@property (nonatomic, copy, readonly) NSString * transformPinYin;
/**富文本只改变颜色*/
- (NSMutableAttributedString *)attributedWithColor:(UIColor *)color subStrings:(NSArray <NSString *>*)stringArr;
/**富文本只改变字体*/
- (NSMutableAttributedString *)attributedWithFont:(UIFont *)font subStrings:(NSArray <NSString *>*)stringArr;
/**富文本同时改变颜色和字体*/
- (NSMutableAttributedString *)attributedWithColor:(UIColor *)color font:(UIFont *)font subStrings:(NSArray <NSString *>*)stringArr;
/**富文本下划线*/
- (NSMutableAttributedString *)attributedWithLineInColor:(UIColor *)color subStrings:(NSArray <NSString *>*)stringArr;
/**根据字体大小求字符串宽高*/
- (CGSize)sizeWithFont:(UIFont *)font;
/**纯小数字符串 -- 设置允许小数点后位数*/
- (void)setLimited:(const NSInteger)limited OverstepBlock:(void(^)(void))block;
NSDate+bascSetting
/**获取当前日期*/
+(NSString *)currentDate;
/**获取当前年*/
+(NSString *)currentYear;
/**获取当前月*/
+(NSString *)currentMonth;
/**获取当前日*/
+(NSString *)currentDay;
/**获取当前小时*/
+(NSString *)currentHour;
/**获取当前分钟*/
+(NSString *)currentMinute;
/**获取当前秒*/
+(NSString *)currentSecond;
/**获取某个时间段,几秒间隔后的时间*/
+(NSString *)beforeSecond:(NSInteger)second Date:(NSDate *)date;
/**获取某个时间段,几分钟间隔后的时间*/
+(NSString *)beforeMin:(NSInteger)min Date:(NSDate *)date;
/**获取某个时间段,几小时间隔后的时间*/
+(NSString *)beforeHour:(NSInteger)hour Date:(NSDate *)date;
/**获取某个时间段,几天间隔后的时间*/
+(NSString *)beforeDay:(NSInteger)day Date:(NSDate *)date;
/**获取某个时间段,几月间隔后的时间*/
+(NSString *)beforeMonth:(NSInteger)month Date:(NSDate *)date;
/**获取某个时间段,几年3间隔后的时间*/
+(NSString *)beforeYear:(NSInteger)year Date:(NSDate *)date;
/**通过特定类型字符串返回日期格式*/
+ (NSDate *)dateFromDateforamt:(NSString *)foramt String:(NSString *)string;
UIResponder+chain
视图的响应链
NSString *chain = [self.view descriptResponderChain];
NSNotificationCenter+extension
- 主线程通知
[[NSNotificationCenter defaultCenter] postOnMainThreadWithNotificationName:@"name" object:nil userInfo:nil];
- 子线程通知
[[NSNotificationCenter defaultCenter] postOnAsyncThreadWithNotificationName:@"name" object:nil userInfo:nil];
如有问题或bug,请私信.github地址.