2017-09-01 1 views
0

私はいくつかのtextFieldアウトレットコレクションを持っています。私は各コレクションを移動し、各textFieldに枠線を追加したいと思います。私はこのコレクションを一度に正常に行うことができます。しかし、コレクションごとに境界関数を別々に呼び出す必要はありません。アウトレットコレクション

は、私はこれは私がこのような何かをやろうとしている各コレクション

for name in nameCollection { 
    someFunction... 
    } 

のために働く、次のoutletCollections

@IBOutlet var nameCollection: [UITextField]! 
@IBOutlet var phoneCollection: [UITextField]! 

を持っています。

let collections = [nameCollection, phoneCollection] 

for name in collections { 
    someFunction... 
    } 

基本的には、コレクションのリストを提供し、各コレクションのメンバーごとに機能を実行したいと考えています。

+0

あなたはどのような問題に直面していますか?これを行うときのエラーは何ですか? – 3stud1ant3

答えて

1

ちょうどあなたの出口のコレクションを結合:たとえば

let combinedCollection = nameCollection + phoneCollection 

extension UITextField 
{ 
    func doSomething() 
    { 

    } 
} 

class ViewController: UIViewController { 

    @IBOutlet var nameCollection: [UITextField]! 
    @IBOutlet var phoneCollection: [UITextField]! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let combinedCollection = nameCollection + phoneCollection 
     for eachField in combinedCollection 
     { 
      eachField.doSomething() 
     } 
    } 
} 

この例では、各コレクションは、オブジェクトの同じ種類を持っていることを前提としています。

関連する問題