20160905, 解Model, 及其Debug ~> Model

20160905, 解Model, 及其Debug ~> Model

解Model



import UIKit

class BannerPicModel: NSObject {

    
    var code: NSNumber?
    var msg: String?
    var data: BPicDataModel?
    
    class func parseModel(withData data: NSData) -> BannerPicModel{
    
//    func parseModel(withData data: NSData) -> BannerPicModel{
    
        print("nihap")
        let bannerPicModel = BannerPicModel()
        let jsonData = try! NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers)
        
        
        
            let dictionary = jsonData as! Dictionary
            
        
            bannerPicModel.setValuesForKeysWithDictionary(dictionary)
            
            
            let dataModel = BPicDataModel()
            
            let dataDictionary = dictionary["data"] as! Dictionary
            
            
            dataModel.setValuesForKeysWithDictionary(dataDictionary)
            
            var itemModels = Array()
            
            let items = dataDictionary["item"] as! Array>

            for item in items {
            
                let itemModel = BPDataItemModel()
                itemModel.setValuesForKeysWithDictionary(item)
                itemModels.append(itemModel)
                
            }
            
            dataModel.item = itemModels
            
            
            let campaignModel = BPDataCampaignModel()
            let campaignDictionary = dataDictionary["campaign"] as! Dictionary
            
            campaignModel.setValuesForKeysWithDictionary(campaignDictionary)
            
            dataModel.campaign = campaignModel
            
            bannerPicModel.data = dataModel
        
            
        
     
        
        
        return bannerPicModel
    
    }
    
    
    
}

class BPicDataModel: NSObject {

    var item: Array?
    var shareUrl: String?
    var campaign: BPDataCampaignModel?
    

}

class BPDataItemModel: NSObject {
    
    
    var itemId: NSNumber?//Int?
    var theme_campaign_id: NSNumber?//Int?
    var dinner_id: NSNumber?//Int?
    
    var type: NSNumber?//Int?
    var show_order: NSNumber?//Int?
    var avaliable: NSNumber?//Int?

    var unit: String?
    var dinner_type: NSNumber?//Int?
    var dinner_imageurl: String?
    

    var dinner_title: String?
    var dinner_district: String?
    var dinner_price: NSNumber?//Int?
    
    
    var dinner_datetime: String?
    var dinner_minCount: NSNumber?//Int?
    var dinner_maxCount: NSNumber?//Int?
    

    var dinner_orderCount: NSNumber?//Int?
    var dinner_endOrderTime: String?
    
    
 
    func setId(itemId: Int){
        
     
        self.itemId = itemId
        
        
    }
    
    
    
    
}

class BPDataCampaignModel: NSObject {
    
    
    var campaignId: NSNumber?//Int?
    var title: String?
    var subtitle: String?
    
    
    var banner_image: String?
    var campaignDescription: String?
    var show_order: NSNumber?//Int?
    
    
    var type: NSNumber?//Int?
    var avaliable: NSNumber?//Int?
    
    
    
    func setId(campaignId: Int){
    
    
        self.campaignId = campaignId
    
    }
    
    
    
    func setDescription(campaignDescription: String){
    
    
    
        self.campaignDescription = campaignDescription
    
    
    
    }
    
    
    
}







你可能感兴趣的:(20160905, 解Model, 及其Debug ~> Model)