Latest 0.1.1
Homepage https://github.com/DefaultYuan/DYSafeObject
License MIT
Platforms ios 7.0, requires ARC
Frameworks UIKit
Authors

仓库描述

为了避免线上项目中的用到的数据而产生的Crash

使用方法

pod 'DYSafeObject', '~> 0.1.1'

以下是测试代码

数组 Test

防止数组里面对象为nil的情况、数组越界产生的崩溃

NSString *s1 = nil;
NSArray *array = @[s1,@"a",@"v",@"c",@"d",@"f",@"s",@"v",@"g"];
NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithArray:array];
NSLog(@"数组 Test--array:%@   mutableArray:%@",array[20],mutableArray[20]);
NSLog(@"数组 Test--array:%@   mutableArray:%@",[array objectAtIndex:20],mutableArray[20]);
NSLog(@"数组 Test--array%@",array);

字典 Test

防止字典的key与value为nil产生的崩溃

NSString *key = nil;
NSString *str = nil;
NSDictionary *dict = @{key:str};
NSArray *dArray = @[str];
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
mutableDict[@"key"] = str;

NSLog(@"字典 Test--dict:%@",dict);
NSLog(@"字典 Test--dArray:%@",dArray);
NSLog(@"字典 Test--mutableDict:%@ key:%@",mutableDict,mutableDict[@"key"]);

字符串 Test

防止字符串长度越界

NSMutableString *string = [[NSMutableString alloc] initWithFormat:@"世界因我而精彩"];
NSLog(@"字符串 Test--%@",[string substringFromIndex:50]);

处理NSNull 异常

消息转发 Test

NSDictionary *dic2 = @{@"key":[NSNull null]};
NSLog(@"dic2==%@",dic2);
[dic2[@"key"] UTF8String];

Latest podspec

{
    "name": "DYSafeObject",
    "version": "0.1.1",
    "summary": "u9632u6b62 u5b57u5178valueu4e3anilu3001u6570u7ec4u8d8au754cu3001u3001NSNullu5bf9u8c61u5bfcu81f4u7684Crash.",
    "homepage": "https://github.com/DefaultYuan/DYSafeObject",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "defaultyuan": "[email protected]"
    },
    "source": {
        "git": "https://github.com/DefaultYuan/DYSafeObject.git",
        "tag": "0.1.1"
    },
    "social_media_url": "https://weibo.com/u/2792951481",
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "DYSafeObject/DYSafeObject/Classes/**/*",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This