2017-02-19 3 views
-4
if let place = placement?[0] { 

    if place.postalCode != nil { 
     self.currentLocation.text = "Current Location: \(place.postalCode!)" 
     self.currentPostalCode = Int(place.postalCode!) 

     if (district1ZipCodes.contains(self.currentPostalCode) != false) { 
      self.congressionalDistrict.text = "Congressional District: 1st" 
      representatives.insert(String("Steve Chabot(R)"), at: 0) 
     } 
     if (district2ZipCodes.contains(self.currentPostalCode) != false) { 
      self.congressionalDistrict.text = "Congressional District: 2nd" 
      representatives.insert(String("Brad Wenstrup(R)"), at: 0) 
     } 
     if (district3ZipCodes.contains(self.currentPostalCode) != false) { 
      self.congressionalDistrict.text = "Congressional District: 3rd" 
      representatives.insert(String("Joyce Beatty(D)"), at: 0) 
     } 
     if (district3ZipCodes.contains(self.currentPostalCode) != false) { 
      self.congressionalDistrict.text = "Congressional District: 4th" 
      representatives.insert(String("Jim Jordan(R)"), at: 0) 
     } 
     if (district5ZipCodes.contains(self.currentPostalCode) != false) { 
      self.congressionalDistrict.text = "Congressional District: 5th" 
      representatives.insert(String("Robert Latta(R)"), at: 0) 
     } 
     if (district14ZipCodes.contains(self.currentPostalCode) != false) { 
      self.congressionalDistrict.text = "Congressional District: 14th" 
      representatives.insert(String("David Joyce(R)"), at: 0) 
     } 
    } 
} 

私のコードでは、これを実行しているアプリケーションではテーブルにラベルを割り当てるコードがありますが、何らかの理由でこれがループであるかのように何度も繰り返しますが、ifステートメント。それは明らかではないが、私はそれがあなたのコード内の別の場所に座っていると思うので、これは問題に貢献している場合、:)あなたが投稿したコードのこの部分をif文はループのように繰り返していますか?

+0

あなたのコードをさらに表示する必要があります。問題はあなたのコードのどこかにあるようです。 – naglerrr

+0

あなたのコードは読みにくいですが、このコードはどのような関数に含まれていますか?最初の要素に 'representatives.insert(" ... "、at:0)'を挿入し、最も外側の 'if'が最初の要素を扱うので、これらの' insert'が関数を再度トリガした可能性があります。再び –

答えて

0

を私を助けてくださいことは間違っています:

if (district3ZipCodes.contains(self.currentPostalCode) != false) { 
    self.congressionalDistrict.text = "Congressional District: 4th" 
    representatives.insert(String("Jim Jordan(R)"), at: 0) 
} 

ますdistrict3ZipCodesをdistrict4Zipコードの代わりに2回確​​認しています

関連する問題