美文网首页
新建一个类

新建一个类

作者: 盖世英雄的梦想 | 来源:发表于2018-09-09 20:08 被阅读0次

    1.新建一个类
    2.属性:
    var name = ""
    var age = ""
    var gender = ""

    3.在建一个类
    4.protocol DealdDataProtocol {
    func returnModelArray(arrayDict : [[String:String]]) ->[StudentModel]
    }

    class DeailData: NSObject ,DealdDataProtocol {

    func returnModelArray(arrayDict: [[String : String]]) -> [StudentModel] {
        var array : [StudentModel] = []
        
        for dict in arrayDict {
            let student = StudentModel()
            student.name = dict["name"] ?? ""
            student.age = dict["age"]!
            student.gender = dict["gender"]!
        
        array.append(student)
        }
        
        return array
        
    }
    

    }

    let s = StudentModel()

        let deal = DeailData()
        
        
        var dictArray : [[String:String]] = []
        
        for _ in 0..<5 {
            
            let dict = ["name":"lily","age":"23","gender":"nv"]
            
            dictArray.append(dict)
    
            
        }
        let arrayModel = deal.returnModelArray(arrayDict: dictArray)
        for model in arrayModel {
            
            print(model.name)
            print(model.age)
            print(model.gender)
            
        }
        print(arrayModel)
        
    
    }
    

    相关文章

      网友评论

          本文标题:新建一个类

          本文链接:https://www.haomeiwen.com/subject/bhmdgftx.html