A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.

Overview

MJExtension

SPM supported Carthage compatible podversion Platform

  • A fast, convenient and nonintrusive conversion framework between JSON and model.
  • 转换速度快、使用简单方便的字典转模型框架

📜 ✍🏻Release Notes: more details

Contents


Getting Started【开始使用】

Features【能做什么】

  • MJExtension是一套字典和模型之间互相转换的超轻量级框架
  • JSON --> ModelCore Data Model
  • JSONString --> ModelCore Data Model
  • ModelCore Data Model --> JSON
  • JSON Array --> Model ArrayCore Data Model Array
  • JSONString --> Model ArrayCore Data Model Array
  • Model ArrayCore Data Model Array --> JSON Array
  • Coding all properties of a model with only one line of code.
    • 只需要一行代码,就能实现模型的所有属性进行Coding / SecureCoding(归档和解档)

Installation【安装】

CocoaPods【使用CocoaPods】

pod 'MJExtension'

Carthage

github "CoderMJLee/MJExtension"

Swift Package Manager

Released from 3.4.0

Manually【手动导入】

  • Drag all source files under folder MJExtension to your project.【将MJExtension文件夹中的所有源代码拽入项目中】
  • Import the main header file:#import "MJExtension.h"【导入主头文件:#import "MJExtension.h"

Examples【示例】

Add MJKeyValue protocol to your model if needed【如果有需要, 请在模型中加入 MJKeyValue 协议】

Usage in Swift [关于在Swift中使用MJExtension] ‼️

Example:

@objc(MJTester)
@objcMembers
class MJTester: NSObject {
    // make sure to use `dynamic` attribute for basic type & must use as Non-Optional & must set initial value
    dynamic var isSpecialAgent: Bool = false
    dynamic var age: Int = 0
    
    var name: String?
    var identifier: String?
}
  1. @objc or @objcMembers attributes should be added to class or property for declaration of Objc accessibility [在 Swift4 之后, 请在属性前加 @objc 修饰或在类前增加 @objcMembers. 以保证 Swift 的属性能够暴露给 Objc 使用. ]
  2. If you let Bool & Int as property type, make sure that using dynamic to attribute it. It must be Non-Optional type and assign a default value.[如果要使用 BoolInt 等 Swfit 专用基本类型, 请使用 dynamic 关键字修饰, 类型为 Non-Optional, 並且给定初始值.]

纯Swift版的JSON与Model转换框架已经开源上架

  • KakaJSON
  • 中文教程
  • 如果你的项目是用Swift写的Model,墙裂推荐使用KakaJSON
    • 已经对各种常用的数据场景进行了大量的单元测试
    • 简单易用、功能丰富、转换快速

The most simple JSON -> Model【最简单的字典转模型】

typedef enum {
    SexMale,
    SexFemale
} Sex;

@interface User : NSObject
@property (copy, nonatomic) NSString *name;
@property (copy, nonatomic) NSString *icon;
@property (assign, nonatomic) unsigned int age;
@property (copy, nonatomic) NSString *height;
@property (strong, nonatomic) NSNumber *money;
@property (assign, nonatomic) Sex sex;
@property (assign, nonatomic, getter=isGay) BOOL gay;
@end

/***********************************************/

NSDictionary *dict = @{
    @"name" : @"Jack",
    @"icon" : @"lufy.png",
    @"age" : @20,
    @"height" : @"1.55",
    @"money" : @100.9,
    @"sex" : @(SexFemale),
    @"gay" : @"true"
//   @"gay" : @"1"
//   @"gay" : @"NO"
};

// JSON -> User
User *user = [User mj_objectWithKeyValues:dict];

NSLog(@"name=%@, icon=%@, age=%zd, height=%@, money=%@, sex=%d, gay=%d", user.name, user.icon, user.age, user.height, user.money, user.sex, user.gay);
// name=Jack, icon=lufy.png, age=20, height=1.550000, money=100.9, sex=1

JSONString -> Model【JSON字符串转模型】

// 1.Define a JSONString
NSString *jsonString = @"{\"name\":\"Jack\", \"icon\":\"lufy.png\", \"age\":20}";

// 2.JSONString -> User
User *user = [User mj_objectWithKeyValues:jsonString];

// 3.Print user's properties
NSLog(@"name=%@, icon=%@, age=%d", user.name, user.icon, user.age);
// name=Jack, icon=lufy.png, age=20

Model contains model【模型中嵌套模型】

@interface Status : NSObject
@property (copy, nonatomic) NSString *text;
@property (strong, nonatomic) User *user;
@property (strong, nonatomic) Status *retweetedStatus;
@end

/***********************************************/

NSDictionary *dict = @{
    @"text" : @"Agree!Nice weather!",
    @"user" : @{
        @"name" : @"Jack",
        @"icon" : @"lufy.png"
    },
    @"retweetedStatus" : @{
        @"text" : @"Nice weather!",
        @"user" : @{
            @"name" : @"Rose",
            @"icon" : @"nami.png"
        }
    }
};

// JSON -> Status
Status *status = [Status mj_objectWithKeyValues:dict];

NSString *text = status.text;
NSString *name = status.user.name;
NSString *icon = status.user.icon;
NSLog(@"text=%@, name=%@, icon=%@", text, name, icon);
// text=Agree!Nice weather!, name=Jack, icon=lufy.png

NSString *text2 = status.retweetedStatus.text;
NSString *name2 = status.retweetedStatus.user.name;
NSString *icon2 = status.retweetedStatus.user.icon;
NSLog(@"text2=%@, name2=%@, icon2=%@", text2, name2, icon2);
// text2=Nice weather!, name2=Rose, icon2=nami.png

Model contains model-array【模型中有个数组属性,数组里面又要装着其他模型】

@interface Ad : NSObject
@property (copy, nonatomic) NSString *image;
@property (copy, nonatomic) NSString *url;
@end

@interface StatusResult : NSObject
/** Contatins status model */
@property (strong, nonatomic) NSMutableArray *statuses;
/** Contatins ad model */
@property (strong, nonatomic) NSArray *ads;
@property (strong, nonatomic) NSNumber *totalNumber;
@end

/***********************************************/

// Tell MJExtension what type of model will be contained in statuses and ads.
[StatusResult mj_setupObjectClassInArray:^NSDictionary *{
    return @{
               @"statuses" : @"Status",
               // @"statuses" : [Status class],
               @"ads" : @"Ad"
               // @"ads" : [Ad class]
           };
}];
// Equals: StatusResult.m implements +mj_objectClassInArray method.

NSDictionary *dict = @{
    @"statuses" : @[
                      @{
                          @"text" : @"Nice weather!",
                          @"user" : @{
                              @"name" : @"Rose",
                              @"icon" : @"nami.png"
                          }
                      },
                      @{
                          @"text" : @"Go camping tomorrow!",
                          @"user" : @{
                              @"name" : @"Jack",
                              @"icon" : @"lufy.png"
                          }
                      }
                  ],
    @"ads" : @[
                 @{
                     @"image" : @"ad01.png",
                     @"url" : @"http://www.ad01.com"
                 },
                 @{
                     @"image" : @"ad02.png",
                     @"url" : @"http://www.ad02.com"
                 }
             ],
    @"totalNumber" : @"2014"
};

// JSON -> StatusResult
StatusResult *result = [StatusResult mj_objectWithKeyValues:dict];

NSLog(@"totalNumber=%@", result.totalNumber);
// totalNumber=2014

