Latest 2.0.1
Homepage https://github.com/yellowzhou/YZExtension
License MIT
Platforms ios 6.0, requires ARC
Frameworks CFNetwork, Foundation
Authors

YZStrongExtension

安装使用

pod ‘YZExtension’, ‘~> 2.0.0’

说明

在使用 数组或者字典、字符串时,经常遇到越界或者nil对象引起的闪退,在庞杂的项目中,无法逐个排查。
采用 method swizzling实现 这类异常得到修复,在运行中,不能出现闪退

  • 数组越界取值

    
    NSMutableArray *list = [NSMutableArray new];
    id object = [list objectAtIndex:1000];
    NSLog(@"%@",object);// 0x600000446e70 [__NSArrayM objectAtIndex:] index 1000 beyond bounds [0 .. 0]
  • 数组插入nil对象

    
    NSMutableArray *list = [NSMutableArray new];
    [list insertObject:nil atIndex:0];
    // 0x600000446e70 [__NSArrayM insertObject:atIndex:] object cannot be nil
    [list replaceObjectAtIndex:0 withObject:nil];
    // 0x600000448220 [__NSArrayM replaceObjectAtIndex:withObject:] object cannot be nil
    
    NSArray *array = @[@"aa",text,@"ccc"];
    // 0x6000000031f0 [__NSPlaceholderArray initWithObjects:count:] attempt to insert nil object from objects[1]
    NSLog(@"%@",array);
    /* (
    aa,
    ccc
    ) */
  • 字典添加nil对象

    
    NSString *text = nil;
    [list addObject:@{@"name":text}];
    NSDictionary *dic = @{@"name":@"aaa",@"age":text,@"sex":@"man"};
    // 0x600000003230 [__NSPlaceholderDictionary initWithObjects:forKeys:count:] attempt to insert nil object from objects[1]
    NSLog(@"%@",dic); 
    /* {
    name = aaa;
    sex = man;
    } */
  • 字典设置 key、object 为nil对象

    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setObject:nil forKey:@"test"];
    [dict setObject:@"object" forKey:text];
    // 0x60400023a060 [__NSDictionaryM setObject:forKey:] key cannot be nil (object: object)
    // 0x60400023a060 [__NSDictionaryM setObject:forKey:] object cannot be nil (key: test)
    
    * NSString 截取越界

    NSString tmp = @"hello wrold";
    NSString
    p = [tmp substringFromIndex:100];
    p = [tmp substringToIndex:300];
    p = [tmp substringWithRange:(NSRange){20,40}];

Latest podspec

{
    "name": "YZExtension",
    "platforms": {
        "ios": "6.0"
    },
    "version": "2.0.1",
    "summary": "u521bu5efau7cfbu7edfu7c7bAPIu62d3u5c55uff0cu63d0u9ad8u7a0bu5e8fu5065u58ee",
    "homepage": "https://github.com/yellowzhou/YZExtension",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "yellowzhou": "[email protected]"
    },
    "source": {
        "git": "https://github.com/yellowzhou/YZExtension.git",
        "tag": "2.0.1"
    },
    "frameworks": [
        "CFNetwork",
        "Foundation"
    ],
    "source_files": "YZExtension/Extension/*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This