如何在Swift 4中制作一定大小的数组? [英] How to make an array of certain size in Swift 4?

查看:379
本文介绍了如何在Swift 4中制作一定大小的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何制作一个简单的数组,比如说1000个浮点数?我已经尝试过了:

How do I make a simple array of say 1000 floats? I have tried this:

var computeArray = Array<Float>(repeating: nil, count:1000)

并获得

表达式类型不明确,没有更多上下文

Type of expression is ambiguous without more context

我也尝试过这样做,并且得到了同样的东西:

I also tried this and got the same thing:

var computeArray = [Float](repeating: nil, count:1000)

它是如此简单,但我无法使其正常工作.这些基本上与我在网上找到的示例相同.最新的Swift 4有什么改变吗?

It's so simple but I can't get it to work. These are basically the same as examples I've found online. Has something changed with the most recent Swift 4?

推荐答案

尝试一下.

var computeArray: Array<Float> = Array(repeating: 0, count: 1000)

或带有nil

var computeArray: Array<Float?> = Array(repeating: nil, count: 1000)

这篇关于如何在Swift 4中制作一定大小的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