aStoryboard.instantiateViewControllerWithIdentifier(" myid")在lldb中返回nil但不返回n​​il [英] aStoryboard.instantiateViewControllerWithIdentifier("myid") returns nil but not nil in lldb

查看:161
本文介绍了aStoryboard.instantiateViewControllerWithIdentifier(" myid")在lldb中返回nil但不返回n​​il的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是迄今为止发生在我身上最奇怪的事情。所以我在单元测试中有以下代码...

This is by far the strangest thing thats happened to me. So I have the code below in a unit test...

let aStoryboard = UIStoryboard(name: "myStoryboard", bundle: nil)
let viewController = aStoryboard.instantiateViewControllerWithIdentifier("myViewController") as? CustomViewController

执行上面的代码并且viewController是nil,好吧可能会发生(它不应该是因为两个标识符都存在,文件链接到测试目标)但是没关系。

The code above is executed and viewController is nil, okay that can happen (it shouldn't be because both identifiers exist and files are linked to test targets) but yeah okay.

这是一个疯狂的部分,当我添加断点时,跳过上面的行然后键入以下内容为lldb

Here's the crazy part, when I add a breakpoint, step over the lines above and then type the following into lldb

viewController = aStoryboard.instantiateViewControllerWithIdentifier("myViewController") as? CustomViewController

viewController分配有内存。怎么样?如果我在lldb中手动添加它,那么它有内存,如果我没有,那么它没有内存,它是单元测试的零。

viewController is allocated with memory. What how? If I manually add this in lldb then it has memory if I don't then it doesn't have memory and it's nil for the unit test.

有人帮助我!

推荐答案


viewController分配内存。怎么回事?如果我在lldb中手动添加这个它有记忆,如果我没有,那么它没有记忆,它没有单位测试。

"viewController is allocated with memory. What how? If I manually add this in lldb then it has memory if I don't then it doesn't have memory and it's nil for the unit test."

在Swift中没有与Objective-C的含义不同。它不是指向NULL的指针。这只是意味着没有适当的价值。更多信息请访问:使用快速语言的null / nil

In Swift nil doesn't mean the same as Objective-C. It's not a pointer to NULL. It just mean absence of proper value. More information here: null / nil in swift language

所以回答你的问题:没有内存为nil变量。

So answering your question: it's fine to have memory for nil variable.

这篇关于aStoryboard.instantiateViewControllerWithIdentifier(" myid")在lldb中返回nil但不返回n​​il的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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