//
//  NSAttributedString+gmsafekit.m
//  HiSports
//
//  Created by luxiaoming on 16/8/26.
//  Copyright © 2016年 com.ouj. All rights reserved.
//

#import "NSAttributedString+gmsafekit.h"

@implementation NSAttributedString (gmsafekit)


- (instancetype)safeInitWithString:(NSString *)str {
    if (str && str.length > 0) {
        return [[[self class] alloc] initWithString:str];//因为NSMutableAttributedString会继承这些方法，所以只能用[self class]
    } else {
        return nil;
    }
}

- (instancetype)safeInitWithString:(NSString *)str attributes:(NSDictionary<NSString *,id> *)attrs {
    if (str && str.length > 0) {
        return [[[self class] alloc] initWithString:str attributes:attrs];//因为NSMutableAttributedString会继承这些方法，所以只能用[self class]
    } else {
        return nil;
    }
}

- (instancetype)safeInitWithAttributedString:(NSAttributedString *)attrStr {
    if (attrStr) {
        return [[[self class] alloc] initWithAttributedString:attrStr];//因为NSMutableAttributedString会继承这些方法，所以只能用[self class]
    } else {
        return nil;
    }
}

@end







@implementation NSMutableAttributedString (gmsafekit)

- (void)safeAppendAttributedString:(NSAttributedString *)attrString {
    if (attrString && [attrString isKindOfClass:[NSAttributedString class]]) {
        [self appendAttributedString:attrString];
    }
}

@end
