It is necessary to write an array of structures in Swift, based on existing c ++ code.

c ++:

struct luchnik{ int sila=0, target; float hp=100, udar=0; }; 

Then an array of structures is created.

 luchnik a[20]; 

And the following work with him: Appeal to certain elements, their change, etc. How best to implement it on Swift?
As I understand it, they do not use a similar work scheme.

  • Better to start reading something about the language. Or at least google swift массивы , swift классы . - AivanF.

1 answer 1

I understood nothing, but I will try anyway:

create structure

 struct luchik { let sila=0 let target:Int let hp = 100 let udar = 0 } 

Declare an array that can only contain these structures

 var a = [luchik]() 

work with an array

 let lu:luchik = luchik(target:1) // создать объект (у target нет значения по дефолту, поэтому надо что то присвоить) a.append(lu) // добавить в массив print(a[0].hp) // прочитать из массива значение hp первого элемента