一切都在游泳,除了当我做一个像"fds"这样的随机字符串时,我如何才能正确有效地使用警卫来防止这种错误?
init(weatherData: [String: AnyObject]) {
city = weatherData["name"] as! String
let weatherDict = weatherData["weather"]![0] as! [String: AnyObject]
description = weatherDict["description"] as! String
icon = weatherDict["icon"] as! String
let mainDict = weatherData["main"] as! [String: AnyObject]
currentTemp = mainDict["temp"] as! Double
humidity = mainDict["humidity"] as! Int
let windDict = weatherData["wind"] as! [String: AnyObject]
windSpeed = windDict["speed"] as! Double
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试更改我的OSX应用程序的窗口颜色.
我发现很少有关于如何做的信息,但我已经看到了一些例子.
我试过了:
在我的AppDelegate:
NSApplication.shared.mainWindow?.backgroundColor = NSColor.black
哪个不起作用.
在我的ViewController中:
self.view.window?.backgroundColor = NSColor.blue
我想要的是while循环运行并生成随机数量的int的随机列表.
import random
randAmount = random.randint(15,20)
randNumber = random.randint(2,5)
numbList = []
lookFor = 3
while len(numbList) < randAmount:
numbList.append(randNumber)
Run Code Online (Sandbox Code Playgroud)
我的输出:
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
Run Code Online (Sandbox Code Playgroud)
为了randNumber重复不同的数字,我该怎么办?
注意:如果数字重复可以.