如果已经讨论过,我很抱歉,但我找不到解决方案
我有一个结构:
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
}
}
我正在尝试为密钥找到一些值(我知道它存在)并将此值的变量更改为另一个。怎么了?
答案 0 :(得分:1)
可能perspective
,imageWidth
或imageHeight
不是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
}
}