2016-08-23 3 views
0

以下のコードはiPhone 6と5Sシミュレータでは完全に機能しますが、iPhone 5シミュレータでこのコードを実行しようとすると、これらのコード行は機能しません。iPhone 5のカスタム辞書の値を設定しない

self.groupCollection[creditCadKey] = creditCard 
self.groupCollection[homeKey] = home 
self.groupCollection[boletoKey] = boleto 

辞書の値は変更されず、空のままです。私はこれがなぜ起こっているのか分からない。ここでは、完全なコード:

import Foundation 

public class Checkout_GroupedPaymentSystem : NSObject { 
    public var creditCard: [Checkout_PaymentSystem]? 
    public var home: [Checkout_PaymentSystem]? 
    public var voucher: [Checkout_PaymentSystem]? 
    public var boleto: [Checkout_PaymentSystem]? 

    public let creditCadKey = "Cartão de Crédito" 
    public let homeKey = "Pagamento em Casa" 
    public let voucherKey = "Voucher" 
    public let boletoKey = "Boleto Bancário" 

    public var groupCollection: [String:[Checkout_PaymentSystem]] = [:] 

    public init(fromDictionary dictionay: NSDictionary) { 

     if let creditCardArray = dictionay[creditCadKey] as? [NSDictionary]{ 
      creditCard = [Checkout_PaymentSystem]() 
      for dic in creditCardArray { 
       let value = Checkout_PaymentSystem(fromDictionary: dic) 
       creditCard?.append(value) 
      } 
      self.groupCollection[creditCadKey] = creditCard 
     } 


     if let homeArray = dictionay[homeKey] as? [NSDictionary]{ 
      home = [Checkout_PaymentSystem]() 
      for dic in homeArray { 
       let value = Checkout_PaymentSystem(fromDictionary: dic) 
       home?.append(value) 
      } 

      self.groupCollection[homeKey] = home 
     } 

     if let voucherArray = dictionay[voucherKey] as? [NSDictionary]{ 
      voucher = [Checkout_PaymentSystem]() 
      for dic in voucherArray { 
       let value = Checkout_PaymentSystem(fromDictionary: dic) 
       voucher?.append(value) 
      } 

      //self.groupCollection[voucherKey] = voucher 
     } 

     if let boletoArray = dictionay[boletoKey] as? [NSDictionary]{ 
      boleto = [Checkout_PaymentSystem]() 
      for dic in boletoArray { 
       let value = Checkout_PaymentSystem(fromDictionary: dic) 
       boleto?.append(value) 
      } 

      self.groupCollection[boletoKey] = boleto 
     } 
    } 
} 
+0

あなたは問題がiOSの異なるバージョンではありませんか?各シミュレータで使用しているiOSのバージョンは何ですか? initの辞書パラメータを印刷して、毎回同じエントリがあることを確認してください。 – deadbeef

+0

私はすべてのシミュレータでiOS 9.3を使用しています。また、辞書は常に同じです。 –

答えて

0

このすべてを行うずっと...ずっと簡単な方法があります:

import Foundation 

public class Checkout_GroupedPaymentSystem : NSObject { 
    public static let creditCardKey = "Cartão de Crédito" 
    public static let homeKey = "Pagamento em Casa" 
    public static let voucherKey = "Voucher" 
    public static let boletoKey = "Boleto Bancário" 

    public var creditCards: [Checkout_PaymentSystem]? 
    public var homes: [Checkout_PaymentSystem]? 
    public var vouchers: [Checkout_PaymentSystem]? 
    public var boletos: [Checkout_PaymentSystem]? 

    public var groupCollection: [String:[Checkout_PaymentSystem]] = [:] 

    public init(fromDictionary dictionary: NSDictionary) { 
     guard let creditCardArray = dictionary[creditCardKey] as? [NSDictionary], 
      let homeArray = dictionary[homeKey] as? [NSDictionary], 
      let voucherArray = dictionary[voucherKey] as? [NSDictionary], 
      let boletoArray = dictionary[boletoKey] as? [NSDictionary]else { 
      fatalError("One of these is nil or is the wrong type.") 
     } 

     self.creditCards = creditCardArray.map{ Checkout_PaymentSystem(fromDictionary: $0) } 
     self.homes = homeArray.map{ Checkout_PaymentSystem(fromDictionary: $0) } 
     self.vouchers = voucherArray.map{ Checkout_PaymentSystem(fromDictionary: $0) } 
     self.botelo = boletoArray.map{ Checkout_PaymentSystem(fromDictionary: $0) } 

     self.groupCollection = [ 
      creditCardKey: self.creditCards, 
      homeKey: self.creditCards, 
      voucherKey: self.creditCards, 
      boletoKey: self.creditCards, 
     ] 
    } 
} 
+0

この男にはおなじみのチェックマークを付けてください! – ospahiu

+0

私はまだこの解決策と同じ問題に直面しています。また、initの辞書パラメータはnilでもよいし、いくつかのnilキーを持つこともできます。 –

+0

問題を詳しく説明できますか? – Alexander

関連する問題