xcode - How to make a function which can allow me to make elements and add them to an array? -


i learning swift basics. exercising self thinking of somethings , making it.

so earlier wanted make function allow me add elements of type "int" in tuple. here code in swift 2.0 syntax made:

    func tuplemaker(t1 t1: int, t2: int) -> (tuple1: int, tuple2: int) {          let tuples = (t1, t2)          return  tuples         } 

so wanted know how make function allow me me make , add elements array. function above allow me add 2 elements in it, tell me how can add many elements in array , tuple want.

thank in advance.

var array: [(int, int)] = [] // create empty mutable array contains tuple of ints  func addtoarray(inout array: [(int, int)], first: int, second: int) {     let tuple = (first, second)     array.append(tuple) }  addtoarray(&array, first: 1, second: 2) addtoarray(&array, first: 3, second: 4)  array // => [(1,2), (3,4)] 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -