gpt4 book ai didi

ios - Swift字典更改值的变量

转载 作者:行者123 更新时间:2023-11-29 02:34:34 24 4
gpt4 key购买 nike

很抱歉,如果已经讨论过,但我没有找到解决方案

我有一个结构:

struct Point2D
{
var x: Double = 0.0
var y: Double = 0.0
}

我也有一个类:

class Letter
{
var points3D: Dictionary<String,Point3D> = [:]
var points2D: Dictionary<String,Point2D> = [:]
var edges: Dictionary<String,Edge> = [:]
}

在某些方面:

class GraphicView: UIView {
var letter:Letter!

override func drawRect(rect: CGRect) {
for (name,point3d) in letter.points3D {
//Says String isn't convertable to DictionaryIndex<String,Point2D>
letter.points2D[name]!.x = point3d.x * (perspective / (perspective - point3d.z)) + imageWidth/2
letter.points2D[name]!.y = point3d.y * (perspective / (perspective - point3d.z)) + imageHeight/2
}
}

我正在尝试为键找到一些值(我知道它存在)并将该值的变量更改为另一个。怎么了?

最佳答案

也许 perspectiveimageWidthimageHeight 不是 Double

尝试:

class GraphicView: UIView {
var letter:Letter!

override func drawRect(rect: CGRect) {
for (name,point3d) in letter.points3D {
letter.points2D[name]!.x = point3d.x * (Double(perspective) / (Double(perspective) - point3d.z)) + Double(imageWidth)/2
letter.points2D[name]!.y = point3d.y * (Double(perspective) / (Double(perspective) - point3d.z)) + Double(imageHeight)/2
}
}

关于ios - Swift字典更改值的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26507552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com