Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

ios - NSDictionaryOfVariableBindings swift equivalent?

The Apple documentation shows an unsettling blank space under the 'Creating a Dictionary' section of the UIKit reference here.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

According to Apple source code:

NSDictionaryOfVariableBindings(v1, v2, v3) is equivalent to [NSDictionary dictionaryWithObjectsAndKeys:v1, @"v1", v2, @"v2", v3, @"v3", nil];

So in Swift you can do the same using:

let bindings = ["v1": v1, "v2": v2, "v3": v3]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...