OC - 常用技巧

来源:互联网 发布:大数据和计算机 编辑:程序博客网 时间:2024/06/03 02:26

本部分内容不定期持续更新


1.根window对象

UIWindow * window = [UIApplication sharedApplication].keyWindow;window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];window.backgroundColor = [UIColor whiteColor];window.rootViewController = [[ViewController alloc] init];// makeKeyAndVisible:去使被使用对象的主窗口显示到屏幕的最前端。也可以使用hiddenUIView方法隐藏这个窗口[window makeKeyAndVisible];

2.NSNumber创建数字对象

NSNumber创建数字对象
或者

NSNumber * number = @3;

输出数字对象
输出值为3.000000

注:NSNumber为类,NSUInteger为基本数据类型,因此NSNumber创建的对象均可拿来直接赋值使用,而NSUInteger无法做到。


3.混编

设置

-fno-objc-arc

4.Xcode版本验证

想要验证xcode是否是官方原版,在终端输入

spctl --assess --verbose /Applications/Xcode.app

等一段时间后有

/Applications/Xcode.app: acceptedsource=Mac App Store

即说明xcode是从苹果商城下载的
或者

/Applications/Xcode.app: acceptedsource=Apple/Applications/Xcode.app: acceptedsource=Apple System

除此之外其他Xcode均无效


5.判断某个字符串是否为空

+ (BOOL)isBlank:(NSString *)string{    if ( string == nil || string == NULL || [ string isEqualToString : @"(null)" ]        || [ string isEqualToString : @"" ] || [ string isEqualToString : @" " ]) {        return YES ;    }    if ( [string isKindOfClass:[NSNull class]] ) {        return YES ;    }    if ( [[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0 ) {        return YES ;    }    return NO ;}

6. provision profile路径

~/Library/MobileDevice/Provisioning Profiles

7. ASCII码表验证密码输入强度等级

此方法稍微修改便可区分密码输入强度等级

+(BOOL)isPasswordCorrect:(NSString*)content{    if (content.length<8 || content.length>16)    {        return NO ;    }    BOOL numberResult = NO;    BOOL letterResult = NO;      for (int i = 0; i<content.length; i++)    {        char character = [content characterAtIndex:i];        // 0~9        if (( character >=48 && character <= 57 ) && numberResult == NO)        {            numberResult = YES;        }        // A~Z   a~z        if (((character >=65  && character <=90) || (character >=97  && character <=122))  && letterResult == NO)        {            letterResult = YES;        }        if (numberResult == YES && letterResult ==YES)        {            return YES;        }    }    return NO;}

8. GIF转数组

#import <ImageIO/ImageIO.h>- (NSMutableArray *)praseGIFDataToImageArray:(NSData *)data{    NSMutableArray * frames = [[NSMutableArray alloc]init];    CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef)data, NULL);    CGFloat animationTime = 0.f;    if (src) {        size_t l = CGImageSourceGetCount(src);        frames = [NSMutableArray arrayWithCapacity:l];        for (size_t i = 0; i < l ; i++) {            CGImageRef img = CGImageSourceCreateImageAtIndex(src, i, NULL);            NSDictionary * properties = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(src, i, NULL));            NSDictionary * frameProperties = [properties objectForKey:(NSString *)kCGImagePropertyGIFDictionary];            NSNumber * delayTime = [frameProperties objectForKey:(NSString *)kCGImagePropertyGIFUnclampedDelayTime];            animationTime += [delayTime floatValue];            if (img) {                [frames addObject:[UIImage imageWithCGImage:img]];                CGImageRelease(img);            }        }        CFRelease(src);    }    return frames;}
1 0
原创粉丝点击