我正在使用map()for-in循环中的数组函数,如下所示:
let numbers = [2, 4, 6, 8, 10]
for doubled in numbers.map { $0 * 2 } // compile error
{
print(doubled)
}
Run Code Online (Sandbox Code Playgroud)
这会产生编译错误:
使用未解析的标识符'doubled'
但是,如果我将括号用于map()函数,它可以正常工作.即
for doubled in numbers.map ({ $0 * 2 })
{
print(doubled)
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么编译器不会区分尾随函数和循环的代码块,假设这会导致问题?
我正在开发一个应用程序,我正在使用Windows 8 Toast通知
我需要的是显示通知时我需要两个按钮; 第一个被解雇(我们在示例中有这个)和第二个将在我的代码中实现事件,如果用户按下它我需要执行代码应用程序.
这是一个示例,显示Windows 8 Toast通知上的按钮,但我无法重命名(贪睡)按钮文本,并且无法在我的代码中添加其事件处理程序.
string toastXmlString =
"<toast duration=\"long\">\n" +
"<visual>\"<binding template=\"ToastText02\">\n" +
"<text id=\"1\">Alarms Notifications SDK Sample App</text>\n" +
"<text id=\"2\">" + alarmName + "</text>\n" +
"</binding>\n" +
"</visual>\n" +
"<commands scenario=\"alarm\">\n" +
"<command id=\"snooze\"/>\n" +
"<command id=\"dismiss\"/>\n" +
"</commands>\n" +
"</toast>\n";
Run Code Online (Sandbox Code Playgroud)
这是结果:

谢谢