2016-08-23 9 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

당신에게 문제가 아이폰 OS의 다른 버전없는 확신은? 각 시뮬레이터에서 사용하는 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