判断字符串为空串
+(BOOL)isEmptyString:(NSString*)string
{
if (string == nil)return YES;
//去空格之后判断length是否为0
NSCharacterSet* whitespace = [NSCharacterSetwhitespaceAndNewlineCharacterSet];
NSString* content = [stringstringByTrimmingCharactersInSet:whitespace];
if ([content length] ==0) return YES;
return NO;
}
生成md5
- (NSString *)md5{
constchar *concat_str = [self UTF8String];
unsignedchar result[CC_MD5_DIGEST_LENGTH];
CC_MD5(concat_str,strlen(concat_str), result);
NSMutableString *hash = [NSMutableStringstring];
for (int i =0; i < 16; i++){
[hashappendFormat:@"%02X", result[i]];
}
return [hashlowercaseString];
}
生成uuid
+ (NSString *)generateUUID
{
CFUUIDRef uuid =CFUUIDCreate(NULL);
NSString *uuidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(nil, uuid)) ;
CFRelease(uuid);
return uuidString;
}
//比较两个日期
- (BOOL)isEarlierThanDate:(NSDate *)aDate
{
NSCalendar *calendar= [NSCalendar currentCalendar];
NSInteger desiredComponents= (NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit);
NSDateComponents *firstComponents= [calendar components:desiredComponents fromDate:self];
NSDateComponents *secondComponents= [calendar components:desiredComponents fromDate:aDate];
NSDate *firstWOYear= [calendar dateFromComponents:firstComponents];
NSDate *SecondWOYear = [calendar dateFromComponents:secondComponents];
NSComparisonResult result= [firstWOYear compare:SecondWOYear];
if (result== NSOrderedAscending || result == NSOrderedSame) {
return NO;
} else if (result== NSOrderedDescending) {
return YES;
} else {
return YES;
}
}