NSDictionaryOfVariableBindings swift等价? [英] NSDictionaryOfVariableBindings swift equivalent?
问题描述
Apple文档显示UIKit参考的创建字典部分下的空白空间这里。
The Apple documentation shows an unsettling blank space under the 'Creating a Dictionary' section of the UIKit reference here.
有没有人找到 NSDictionaryOfVariableBindings
宏的替代品,或者我们是否只想写自己的?
Has anyone found a replacement for the NSDictionaryOfVariableBindings
macro, or are we expected to just write our own?
编辑 - 根据这个或许正确的方法是编写一个全局函数来处理这个问题?看起来复杂的宏完全不存在。
EDIT - According to this perhaps the right approach is to write a global function to handle this? Looks like complex macros are out entirely.
推荐答案
根据Apple源代码:
According to Apple source code:
NSDictionaryOfVariableBindings(v1,v2,v3)相当于[NSDictionary dictionaryWithObjectsAndKeys:v1,@v1,v2,@v2,v3,@v3,nil];
NSDictionaryOfVariableBindings(v1, v2, v3) is equivalent to [NSDictionary dictionaryWithObjectsAndKeys:v1, @"v1", v2, @"v2", v3, @"v3", nil];
所以在Swift中你也可以这样做:
So in Swift you can do the same using:
let bindings = ["v1": v1, "v2": v2, "v3": v3]
这篇关于NSDictionaryOfVariableBindings swift等价?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!