Swift字典更改值的变量

时间:2014-10-22 12:33:41

标签: ios swift

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

我有一个结构:

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
        }
}

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

1 个答案:

答案 0 :(得分:1)

可能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
        }
}