Objective-C 常用代码

这里会归纳一些在Objective-C开发中常用的代码 代码会慢慢增多  =)

生成一定范围的随机数

 

验证邮箱是否合法

 

- (BOOL) validEmail:(NSString*) emailString {
      if([emailString length]==0){
         return NO;
      }
 
      NSString *regExPattern = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
 
      NSRegularExpression *regEx = [[NSRegularExpression alloc] initWithPattern:regExPattern       options:NSRegularExpressionCaseInsensitive error:nil];
      NSUInteger regExMatches = [regEx numberOfMatchesInString:emailString options:0 range:NSMakeRange(0, [emailString length])];
 
      NSLog(@"%i", regExMatches);
      if (regExMatches == 0) {
          return NO;
      } else {
          return YES;
      }
}

  

 

判断手机是否越狱

 

+(BOOL)isJailbroken {
      NSString *filePath = @"/Applications/Cydia.app";
      if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
      {
            return YES;
      } else {
            return NO;
      }
}

 

or

posted @ 2015-03-11 11:25  大慈大悲大熊猫  阅读(286)  评论(0编辑  收藏  举报