2017-11-18 10 views
0

ここで私がキー値のペアtitleDiscountで始まる単語を持っているかどうかを調べる必要のあるモデルクラスからJsonデータを取得しています。たとえば、Discountで始まるキー値のペアが見つかった場合特定のテーブルを設定する必要があります表示セルのラベルDiscountどのようにキー値のペアからそれを見つける誰も私を助けることができますこれを実装する方法?ここではここ迅速な名前で特定のキー値を見つける方法3?

は私のモデルクラスのデータである

struct TotalPriceSegments { 

    let code : String? 
    let title : String? 
    let value : Double? 

    init(json: [String:Any]) { 

     self.code = json["code"] as? String 
     self.title = json["title"] as? String 
     self.value = json["value"] as? Double 

    } 
} 

テーブルビューコードcellForRow方法で

let cell = tableView.dequeueReusableCell(withIdentifier: "checkout", for: indexPath) as! CheckoutTableViewCell 
      let array = totalPriceModel?.totalSegments[indexPath.row] 
      cell.titleLabel.text = array?.title 
      let total = doubleToStringDecimalPlacesWithDouble(number: Double((array?.value)!), numberOfDecimalPlaces: 2) 
      cell.valueLabel.text = (String(describing:("$ \(total)"))) 
      return cell 
+0

可能な重複辞書キーと値を知ることなく値](https://stackoverflow.com/questions/26989443/swift-reference-to-a-dictionary-kアイ・アンド・バリュー・アウェイ・ノウハウ・キー) – dcorking

答えて

0

は、このようなチェックを追加します:へ[スウィフトリファレンスの

if array?.title.hasPrefix("Discount") { 
    cell.titleLabel.text = "Discount" 
} 
関連する問題