// Printing
for (Status *status in result.statuses) {
    NSString *text = status.text;
    NSString *name = status.user.name;
    NSString *icon = status.user.icon;
    NSLog(@"text=%@, name=%@, icon=%@", text, name, icon);
}
// text=Nice weather!, name=Rose, icon=nami.png
// text=Go camping tomorrow!, name=Jack, icon=lufy.png

// Printing
for (Ad *ad in result.ads) {
    NSLog(@"image=%@, url=%@", ad.image, ad.url);
}
// image=ad01.png, url=http://www.ad01.com
// image=ad02.png, url=http://www.ad02.com

Model name - JSON key mapping【模型中的属性名和字典中的key不相同(或者需要多级映射)】

@interface Bag : NSObject
@property (copy, nonatomic) NSString *name;
@property (assign, nonatomic) double price;
@end

@interface Student : NSObject
@property (copy, nonatomic) NSString *ID;
@property (copy, nonatomic) NSString *desc;
@property (copy, nonatomic) NSString *nowName;
@property (copy, nonatomic) NSString *oldName;
@property (copy, nonatomic) NSString *nameChangedTime;
@property (strong, nonatomic) Bag *bag;
@end

/***********************************************/

// How to map
[Student mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
    return @{
               @"ID" : @"id",
               @"desc" : @"description",
               @"oldName" : @"name.oldName",
               @"nowName" : @"name.newName",
               @"nameChangedTime" : @"name.info[1].nameChangedTime",
               @"bag" : @"other.bag"
           };
}];
// Equals: Student.m implements +mj_replacedKeyFromPropertyName method.

NSDictionary *dict = @{
    @"id" : @"20",
    @"description" : @"kids",
    @"name" : @{
        @"newName" : @"lufy",
        @"oldName" : @"kitty",
        @"info" : @[
        		 @"test-data",
        		 @{
            	             @"nameChangedTime" : @"2013-08"
                         }
                  ]
    },
    @"other" : @{
        @"bag" : @{
            @"name" : @"a red bag",
            @"price" : @100.7
        }
    }
};

// JSON -> Student
Student *stu = [Student mj_objectWithKeyValues:dict];

// Printing
NSLog(@"ID=%@, desc=%@, oldName=%@, nowName=%@, nameChangedTime=%@",
      stu.ID, stu.desc, stu.oldName, stu.nowName, stu.nameChangedTime);
// ID=20, desc=kids, oldName=kitty, nowName=lufy, nameChangedTime=2013-08
NSLog(@"bagName=%@, bagPrice=%f", stu.bag.name, stu.bag.price);
// bagName=a red bag, bagPrice=100.700000

JSON array -> model array【将一个字典数组转成模型数组】

NSArray *dictArray = @[
                         @{
                             @"name" : @"Jack",
                             @"icon" : @"lufy.png"
                         },
                         @{
                             @"name" : @"Rose",
                             @"icon" : @"nami.png"
                         }
                     ];

// JSON array -> User array
NSArray *userArray = [User mj_objectArrayWithKeyValuesArray:dictArray];

// Printing
for (User *user in userArray) {
    NSLog(@"name=%@, icon=%@", user.name, user.icon);
}
// name=Jack, icon=lufy.png
// name=Rose, icon=nami.png

Model -> JSON【将一个模型转成字典】

// New model
User *user = [[User alloc] init];
user.name = @"Jack";
user.icon = @"lufy.png";

Status *status = [[Status alloc] init];
status.user = user;
status.text = @"Nice mood!";

// Status -> JSON
NSDictionary *statusDict = status.mj_keyValues;
NSLog(@"%@", statusDict);
/*
 {
 text = "Nice mood!";
 user =     {
 icon = "lufy.png";
 name = Jack;
 };
 }
 */

// More complex situation
Student *stu = [[Student alloc] init];
stu.ID = @"123";
stu.oldName = @"rose";
stu.nowName = @"jack";
stu.desc = @"handsome";
stu.nameChangedTime = @"2018-09-08";

Bag *bag = [[Bag alloc] init];
bag.name = @"a red bag";
bag.price = 205;
stu.bag = bag;

NSDictionary *stuDict = stu.mj_keyValues;
NSLog(@"%@", stuDict);
/*
{
    ID = 123;
    bag =     {
        name = "\U5c0f\U4e66\U5305";
        price = 205;
    };
    desc = handsome;
    nameChangedTime = "2018-09-08";
    nowName = jack;
    oldName = rose;
}
 */

Model array -> JSON array【将一个模型数组转成字典数组】

// New model array
User *user1 = [[User alloc] init];
user1.name = @"Jack";
user1.icon = @"lufy.png";

User *user2 = [[User alloc] init];
user2.name = @"Rose";
user2.icon = @"nami.png";

NSArray *userArray = @[user1, user2];

// Model array -> JSON array
NSArray *dictArray = [User mj_keyValuesArrayWithObjectArray:userArray];
NSLog(@"%@", dictArray);
/*
 (
 {
 icon = "lufy.png";
 name = Jack;
 },
 {
 icon = "nami.png";
 name = Rose;
 }
 )
 */

Core Data

func json2CoreDataObject() {
    context.performAndWait {
        let object = MJCoreDataTester.mj_object(withKeyValues: Values.testJSONObject, context: context)
        // use the object
    }
}

func coreDataObject2JSON() {
    context.performAndWait {        
        let dict = coreDataObject.mj_keyValues()
        // use dict
    }
}

Coding (Archive & Unarchive methods are deprecated in iOS 12)

#import "MJExtension.h"

@implementation MJBag
// NSCoding Implementation
MJCodingImplementation
@end

/***********************************************/

// what properties not to be coded
[MJBag mj_setupIgnoredCodingPropertyNames:^NSArray *{
    return @[@"name"];
}];
// Equals: MJBag.m implements +mj_ignoredCodingPropertyNames method.

// Create model
MJBag *bag = [[MJBag alloc] init];
bag.name = @"Red bag";
bag.price = 200.8;

NSString *file = [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/bag.data"];
// Encoding by archiving
[NSKeyedArchiver archiveRootObject:bag toFile:file];

// Decoding by unarchiving
MJBag *decodedBag = [NSKeyedUnarchiver unarchiveObjectWithFile:file];
NSLog(@"name=%@, price=%f", decodedBag.name, decodedBag.price);
// name=(null), price=200.800000

Secure Coding

Using MJSecureCodingImplementation(class, isSupport) macro.

@import MJExtension;

// NSSecureCoding Implementation
MJSecureCodingImplementation(MJBag, YES)

@implementation MJBag
@end

 /***********************************************/

// what properties not to be coded
[MJBag mj_setupIgnoredCodingPropertyNames:^NSArray *{
    return @[@"name"];
}];
// Equals: MJBag.m implements +mj_ignoredCodingPropertyNames method.

// Create model
MJBag *bag = [[MJBag alloc] init];
bag.name = @"Red bag";
bag.price = 200.8;
bag.isBig = YES;
bag.weight = 200;

NSString *file = [NSTemporaryDirectory() stringByAppendingPathComponent:@"bag.data"];

NSError *error = nil;
// Encoding by archiving
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:bag requiringSecureCoding:YES error:&error];
[data writeToFile:file atomically:true];

// Decoding by unarchiving
NSData *readData = [NSFileManager.defaultManager contentsAtPath:file];
error = nil;
MJBag *decodedBag = [NSKeyedUnarchiver unarchivedObjectOfClass:MJBag.class fromData:readData error:&error];
MJExtensionLog(@"name=%@, price=%f", decodedBag.name, decodedBag.price);

Camel -> underline【统一转换属性名(比如驼峰转下划线)】

