小编Cas*_*sey的帖子

在Init中使用Guard?

一切都在游泳,除了当我做一个像"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)

swift

3
推荐指数
1
解决办法
1129
查看次数

Swift - Cocoa - 改变窗口颜色?

我正在尝试更改我的OSX应用程序的窗口颜色.

我发现很少有关于如何做的信息,但我已经看到了一些例子.

我试过了:

在我的AppDelegate: NSApplication.shared.mainWindow?.backgroundColor = NSColor.black 哪个不起作用.

在我的ViewController中: self.view.window?.backgroundColor = NSColor.blue

例

macos cocoa swift

2
推荐指数
1
解决办法
653
查看次数

使用While循环生成要追加的整数?

我想要的是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重复不同的数字,我该怎么办?

注意:如果数字重复可以.

python

-2
推荐指数
1
解决办法
93
查看次数

标签 统计

swift ×2

cocoa ×1

macos ×1

python ×1