简单的快速数组追加不起作用 [英] Simple swift array append not working

查看:64
本文介绍了简单的快速数组追加不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这将是超级基础,但是我有这段代码:

I know this is going to be super elementary, but I have this piece of code:

var labels: [String]?

func initVC(image: Images){
    self.image = image

    let tempLabels = image.label?.allObjects as! [Labels]
    for i in 0..<tempLabels.count{
        labels?.append(tempLabels[i].label!)
    }

}

标签在公共范围内,因此该函数应该可以访问它,但是当循环运行时,标签仍然为零,没有任何元素.

labels is in the public scope, so the function should have access to it, but when the loop runs through, labels is still nil with no elements.

当我在调试过程中进行调试时,tempLabels就像我期望的那样包含2个字符串元素.

When I po during debugging, tempLabels is as I expect it to be with 2 string elements.

我很确定这是一个非常简单的问题,但是我想我现在还没有解决.

I'm pretty sure this is a very simple problem, but I guess I'm just out of it right now.

推荐答案

标签从未初始化.更改

var labels:[String]?

var labels:[String] = []

这篇关于简单的快速数组追加不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