// Dog
#import "MJExtension.h"

@implementation Dog
+ (NSString *)mj_replacedKeyFromPropertyName121:(NSString *)propertyName
{
    // nickName -> nick_name
    return [propertyName mj_underlineFromCamel];
}
@end

// NSDictionary
NSDictionary *dict = @{
                       @"nick_name" : @"旺财",
                       @"sale_price" : @"10.5",
                       @"run_speed" : @"100.9"
                       };
// NSDictionary -> Dog
Dog *dog = [Dog mj_objectWithKeyValues:dict];

// printing
NSLog(@"nickName=%@, scalePrice=%f runSpeed=%f", dog.nickName, dog.salePrice, dog.runSpeed);

NSString -> NSDate, nil -> @""【过滤字典的值(比如字符串日期处理为NSDate、字符串nil处理为@"")】

// Book
#import "MJExtension.h"

@implementation Book
- (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property
{
    if ([property.name isEqualToString:@"publisher"]) {
        if (oldValue == nil) return @"";
    } else if (property.type.typeClass == [NSDate class]) {
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        fmt.dateFormat = @"yyyy-MM-dd";
        return [fmt dateFromString:oldValue];
    }

    return oldValue;
}
@end

// NSDictionary
NSDictionary *dict = @{
                       @"name" : @"5分钟突破iOS开发",
                       @"publishedTime" : @"2011-09-10"
                       };
// NSDictionary -> Book
Book *book = [Book mj_objectWithKeyValues:dict];

// printing
NSLog(@"name=%@, publisher=%@, publishedTime=%@", book.name, book.publisher, book.publishedTime);

NSDate -> NSString【模型转字典时, 修改 Date 类型至 String】

- (void)mj_objectDidConvertToKeyValues:(NSMutableDictionary *)keyValues {
    // NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // formatter.dateFormat = @"yyy-MM-dd";
    // should use sharedFormatter for better performance  
    keyValues[@"publishedTime"] = [sharedFormatter stringFromDate:self.publishedTime];
}

More use cases【更多用法】

  • Please reference to NSObject+MJKeyValue.h and NSObject+MJCoding.h

期待

  • 如果在使用过程中遇到BUG,希望你能Issues我,谢谢(或者尝试下载最新的框架代码看看BUG修复没有)
  • 如果在使用过程中发现功能不够用,希望你能Issues我,我非常想为这个框架增加更多好用的功能,谢谢
  • 如果你想为MJExtension输出代码,请拼命Pull Requests我
Comments
  • +[NSObject(Property) properties] (NSObject+MJProperty.m:179)

    +[NSObject(Property) properties] (NSObject+MJProperty.m:179)

    #1 Thread SIGSEGV SEGV_ACCERR

    CoreFoundation | -[__NSDictionaryM setObject:forKey:] + 320 -- | -- 1 CoreFoundation | -[__NSDictionaryM setObject:forKey:] + 296 2 XX | +[NSObject(Property) properties] (NSObject+MJProperty.m:179) 3 XX | +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:0) 4 XX | -[NSObject(MJKeyValue) mj_setKeyValues:context:] (NSObject+MJKeyValue.m:197) 5 XX | +[NSObject(MJKeyValue) mj_objectWithKeyValues:context:] (NSObject+MJKeyValue.m:218)

    子线程使用,崩溃次数还是挺高的,系统各个版本都有,+ (NSMutableArray *)properties { @synchronized (self) { } } 函数体加锁还是不行

    opened by daaiwusheng 14
  • 使用MJExtension 上架审核被拒2.5.1,请问是什么原因呢?

    使用MJExtension 上架审核被拒2.5.1,请问是什么原因呢?

    1. 具体信息如下:

    Guideline 2.5.1 - Performance - Software Requirements

    Your app uses or references the following non-public APIs:

    [NSManagedObject allocWithEntity:] and [NSManagedObject allocBatch:withEntity:count:]

    The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change.

    Continuing to use or conceal non-public APIs in future submissions of this app may result in the termination of your Apple Developer account, as well as removal of all associated apps from the App Store.

    Next Steps

    If you are using third-party libraries, please update to the most recent version of those libraries. If you do not have access to the libraries' source, you may be able to search the compiled binary using the "strings" or "otool" command line tools. The "strings" tool can output a list of the methods that the library calls and "otool -ov" will output the Objective-C class structures and their defined methods. These tools can help you narrow down where the problematic code resides. You could also use the "nm" tool to verify if any third-party libraries are calling these APIs.

    Resources

    If there are no alternatives for providing the functionality your app requires, you can file an enhancement request.

    1. 使用终端命令扫描私有API 显示在MJExtension里边

    终端扫描的具体信息如下:

    IMacdeiMac:yjq-ios imac$ grep -lr "NSManagedObject" * | grep -v .svn | grep -v .md Pods/MJExtension/MJExtension/MJFoundation.m Pods/MJExtension/MJExtension/NSObject+MJKeyValue.h Pods/MJExtension/MJExtension/NSObject+MJKeyValue.m

    请问该怎么解决呢?现在一点方向也没有,项目所有的数据都经过了MJExtension。

    opened by kuyona 11
  • 字典数组转模型数组耗时1秒

    字典数组转模型数组耗时1秒

    2017-12-12 10:42:57.781581+0800 MobileArk[2547:552663] Tue Dec 12 10:42:57 2017 2017-12-12 10:42:58.679081+0800 MobileArk[2547:552663] Tue Dec 12 10:42:58 2017

    opened by kongxiaofeng 11
  • 亲爱的,杰哥! objectArrayWithKeyValuesArray解析数据失败.

    亲爱的,杰哥! objectArrayWithKeyValuesArray解析数据失败.

    objectArrayWithKeyValuesArray解析<大众点评json数据>失败!杰哥,我做的是<团购网>ipad的例子.第一次点击城市就可以加载数据.但是再次点击城市pop窗口,就解析失败了.我用你以前的版本就是可以解析的.但是现在这个新版本就有问题.我用你上课的代码测试也是失败的.求解!

    opened by w447207336 11
  • iOS 13  com.apple.main-thread EXC_BAD_ACCESS KERN_PROTECTION_FAILURE

    iOS 13 com.apple.main-thread EXC_BAD_ACCESS KERN_PROTECTION_FAILURE

    作者您好, 感谢您能开发出这么优秀的开源工具. 最近我的 APP 收集到了两个 iOS 13 系统上和 MJExtension 相关的 crash, 只有在 iOS 13 上才出现, 不确定是 APP 这边代码写的有问题或者这个问题能从SDK 上修复. 请您有时间帮忙看一下.

    Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_PROTECTION_FAILURE 0x000000016b4b3f18

    Crashed: com.apple.main-thread 0 CoreFoundation 0x1dac414a0 __CFStringAppendBytes + 588 1 CoreFoundation 0x1dac334e8 __CFStringAppendFormatCore + 12820 2 CoreFoundation 0x1dac33860 _CFStringCreateWithFormatAndArgumentsAux2 + 152 3 Foundation 0x1da7972cc +[NSString stringWithFormat:] + 84 4 UIKitCore 0x1e257581c ___UIBuiltinTraitStorageDescription_block_invoke + 220 5 UIKitCore 0x1e257604c _UIBuiltinTraitStorageEnumeratePairWithBlock + 88 6 UIKitCore 0x1e2575704 _UIBuiltinTraitStorageDescription + 296 7 UIKitCore 0x1e25764a4 -[UITraitCollection _descriptionWithPrivateTraits:] + 64 8 Foundation 0x1da79a9b8 -[NSObject(NSKeyValueCoding) valueForKey:] + 304 9 * 0x1051781e8 -[MJProperty valueForObject:] (MJProperty.m:75) // crash 指向这一行代码 10 * 0x10517c0b8 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:319) 11 * 0x10517e2bc +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 12 * 0x10517be94 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 13 * 0x10517c120 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 14 * 0x10517e2bc +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 15 * 0x10517be94 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 16 * 0x105081c64 -[SRFilterSpirit setSpiritModel:] (SRFilterSpirit.m:68) 17 * 0x105082f44 -[SRFilterSpirit initWithModel:] (SRFilterSpirit.m:246) 18 * 0x105082c50 +[SRFilterSpirit spiritWithModel:] (SRFilterSpirit.m:227) 19 * 0x104cb07c4 -[SRFiltersCtrl displayCategorySelectorWithRefineModel:] (SRFiltersCtrl.m:272) 20 * 0x104cb1914 -[SRFiltersCtrl tableView:didSelectRowAtIndexPath:] (SRFiltersCtrl.m:372) 21 UIKitCore 0x1e2a952f8 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 4354440852 22 UIKitCore 0x1e2a95514 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 4354441504 23 UIKitCore 0x1e28df2a4 _runAfterCACommitDeferredBlocks + 4354450108 24 UIKitCore 0x1e28cf77c _cleanUpAfterCAFlushAndRunDeferredBlocks + 4354440852 25 UIKitCore 0x1e28fe668 _afterCACommitHandler + 4354441504 26 CoreFoundation 0x1dac0eb24 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 4354450108 27 CoreFoundation 0x1dac09a24 __CFRunLoopDoObservers + 4354440852 28 CoreFoundation 0x1dac09ff0 __CFRunLoopRun + 4354441504 29 CoreFoundation 0x1dac097ac CFRunLoopRunSpecific + 4354450108 30 GraphicsServices 0x1d9e0b180 GSEventRunModal + 4354440852 31 UIKitCore 0x1e28d6244 UIApplicationMain + 4354441504 32 * 0x104f6123c main (main.m:16) 33 libdyld.dylib 0x1db15fe7c start + 4354440852

    谢谢.

    duplicate-重复的问题 
    opened by zhangduyu 10
  • setupReplacedKeyFromPropertyName和setupObjectClassInArray不能连续组合使用

    setupReplacedKeyFromPropertyName和setupObjectClassInArray不能连续组合使用

    setupReplacedKeyFromPropertyName和setupObjectClassInArray不能连续组合使用, [HomeModel setupReplacedKeyFromPropertyName:^NSDictionary *{ return @{ @"home_statuses" : @"statuses", @"home_total_number" : @"total_numbe" }; }]; [HomeModel setupObjectClassInArray:^NSDictionary *{ return @{ @"statuses":@"HomeStatusesModel" }; }];

    HomeModel *home = [HomeModel objectWithKeyValues:returnValue];

    HomeStatusesModel里面的东西就解析不到了,不知道能不能补充

    opened by BigBlackApple 10
  • 在Swift项目中保持OC环境来使用MJExtension

    在Swift项目中保持OC环境来使用MJExtension

    Hi,MJ老师: 现在在Swift下通过标题叙述的方法并将Model模型引入到Swift的Bridge Header中也能成功使用这个框架。只是有些方法可能不是表面上那样,比如:

    MJPerson *person = [MJPerson objectWithKeyValues : dictionary];
    

    在Swift中就变成了

    let person = MJPerson(keyValues : dictionary)
    

    而不是很多人想象的

    let persion = MJPerson.objectWithKeyValues(dictinoary)
    

    关于这个方法,我想pr一个example不知是否可行? 还是打算出一个纯Swift版本就不用这样做了?

    opened by WenchaoD 10
  • 使用同一个model解JSON的cache问题

    使用同一个model解JSON的cache问题

    在使用MJExtension的时候,出现一个这样的问题: 定义一个model,比如叫NYGReturnInfoModel, 其中data属性是需要再解析的,即其中会包含其他model @interface NYGReturnInfoModel : NSObject @property (nonatomic, strong) NSNumber *code; @property (nonatomic, strong) NSArray *data;// Contatins 各种Model @property (nonatomic, copy) NSString *message; @property (nonatomic, strong) NSNumber *subcode; @end

    然后使用setupObjectClassInArray去解,此时data对应的model是NYGGameModel,没有问题. [NYGReturnInfoModel setupObjectClassInArray:^NSDictionary *{ return @{ @"data" : @"NYGGameModel" }; }]; NYGReturnInfoModel *gameReturnInfoModel = [NYGReturnInfoModel objectWithKeyValues:responseObject];

    然后再使用setupObjectClassInArray去解另外一个model, 此时data对应NYGObtainedCommentModel,如 [NYGReturnInfoModel setupObjectClassInArray:^NSDictionary *{ return @{ @"data" : @"NYGObtainedCommentModel" }; }]; NYGReturnInfoModel *returnInfoModel = [NYGReturnInfoModel objectWithKeyValues:responseObject];//MJExtension

    此时, 会发现returnInfoModel类型并不是预想的NYGReturnInfoModel, 而是NYGGameModel.

    查看源码发现, 使用了cache. 但是对于这种情况, 使用cache貌似不是一个好的选择?

    期待你的回答.

    opened by rainer-liao 10
  • 发现最新版BOOL值字段转模型有问题,3.0.17之前的都没问题

    发现最新版BOOL值字段转模型有问题,3.0.17之前的都没问题

    描述bug 清晰简单地描述这个bug是啥

    怎么样重现这个bug

    1. 显示哪个页面
    2. 点击哪个位置
    3. 滚动到哪个位置
    4. 发生了什么错误

    你期望的结果是什么? 你本来期望得到的正确结果是怎样的?就是解决bug之后的结果

    截图 如果有必要的话,请上传几张截图

    运行环境

    • iPhone6
    • iOS8.1
    • Xcode10

    额外的 最好能提供出现bug的Demo

    opened by QuintGao 9
  • MJExtension解析字典崩溃

    MJExtension解析字典崩溃

    data = { linkedList = ( { adName = "11111"; adUrl = "http://demo.lanrenzhijia.com/2014/pic0929/images/youku.png"; directContext = 1; directType = 1; id = 10; }, ); }; errorCode = 0; msg = ""; success = 1;

    这个用以下model解析,会有大几率崩溃: @interface ADAnalyzeToDictionaryDto : NSObject @property (nonatomic, strong) NSString *success; @property (nonatomic, strong) NSMutableDictionary *data; @property (nonatomic, strong) NSString *msg; @property (nonatomic, strong) NSString *message; @property (nonatomic, strong) NSString *errorCode; @end

    opened by K-Kevin 9
  • Embedded object with nil properties stops keyValues in parent object

    Embedded object with nil properties stops keyValues in parent object

    Hi,

    I have a parent object

    @interface ParentModel : NSObject

    @property (nonatomic, strong) MusicLibrary *musicLibrary; @property (nonatomic, strong) NSArray *contacts;

    @end

    The music library has the following properties

    @interface MusicLibrary : NSObject

    @property (nonatomic, strong) NSArray *songs; @property (nonatomic, strong) NSArray *plays;

    @end

    If both songs and plays are nil, then contacts in the parent model never gets converted to a dictionary when i call key values. So if all properties in an embedded object are nil it stops iterating through the properties on the parent object at that point.

    What should happen is if songs and plays are nil then contacts should still be converted to the dictionary. Can you have a look at this?

    opened by liamogierussell 9
  • -[MJProperty setValue:forObject:] + [MJProperty.m : 98]

    -[MJProperty setValue:forObject:] + [MJProperty.m : 98]

    出错堆栈如下: 0 libobjc.A.dylib _objc_release_x0 + 8 1 Foundation -[NSObject(NSKeyValueCoding) setValue:forKey:] + 324 2 DuCheng -[MJProperty setValue:forObject:] (MJProperty.m:98) 3 DuCheng __48-[NSObject(MJKeyValue) mj_setKeyValues:context:]_block_invoke (NSObject+MJKeyValue.m:221) 4 DuCheng +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:134) 5 JinJiangDuCheng -[NSObject(MJKeyValue) mj_setKeyValues:context:] (NSObject+MJKeyValue.m:231) 6 DuCheng +[NSObject(MJKeyValue) mj_objectWithKeyValues:context:] (NSObject+MJKeyValue.m:0) 7 DuCheng +[NSObject(MJKeyValue) mj_objectArrayWithKeyValuesArray:context:] (NSObject+MJKeyValue.m:0) 8 DuCheng __48-[NSObject(MJKeyValue) mj_setKeyValues:context:]_block_invoke (NSObject+MJKeyValue.m:0) 9 DuCheng +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:134) 10 DuCheng -[NSObject(MJKeyValue) mj_setKeyValues:context:] (NSObject+MJKeyValue.m:231) 11 JinJiangDuCheng +[NSObject(MJKeyValue) mj_objectWithKeyValues:context:] (NSObject+MJKeyValue.m:0) 12 DuCheng __48-[NSObject(MJKeyValue) mj_setKeyValues:context:]_block_invoke (NSObject+MJKeyValue.m:0) 13 DuCheng +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:134) 14 DuCheng -[NSObject(MJKeyValue) mj_setKeyValues:context:] (NSObject+MJKeyValue.m:231) 15 DuCheng +[NSObject(MJKeyValue) mj_objectWithKeyValues:context:] (NSObject+MJKeyValue.m:0)

    这个错误经常发生在iOS 16.1系统上。请问如何解决?

    opened by AlbertCamusSZB 1
  • 模型转字典,出现问题了

    模型转字典,出现问题了

    就是我的模型里面是一个子模型,但是实际的模型实体类这个子模型是一个数组,现在转出来就不是json了。发现在这里加个判断就好了。if (!type.isFromFoundation && propertyClass),加上![value isKindOfClass:[NSArray class]].麻烦评估一下影响,谢谢

    opened by kedu 2
  • 在Bugly上发现个问题SEGV_ACCERR pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:)

    在Bugly上发现个问题SEGV_ACCERR pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:)

    提示是这个分类 NSObject+MJProperty.m:144 没有找到具体的什么原因!

    详细信息在下方⬇️ pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 1 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 2 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 3 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 4 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 5 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 6 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 7 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 8 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 9 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 10 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 11 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 12 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 13 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 14 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 15 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 16 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 17 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 18 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 19 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 20 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 21 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 22 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 23 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 24 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 25 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 26 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 27 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 28 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 29 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 30 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 31 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 32 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 33 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 34 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 35 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 36 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 37 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 38 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 39 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 40 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 41 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 42 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 43 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 44 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 45 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 46 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 47 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 48 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 49 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 50 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 51 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 52 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 53 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 54 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 55 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 56 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 57 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 58 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 59 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 60 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 61 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 62 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326) 63 pemv260 +[NSObject(Property) mj_enumerateProperties:] (NSObject+MJProperty.m:144) 64 pemv260 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] (NSObject+MJKeyValue.m:390) 65 pemv260 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke (NSObject+MJKeyValue.m:326)

    opened by MyNameZhangXinMiao 1
  • 友盟上偶现的一个崩溃信息 ,[MJProperty valueForObject:] + [MJProperty.m : 78],一直排查不到

    友盟上偶现的一个崩溃信息 ,[MJProperty valueForObject:] + [MJProperty.m : 78],一直排查不到

    CrashDoctor Diagnosis: Stack overflow in (null) Thread 0 Crashed: 0 CoreFoundation 0x000000019d38e56c _NSIsNSArray + [ : 4] 1 CoreFoundation 0x000000019d25dca0 -[NSArray isEqualToArray:] + [ : 96] 2 CoreFoundation 0x000000019d254080 -[__NSDictionaryM objectForKey:] + [ : 184] 3 CoreText 0x000000019e095284 TDescriptorSource::CopySpliceFontForName(__CFString const*, __CFString const*, __CFNumber const*, CTFontLegibilityWeight, __CFNumber const*, __CFString const*, __CFNumber const*) + [ : 384] 4 CoreText 0x000000019e08d644 TDescriptorSource::CopySplicedDescriptorForName(__CFString const*, __CFString const*, __CFString const*, __CFNumber const*, CTFontLegibilityWeight, __CFNumber const*, __CFString const*, __CFNumber const*) const + [ : 136] 5 CoreText 0x000000019e07c4f4 TDescriptor::CreateMatchingDescriptorInternal(__CFSet const*, unsigned long) const + [ : 1764] 6 CoreText 0x000000019e07cd50 TDescriptor::InitBaseFont(unsigned long, double) + [ : 76] 7 CoreText 0x000000019e05e0bc TDescriptor::Hash() const + [ : 56] 8 UIFoundation 0x00000001a09f7f7c -[_UIFontDescriptorCacheKey _hash] + [ : 52] 9 UIFoundation 0x00000001a09f78f0 -[_UIFontCacheKey _precalculateHash] + [ : 32] 10 UIFoundation 0x00000001a09f78a0 +[_UIFontCacheKey fontCacheKeyWithFontDescriptor:pointSize:textStyleForScaling:pointSizeForScaling:maximumPointSizeAfterScaling:textLegibility:] + [ : 200] 11 UIFoundation 0x00000001a0a08b54 +[UIFont _fontWithDescriptor:size:textStyleForScaling:pointSizeForScaling:maximumPointSizeAfterScaling:forIB:legibilityWeight:] + [ : 220] 12 PhotosUI 0x00000001ba8d16e0 -[UIFont(PhotosUI) pu_fontWithMonospacedNumbers] + [ : 456] 13 Foundation 0x000000019d650620 -[NSObject(NSKeyValueCoding) valueForKey:] + [ : 308] 14 MyApp 0x00000001052d9b5c -[MJProperty valueForObject:] + [MJProperty.m : 78] 15 MyApp 0x0000000104f30ff8 __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke + [NSObject+MJKeyValue.m : 364] 16 MyApp 0x000000010525085c +[NSObject(Property) mj_enumerateProperties:] + [NSObject+MJProperty.m : 134] 17 MyApp 0x0000000104f30da8 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] + [NSObject+MJKeyValue.m : 435] 18 MyApp 0x0000000104f3105c __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke + [NSObject+MJKeyValue.m : 371] 19 MyApp 0x000000010525085c +[NSObject(Property) mj_enumerateProperties:] + [NSObject+MJProperty.m : 134] 20 MyApp 0x0000000104f30da8 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] + [NSObject+MJKeyValue.m : 435] 21 MyApp 0x0000000104f3105c __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke + [NSObject+MJKeyValue.m : 371] 22 MyApp 0x000000010525085c +[NSObject(Property) mj_enumerateProperties:] + [NSObject+MJProperty.m : 134] 23 MyApp 0x0000000104f30da8 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] + [NSObject+MJKeyValue.m : 435] 24 MyApp 0x0000000104f3105c __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke + [NSObject+MJKeyValue.m : 371] 25 MyApp 0x000000010525085c +[NSObject(Property) mj_enumerateProperties:] + [NSObject+MJProperty.m : 134] 26 MyApp 0x0000000104f30da8 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] + [NSObject+MJKeyValue.m : 435] 27 MyApp 0x0000000104f3105c __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke + [NSObject+MJKeyValue.m : 371] 28 MyApp 0x000000010525085c +[NSObject(Property) mj_enumerateProperties:] + [NSObject+MJProperty.m : 134] 29 MyApp 0x0000000104f30da8 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] + [NSObject+MJKeyValue.m : 435] 30 MyApp 0x0000000104f3105c __57-[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:]_block_invoke + [NSObject+MJKeyValue.m : 371] 31 MyApp 0x000000010525085c +[NSObject(Property) mj_enumerateProperties:] + [NSObject+MJProperty.m : 134] 32 MyApp 0x0000000104f30da8 -[NSObject(MJKeyValue) mj_keyValuesWithKeys:ignoredKeys:] + [NSObject+MJKeyValue.m : 435]

    opened by wangyanxi2019 14
  • +[NSObject(Property) mj_enumerateProperties:] 崩溃

    +[NSObject(Property) mj_enumerateProperties:] 崩溃

    为了排除你自己的问题, 请写一个 Demo

    线上日志收集到的崩溃,不是必现

    描述bug json转model崩溃,最近收集到不少类似的崩溃,堆栈的末尾基本上都是这种:

    0   libobjc.A.dylib                 0x00007fff6a2a76e5 objc_retain + 21
    1   MJExtension                     0x000000010b001e10 +[NSObject(Property) mj_enumerateProperties:] + 237
    2   MJExtension                     0x000000010affe954 -[NSObject(MJKeyValue) mj_setKeyValues:context:] + 514
    3   MJExtension                     0x000000010afffb1e +[NSObject(MJKeyValue) mj_objectWithKeyValues:context:] + 448
    4   MJExtension                     0x000000010b000004 +[NSObject(MJKeyValue) mj_objectArrayWithKeyValuesArray:context:] + 659
    5   MJExtension                     0x000000010afff14b __48-[NSObject(MJKeyValue) mj_setKeyValues:context:]_block_invoke + 1804
    6   MJExtension                     0x000000010b001e10 +[NSObject(Property) mj_enumerateProperties:] + 237
    7   MJExtension                     0x000000010affe954 -[NSObject(MJKeyValue) mj_setKeyValues:context:] + 514
    8   MJExtension                     0x000000010afffb1e +[NSObject(MJKeyValue) mj_objectWithKeyValues:context:] + 448
    

    都是不同的类调用 mj_objectWithKeyValues 后崩溃,不是某个单独的类。

    运行环境

    • macOS
    • 涉及到从 10.15 ~ 12.3多个系统版本。
    • Xcode 11

    下面是一个崩溃的例子。

    Incident Identifier: 17A7EEF9-0D28-4CB2-BCA5-A8A919307A51
    CrashReporter Key:   4266f94e49333dbf4d60b8498a0f26d7f6a551b6
    Hardware Model:      MacBookAir7,2
    Process:         Tiger Trade [446]
    Path:            /Applications/Tiger Trade.app/Tiger Trade
    Identifier:      com.itiger.TigerTrade-Mac
    Version:         401F0F (7.13.0)
    Code Type:       X86
    Parent Process:  ? [1]
    
    Date/Time:       2022-06-15 22:05:39.166 +0800
    OS Version:      macOS 10.15.5 (19F101)
    Report Version:  104
    
    Exception Type:  EXC_BAD_ACCESS (SIGBUS)
    Exception Codes: KERN_NAME_EXISTS at 0x000000010ca03046
    Crashed Thread:  0
    
    Thread 0 Crashed:
    0   libobjc.A.dylib                 0x00007fff6a2a76e5 objc_retain + 21
    1   MJExtension                     0x000000010b001e10 +[NSObject(Property) mj_enumerateProperties:] + 237
    2   MJExtension                     0x000000010affe954 -[NSObject(MJKeyValue) mj_setKeyValues:context:] + 514
    3   MJExtension                     0x000000010afffb1e +[NSObject(MJKeyValue) mj_objectWithKeyValues:context:] + 448
    4   MJExtension                     0x000000010b000004 +[NSObject(MJKeyValue) mj_objectArrayWithKeyValuesArray:context:] + 659
    5   MJExtension                     0x000000010afff14b __48-[NSObject(MJKeyValue) mj_setKeyValues:context:]_block_invoke + 1804
    6   MJExtension                     0x000000010b001e10 +[NSObject(Property) mj_enumerateProperties:] + 237
    7   MJExtension                     0x000000010affe954 -[NSObject(MJKeyValue) mj_setKeyValues:context:] + 514
    8   MJExtension                     0x000000010afffb1e +[NSObject(MJKeyValue) mj_objectWithKeyValues:context:] + 448
    9   Tiger Trade                     0x0000000109b8bbf3 0x1098d4000 + 2849779 +[TBStockDayTrendModel trendModelWithKeyValues:security:] (in Tiger Trade) (TBStockTrendModel.m:316)
    10  Tiger Trade                     0x0000000109b8b698 0x1098d4000 + 2848408 +[TBStockTrendModel trendModelWithKeyValues:security:] (in Tiger Trade) (TBStockTrendModel.m:0)
    11  Tiger Trade                     0x000000010992616a 0x1098d4000 + 336234 __61-[TBTrendChartWork doRequestFullTrendDataWithRequest:isLoop:]_block_invoke (in Tiger Trade) (TBTrendChartWork.m:788)
    12  libdispatch.dylib               0x00007fff6b4016c4 _dispatch_call_block_and_release + 12
    13  libdispatch.dylib               0x00007fff6b402658 _dispatch_client_callout + 8
    14  libdispatch.dylib               0x00007fff6b40dcab _dispatch_main_queue_callback_4CF + 936
    15  CoreFoundation                  0x00007fff320a4f11 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    16  CoreFoundation                  0x00007fff32064d17 __CFRunLoopRun + 2028
    17  CoreFoundation                  0x00007fff32063ece CFRunLoopRunSpecific + 462
    18  HIToolbox                       0x00007fff30ce4abd RunCurrentEventLoopInMode + 292
    19  HIToolbox                       0x00007fff30ce47d5 ReceiveNextEventCommon + 584
    20  HIToolbox                       0x00007fff30ce4579 _BlockUntilNextEventMatchingListInModeWithFilter + 64
    21  AppKit                          0x00007fff2f32c829 _DPSNextEvent + 883
    22  AppKit                          0x00007fff2f32b070 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352
    23  AppKit                          0x00007fff2f31cd7e -[NSApplication run] + 658
    24  AppKit                          0x00007fff2f2eeb86 NSApplicationMain + 777
    25  libdyld.dylib                   0x00007fff6b45bcc9 start + 1
    
    Thread 1:
    0   libsystem_kernel.dylib          0x00007fff6b59f756 __semwait_signal + 10
    1   libsystem_c.dylib               0x00007fff6b522d52 sleep + 41
    2   KSCrash                         0x000000010aef8440 monitorCachedData + 753
    3   libsystem_pthread.dylib         0x00007fff6b660109 _pthread_start + 148
    4   libsystem_pthread.dylib         0x00007fff6b65bb8b thread_start + 15
    
    Thread 2 name:  KSCrash Exception Handler (Secondary)
    Thread 2:
    0   libsystem_kernel.dylib          0x00007fff6b59cdfa mach_msg_trap + 10
    1   KSCrash                         0x000000010aeff895 handleExceptions + 179
    2   libsystem_pthread.dylib         0x00007fff6b660109 _pthread_start + 148
    3   libsystem_pthread.dylib         0x00007fff6b65bb8b thread_start + 15
    
    Thread 3 name:  KSCrash Exception Handler (Primary)
    Thread 3:
    0   (null) 0x0000000000000000 0x0 + 0
    
    Thread 4 name:  com.apple.NSEventThread
    Thread 4:
    0   libsystem_kernel.dylib          0x00007fff6b59cdfa mach_msg_trap + 10
    1   CoreFoundation                  0x00007fff32065f85 __CFRunLoopServiceMachPort + 247
    2   CoreFoundation                  0x00007fff32064a52 __CFRunLoopRun + 1319
    3   CoreFoundation                  0x00007fff32063ece CFRunLoopRunSpecific + 462
    4   AppKit                          0x00007fff2f4ce144 _NSEventThread + 132
    5   libsystem_pthread.dylib         0x00007fff6b660109 _pthread_start + 148
    6   libsystem_pthread.dylib         0x00007fff6b65bb8b thread_start + 15
    
    Thread 5 name:  com.apple.NSURLConnectionLoader
    Thread 5:
    0   libsystem_kernel.dylib          0x00007fff6b59cdfa mach_msg_trap + 10
    1   CoreFoundation                  0x00007fff32065f85 __CFRunLoopServiceMachPort + 247
    2   CoreFoundation                  0x00007fff32064a52 __CFRunLoopRun + 1319
    3   CoreFoundation                  0x00007fff32063ece CFRunLoopRunSpecific + 462
    4   CFNetwork                       0x00007fff308f002a CFHTTPMessageGetTypeID + 82234
    5   Foundation                      0x00007fff346f47a2 __NSThread__start__ + 1064
    6   libsystem_pthread.dylib         0x00007fff6b660109 _pthread_start + 148
    7   libsystem_pthread.dylib         0x00007fff6b65bb8b thread_start + 15
    
    Thread 6 name:  com.apple.CFStream.LegacyThread
    Thread 6:
    0   libsystem_malloc.dylib          0x00007fff6b613fdd default_zone_calloc + 49
    1   libsystem_malloc.dylib          0x00007fff6b613f59 malloc_zone_calloc + 99
    2   libsystem_malloc.dylib          0x00007fff6b613ed9 calloc + 24
    3   libdispatch.dylib               0x00007fff6b42c60d _dispatch_continuation_alloc_from_heap + 72
    4   libdispatch.dylib               0x00007fff6b40594a dispatch_channel_async + 231
    5   CoreFoundation                  0x00007fff320e2468 _cfstream_shared_signalEventSync + 357
    6   CoreFoundation                  0x00007fff32065de2 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    7   CoreFoundation                  0x00007fff32065d81 __CFRunLoopDoSource0 + 103
    8   CoreFoundation                  0x00007fff32065b9b __CFRunLoopDoSources0 + 209
    9   CoreFoundation                  0x00007fff320648ca __CFRunLoopRun + 927
    10  CoreFoundation                  0x00007fff32063ece CFRunLoopRunSpecific + 462
    11  CoreFoundation                  0x00007fff320e1fd0 _legacyStreamRunLoop_workThread + 251
    12  libsystem_pthread.dylib         0x00007fff6b660109 _pthread_start + 148
    13  libsystem_pthread.dylib         0x00007fff6b65bb8b thread_start + 15
    
    Thread 7 name:  com.apple.CFSocket.private
    Thread 7:
    0   libsystem_kernel.dylib          0x00007fff6b5a50fe select$DARWIN_EXTSN + 10
    1   libsystem_pthread.dylib         0x00007fff6b660109 _pthread_start + 148
    2   libsystem_pthread.dylib         0x00007fff6b65bb8b thread_start + 15
    
    Thread 8 name:  JavaScriptCore bmalloc scavenger
    Thread 8:
    0   libsystem_kernel.dylib          0x00007fff6b59f882 __psynch_cvwait + 10
    1   libc++.1.dylib                  0x00007fff6872f623 std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >) + 93
    2   JavaScriptCore                  0x00007fff36864be5 bmalloc::Scavenger::threadRunLoop() + 741
    3   JavaScriptCore                  0x00007fff368645f9 bmalloc::Scavenger::threadEntryPoint(bmalloc::Scavenger*) + 9
    4   JavaScriptCore                  0x00007fff36866cd7 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(bmalloc::Scavenger*), bmalloc::Scavenger*> >(void*) + 39
    5   libsystem_pthread.dylib         0x00007fff6b660109 _pthread_start + 148
    6   libsystem_pthread.dylib         0x00007fff6b65bb8b thread_start + 15
    
    Thread 9 name:  com.apple.coreanimation.render-server
    Thread 9:
    0   libsystem_kernel.dylib          0x00007fff6b59cdfa mach_msg_trap + 10
    1   QuartzCore                      0x00007fff3db71f7e CA::Render::Server::server_thread(void*) + 496
    2   QuartzCore                      0x00007fff3db71d87 thread_fun(void*) + 25
    3   libsystem_pthread.dylib         0x00007fff6b660109 _pthread_start + 148
    4   libsystem_pthread.dylib         0x00007fff6b65bb8b thread_start + 15
    
    Thread 10 name:  CVDisplayLink
    Thread 10:
    0   libsystem_kernel.dylib          0x00007fff6b59f882 __psynch_cvwait + 10
    1   CoreVideo                       0x00007fff33ff6d2b CVDisplayLink::waitUntil(unsigned long long) + 229
    2   CoreVideo                       0x00007fff33ff6238 CVDisplayLink::runIOThread() + 482
    3   libsystem_pthread.dylib         0x00007fff6b660109 _pthread_start + 148
    4   libsystem_pthread.dylib         0x00007fff6b65bb8b thread_start + 15
    
    Thread 11:
    0   libsystem_kernel.dylib          0x00007fff6b59e4ce __workq_kernreturn + 10
    1   libsystem_pthread.dylib         0x00007fff6b65bb77 start_wqthread + 15
    
    Thread 12:
    0   libsystem_kernel.dylib          0x00007fff6b59e4ce __workq_kernreturn + 10
    1   libsystem_pthread.dylib         0x00007fff6b65bb77 start_wqthread + 15
    
    Thread 13:
    0   libsystem_kernel.dylib          0x00007fff6b59e4ce __workq_kernreturn + 10
    1   libsystem_pthread.dylib         0x00007fff6b65bb77 start_wqthread + 15
    
    Thread 14:
    0   libsystem_kernel.dylib          0x00007fff6b59e4ce __workq_kernreturn + 10
    1   libsystem_pthread.dylib         0x00007fff6b65bb77 start_wqthread + 15
    
    Thread 15:
    0   libsystem_kernel.dylib          0x00007fff6b59e4ce __workq_kernreturn + 10
    1   libsystem_pthread.dylib         0x00007fff6b65bb77 start_wqthread + 15
    
    Thread 16:
    0   libsystem_kernel.dylib          0x00007fff6b59e4ce __workq_kernreturn + 10
    1   libsystem_pthread.dylib         0x00007fff6b65bb77 start_wqthread + 15
    
    Thread 17:
    0   libsystem_kernel.dylib          0x00007fff6b59e4ce __workq_kernreturn + 10
    1   libsystem_pthread.dylib         0x00007fff6b65bb77 start_wqthread + 15
    
    Thread 18:
    0   libsystem_kernel.dylib          0x00007fff6b59e4ce __workq_kernreturn + 10
    1   libsystem_pthread.dylib         0x00007fff6b65bb77 start_wqthread + 15
    
    Thread 0 crashed with X86_64 Thread State:
       rax: 0x00007ffffffffff8    rbx: 0x0000600003f31200    rcx: 0x0100000000000000    rdx: 0x041dffff89a1ba29 
       rdi: 0x8000600001f9e790    rsi: 0x00007fff756f6add    rbp: 0x00007ffee6329af0    rsp: 0x00007ffee63297e8 
        r8: 0x0000000000000010     r9: 0x00000000000007fb    r10: 0x00007fff89a1d328    r11: 0x00007fff3202ba74 
       r12: 0x0000000000000001    r13: 0x00007fff6a2a76d0    r14: 0x8000600001f9e790    r15: 0x0000000000000001 
       rip: 0x00007fff6a2a76e5 rflags: 0x0000000000010246     cs: 0x000000000000002b     fs: 0x0000000000000000 
        gs: 0x0000000000000000 
    
    Binary Images: *
    
    Extra Information:
    
    Stack Dump (0x00007ffee6329798-0x00007ffee6329888):
    
    00782A6AFF7F0000E09732E6FE7F000085CCFF0A01000000189C32E6FE7F000060DA1D01006000000100000000000000189C32E6FE7F00000000000000000000E1546F75FF7F0000F09A32E6FE7F000051ECFF0A0100000001000000000000000040EE0A010000000042EE0A010000000000000000000000FFFFFFFFFFFFFFFF58BD2C010060000090F43232FF7F00000000000000000000000000000000000000000000000000000000000000000000000000000000000000205F92FF7F000020000000000000000040EE0A010000000100000000000000909832E6FE7F00005740616BFF7F000020548E89FF7F0000
    
    Notable Addresses:
    {
        "r10": {
            "address": 140735502471976,
            "class": "__NSSingleObjectArrayI",
            "type": "objc_class"
        },
        "rip": {
            "address": 140734974555877,
            "class": "NSString",
            "type": "objc_object",
            "value": ""
        },
        "rsi": {
            "address": 140735163624157,
            "class": "NSDate",
            "type": "objc_object",
            "value": 6.95324e-310
        },
        "stack@0x7ffee63297a8": {
            "address": 4479503493,
            "class": "NSString",
            "type": "objc_object",
            "value": "eeeilBXs"
        },
        "stack@0x7ffee6329878": {
            "address": 140734994923607,
            "class": "NSNumber",
            "type": "objc_object",
            "value": 5.49746e+11
        }
    }
    
    Application Stats:
    {
        "active_time_since_last_crash": 37246.2,
        "active_time_since_launch": 37246.2,
        "application_active": true,
        "application_in_foreground": true,
        "background_time_since_last_crash": 0,
        "background_time_since_launch": 0,
        "launches_since_last_crash": 2,
        "sessions_since_last_crash": 2,
        "sessions_since_launch": 1
    }
    
    CrashDoctor Diagnosis: Attempted to dereference garbage pointer 0x10ca03046.
    
    
    opened by JyHu 1
