[英]how to initialize array in swift
I am completely new in swift and iOS developing. 我是Swift和iOS开发中的新手。 I want to initialize this array
我想初始化这个数组
I defined the array like this when my class starts 我上课时就这样定义了数组
var i = 0
var ArrayTitle = [NSString]()
and then I need to initialize it in one of the functions like this 然后我需要在这样的功能之一中对其进行初始化
let ArrayTitl[i] = "text"
and I checked it even like this but the error is same 我什至这样检查它,但错误是相同的
let ArrayTitl[0] = "text"
but it has this Error Cannot assign to immutable expression of type '[Int]'
但它具有此错误
Cannot assign to immutable expression of type '[Int]'
Appreciate any help. 感谢任何帮助。 thanks
谢谢
You are using a dynamic array so you need to append the value. 您正在使用动态数组,因此需要附加值。
Here's a small exemple: 这是一个小例子:
var arrayTitle = [String]()
arrayTitle.append("text")
print(arrayTitle[0]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.