SwiftDeveloper SwiftDeveloper - 3 months ago 7
Swift Question

How to add new array objects with int value

Hello i have

dynamic
array in my project ;

var firstArray = [FirstArray]()


Also i have another array in my view;

var TypeId = [""]


I want to add
1
objects into
TypeId
array size of
firstArray.count
.


For example : firstArray.count = 7 , TypeId Array output must be = ["1","1","1","1","1","1","1"]


Also how to get TypeId array values to string inside like
1,1,1,1,1,1,1


Thank you !

Answer

If you want typeID array contains the number of element equal to firstArray you can use map like this.

var typeID = firstArray.map { _ in String("1") }

Edit : Join typeID array elements by ,

let typeIDString = typeID.joinWithSeparator(",")