ios swift string 类型转化为CGfloat给CGRectMake

     var currentNodeName:String!

    func parser(parser: NSXMLParser, didStartElement elementName: String!, namespaceURI: String!, qualifiedName qName: String!, attributes attributeDict: [NSObject : AnyObject]!)
    {

        currentNodeName = elementName

        if elementName=="background"
        {

            let stringx = attributeDict["x"]! as String
            //if let n = NSNumberFormatter().numberFromString(stringx)
            //{
             //   let x = CGFloat(n)
            //}
            //var y = attributeDict["y"]! as CGFloat
            //var width = attributeDict["width"]! as CGFloat
           var Height = attributeDict["Height"]! as String
            backgroundRect = CGRectMake(0,0,0,0)

        }

    }

从xml里面读出来都是string,怎么转换呢?

自己找到解决办法了,

 let x = CGFloat(((attributeDict["x"]! as String )as NSString).floatValue)
                let y = CGFloat(((attributeDict["y"]! as String ) as NSString).floatValue)
                let Width = CGFloat(((attributeDict["Width"]! as String )as NSString).floatValue)
                let Height = CGFloat(((attributeDict["Height"]! as String ) as NSString).floatValue)

                m_backgroundRect = CGRectMake(x,y,Width,Height)

 let floatValue = Float(stringValue)