Releases(3.4.1)
Owner
M了个J
CEO of The Seemygo.
M了个J
ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects to and from JSON.

ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects (classes and structs) to and from J

Tristan Himmelman 9k Jan 2, 2023
JSONNeverDie - Auto reflection tool from JSON to Model, user friendly JSON encoder / decoder, aims to never die

JSONNeverDie is an auto reflection tool from JSON to Model, a user friendly JSON encoder / decoder, aims to never die. Also JSONNeverDie is a very important part of Pitaya.

John Lui 454 Oct 30, 2022
JSONExport is a desktop application for Mac OS X which enables you to export JSON objects as model classes with their associated constructors, utility methods, setters and getters in your favorite language.

JSONExport JSONExport is a desktop application for Mac OS X written in Swift. Using JSONExport you will be able to: Convert any valid JSON object to a

Ahmed Ali 4.7k Dec 30, 2022
JSONHelper - ✌ Convert anything into anything in one operation; JSON data into class instances, hex strings into UIColor/NSColor, y/n strings to booleans, arrays and dictionaries of these; anything you can make sense of!

JSONHelper Convert anything into anything in one operation; hex strings into UIColor/NSColor, JSON strings into class instances, y/n strings to boolea

Baris Sencan 788 Jul 19, 2022
Magical Data Modeling Framework for JSON - allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS and tvOS apps.

