<commit_before>MJExtension
===
[![SPM supported](https://img.shields.io/badge/SPM-supported-4BC51D.svg?style=flat)](https://github.com/apple/swift-package-manager)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
![podversion](https://img.shields.io/cocoapods/v/MJExtension.svg)
![Platform](https://img.shields.io/cocoapods/p/MJExtension.svg?style=flat)

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

[📜✍🏻**Release Notes**: more details](https://github.com/CoderMJLee/MJExtension/releases)

## Contents

* [Getting Started 【开始使用】](#Getting_Started)
	* [Features 【能做什么】](#Features)
	* [Installation 【安装】](#Installation)
* [Examples 【示例】](#Examples)
  * [Usage in Swift](#usage_in_swift)
  * [JSON -> Model](#JSON_Model)
  * [JSONString -> Model](#JSONString_Model)
  * [Model contains model](#Model_contains_model)
  * [Model contains model-array](#Model_contains_model_array)
  * [Model name - JSON key mapping](#Model_name_JSON_key_mapping)
  * [JSON array -> model array](#JSON_array_model_array)
  * [Model -> JSON](#Model_JSON)
  * [Model array -> JSON array](#Model_array_JSON_array)
  * [Core Data](#Core_Data)
  * [Coding](#Coding)
  * [Secure Coding](#SecureCoding)
  * [Camel -> underline](#Camel_underline)
  * [NSString -> NSDate, nil -> @""](#NSString_NSDate)
  * [NSDate -> NSString](#NSDate_NSString)
  * [More use cases](#More_use_cases)

---

## <a id="Getting_Started"></a> Getting Started【开始使用】

### <a id="Features"></a> Features【能做什么】
- MJExtension是一套字典和模型之间互相转换的超轻量级框架
* `JSON` --> `Model`、`Core Data Model`
* `JSONString` --> `Model`、`Core Data Model`
* `Model`、`Core Data Model` --> `JSON`
* `JSON Array` --> `Model Array`、`Core Data Model Array`
* `JSONString` --> `Model Array`、`Core Data Model Array`
* `Model Array`、`Core Data Model Array` --> `JSON Array`
* Coding all properties of a model with only one line of code.
    * 只需要一行代码，就能实现模型的所有属性进行Coding / SecureCoding（归档和解档）

### <a id="Installation"></a> Installation【安装】

#### CocoaPods【使用CocoaPods】

```ruby
pod 'MJExtension'
```

#### Carthage

```ruby
github "CoderMJLee/MJExtension"
```

#### Swift Package Manager

Released from [`3.4.0`](https://github.com/CoderMJLee/MJExtension/releases/)

#### Manually【手动导入】

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

## <a id="Examples"></a> Examples【示例】

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

### <a id="usage_in_swift"></a> Usage in Swift [关于在Swift中使用MJExtension] ‼️

> Example: 
>
> - [Model - MJTester.swift](MJExtensionTests/SwiftModel/MJTester.swift)
>
> - [Usage - SwiftModelTests.swift](MJExtensionTests/SwiftModelTests.swift)

```swift
@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`.

> 纯Swift版的JSON与Model转换框架已经开源上架
>
> - [KakaJSON](https://github.com/kakaopensource/KakaJSON)
> - [中文教程](https://www.cnblogs.com/mjios/p/11352776.html)
> - 如果你的项目是用Swift写的Model，墙裂推荐使用[KakaJSON](https://github.com/kakaopensource/KakaJSON)
>   - 已经对各种常用的数据场景进行了大量的单元测试
>   - 简单易用、功能丰富、转换快速

### <a id="JSON_Model"></a> The most simple JSON -> Model【最简单的字典转模型】

```objc
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;<commit_msg>Update Swift usage manual in Chinese.<commit_after>MJExtension
===
[![SPM supported](https://img.shields.io/badge/SPM-supported-4BC51D.svg?style=flat)](https://github.com/apple/swift-package-manager)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
![podversion](https://img.shields.io/cocoapods/v/MJExtension.svg)
![Platform](https://img.shields.io/cocoapods/p/MJExtension.svg?style=flat)

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

[📜✍🏻**Release Notes**: more details](https://github.com/CoderMJLee/MJExtension/releases)

## Contents

* [Getting Started 【开始使用】](#Getting_Started)
	* [Features 【能做什么】](#Features)
	* [Installation 【安装】](#Installation)
* [Examples 【示例】](#Examples)
  * [Usage in Swift](#usage_in_swift)
  * [JSON -> Model](#JSON_Model)
  * [JSONString -> Model](#JSONString_Model)
  * [Model contains model](#Model_contains_model)
  * [Model contains model-array](#Model_contains_model_array)
  * [Model name - JSON key mapping](#Model_name_JSON_key_mapping)
  * [JSON array -> model array](#JSON_array_model_array)
  * [Model -> JSON](#Model_JSON)
  * [Model array -> JSON array](#Model_array_JSON_array)
  * [Core Data](#Core_Data)
  * [Coding](#Coding)
  * [Secure Coding](#SecureCoding)
  * [Camel -> underline](#Camel_underline)
  * [NSString -> NSDate, nil -> @""](#NSString_NSDate)
  * [NSDate -> NSString](#NSDate_NSString)
  * [More use cases](#More_use_cases)

---

## <a id="Getting_Started"></a> Getting Started【开始使用】

### <a id="Features"></a> Features【能做什么】
- MJExtension是一套字典和模型之间互相转换的超轻量级框架
* `JSON` --> `Model`、`Core Data Model`
* `JSONString` --> `Model`、`Core Data Model`
* `Model`、`Core Data Model` --> `JSON`
* `JSON Array` --> `Model Array`、`Core Data Model Array`
* `JSONString` --> `Model Array`、`Core Data Model Array`
* `Model Array`、`Core Data Model Array` --> `JSON Array`
* Coding all properties of a model with only one line of code.
    * 只需要一行代码，就能实现模型的所有属性进行Coding / SecureCoding（归档和解档）

### <a id="Installation"></a> Installation【安装】

#### CocoaPods【使用CocoaPods】

```ruby
pod 'MJExtension'
```

#### Carthage

```ruby
github "CoderMJLee/MJExtension"
```

#### Swift Package Manager

Released from [`3.4.0`](https://github.com/CoderMJLee/MJExtension/releases/)

#### Manually【手动导入】

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

## <a id="Examples"></a> Examples【示例】

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

### <a id="usage_in_swift"></a> Usage in Swift [关于在Swift中使用MJExtension] ‼️

> Example: 
>
> - [Model - MJTester.swift](MJExtensionTests/SwiftModel/MJTester.swift)
>
> - [Usage - SwiftModelTests.swift](MJExtensionTests/SwiftModelTests.swift)

```swift
@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`.[如果要使用 `Bool` 和 `Int` 等 Swfit 专用基本类型, 请使用 `dynamic` 关键字修饰, 类型为 `Non-Optional`, 並且给定初始值.]

> 纯Swift版的JSON与Model转换框架已经开源上架
>
> - [KakaJSON](https://github.com/kakaopensource/KakaJSON)
> - [中文教程](https://www.cnblogs.com/mjios/p/11352776.html)
> - 如果你的项目是用Swift写的Model，墙裂推荐使用[KakaJSON](https://github.com/kakaopensource/KakaJSON)
>   - 已经对各种常用的数据场景进行了大量的单元测试
>   - 简单易用、功能丰富、转换快速

### <a id="JSON_Model"></a> The most simple JSON -> Model【最简单的字典转模型】

```objc
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;
{'fraction_non_alphanumeric': 0.16134222017926914, 'fraction_numerical': 0.004826476672029419, 'mean_word_length': 5.185501066098081, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 83, 'https://': 22, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1901649', 'n_tokens_mistral': 3593, 'n_tokens_neox': 3587, 'n_words': 696}