OC - 常用技巧

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


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: accepted
source=Mac App Store

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

/Applications/Xcode.app: accepted
source=Apple

/Applications/Xcode.app: accepted
source=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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值