JSONModel - Magical Data Modeling Framework for JSON JSONModel allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS

JSONModel 6.9k Dec 8, 2022
Magical Data Modeling Framework for JSON - allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS and tvOS apps.

JSONModel - Magical Data Modeling Framework for JSON JSONModel allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS

JSONModel 6.8k Nov 19, 2021
A tool for fast serializing & deserializing of JSON

FastEasyMapping Overview Requirements Installation CocoaPods Carthage Usage Deserialization Serialization Mapping Attributes Relationships Assignment

Yalantis 554 Nov 17, 2022
HandyJSON is a framework written in Swift which to make converting model objects to and from JSON easy on iOS.

HandyJSON To deal with crash on iOS 14 beta4 please try version 5.0.3-beta HandyJSON is a framework written in Swift which to make converting model ob

Alibaba 4.1k Dec 29, 2022
Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON.

JSONFeed Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON. For more information about this new feed format visit: https:/

Toto Tvalavadze 31 Nov 22, 2021
JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift.

JSEN /ˈdʒeɪsən/ JAY-sən JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift. A JSON, as defined in the EC

Roger Oba 8 Nov 22, 2022
JSON-Practice - JSON Practice With Swift

JSON Practice Vista creada con: Programmatic + AutoLayout Breve explicación de l

