<commit_before>//
//  ViewController.swift
//  Mapping
//
//  Created by 郑林琴 on 16/10/10.
//  Copyright © 2016年 Ice Butterfly. All rights reserved.
//

import UIKit
import MappingAce

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        struct UserArrayPhoneEntity: Mapping{
            var age: Int?
            var name: String?
            var phone: PhoneNumber
            var phones: [PhoneNumber]
        }
        
        struct PhoneNumber: Mapping {
            var tel: String
            var type: String
        }
        
        
        let phone: [String : Any] = [
            "tel": "186xxxxxxxx",
            "type": "work"
        ]
        
        let phones = Array(repeating: phone, count: 10)
        let dic: [String : Any] = [
            "age" : 14.0,
            "name": "Binglin",
            "phone": phone,
            "phones": phones
        ]
        
        let age = dic["age"]!
        print(type(of: age))
        
        
        for _ in 0..<150{
//            DispatchQueue.global().async {
            let user = UserArrayPhoneEntity.init(fromDic: dic)
            print(user)
//            }
        }
        
    }<commit_msg>give an simple example in ViewController<commit_after>//
//  ViewController.swift
//  Mapping
//
//  Created by 郑林琴 on 16/10/10.
//  Copyright © 2016年 Ice Butterfly. All rights reserved.
//

import UIKit
import MappingAce

class ViewController: UIViewController {

    struct PhoneNumber: Mapping {
        var tel: String
        var type: String
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.testStructMapping()
        self.testStructMappingWithDefaultValue()
    }
    
    
    func testStructMapping(){
        
        struct UserArrayPhoneEntity: Mapping{
            var age: Int?
            var name: String?
            var phone: PhoneNumber
            var phones: [PhoneNumber]
        }
        
        
        let phone: [String : Any] = [
            "tel": "186xxxxxxxx",
            "type": "work"
        ]
        
        let phones = Array(repeating: phone, count: 10)
        let dic: [String : Any] = [
            "age" : 14.0,
            "name": "Binglin",
            "phone": phone,
            "phones": phones
        ]
        
        let user = UserArrayPhoneEntity(fromDic: dic)
        
        let serialized = user.toDictionary()
            
        print(serialized)
        
    }
    
    func testStructMappingWithDefaultValue(){
        
        struct UserArrayPhoneEntity: InitMapping{
            var age: Int?
            var name: String = "default"
            var phone: PhoneNumber?
            var phones: [PhoneNumber] = []
        }
        
        struct PhoneNumber: Mapping {
            var tel: String
            var type: String
        }
        
        
        let phone: [String : Any] = [
            "tel": "186xxxxxxxx",
            "type": "work"
        ]
        
        let phones = Array(repeating: phone, count: 10)
        let dic: [String : Any] = [
            "age" : 14.0,
            "phone": phone,
            "phones": phones
        ]

        let user = UserArrayPhoneEntity(fromDic: dic)
        let serialized = user.toDictionary()
        print(serialized)

    }
    
    
{'fraction_non_alphanumeric': 0.09730050430139424, 'fraction_numerical': 0.014239098190447939, 'mean_word_length': 1.3239145416953826, 'pattern_counts': {'":': 14, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, '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': '6246356', 'n_tokens_mistral': 996, 'n_tokens_neox': 929, 'n_words': 244}