Vanesa Giselle Korbenfeld 0 Oct 29, 2021
Ss-json - High-performance json parsing in swift

json 0.1.1 swift-json is a pure-Swift JSON parsing library designed for high-per

kelvin 43 Dec 15, 2022
Swift-json - High-performance json parsing in swift

json 0.1.4 swift-json is a pure-Swift JSON parsing library designed for high-per

kelvin 43 Dec 15, 2022
The only Connect API library you'd ever need

ConnectKit A Swift client for Infinite Flight's Connect APIs, built using the Network framework. Supported APIs IF Session Discovery Connect API V2 Op

Alexander Nikitin 7 Dec 14, 2022
🌟 Super light and easy automatic JSON to model mapper

magic-mapper-swift ?? Super light and easy automatic JSON to model mapper Finish writing README.md Ability to map NSManagedObject Ability to convert m

Adrian Mateoaea 26 Oct 6, 2019
Mappable - Flexible JSON to Model converter, specially optimized for immutable properties

Mappable is a lightweight, flexible, easy-to-use framework to convert JSON to model, specially optimized for immutable property initializatio

Leave 27 Aug 26, 2022
JOP is the Json organization program. It can run on any platform that supports Swift.

JOP JOP is a program organized in JSON files. It is based on Swift, provides a syntax similar to Swift, and has the same strong security as Swift. Thi

Underthestars-zhy 1 Nov 18, 2021
Codable code is a Swift Package that allows you to convert JSON Strings into Swift structs

Codable code is a Swift Package that allows you to convert JSON Strings into Swift structs.

Julio Cesar Guzman Villanueva 2 Oct 6, 2022
Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable

Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable. Elevate should no longer be used for

Nike Inc. 611 Oct 23, 2022