How do I add a CGPoint to NSMutableArray?

前端 未结 6 1903
小蘑菇
小蘑菇 2021-02-01 13:58

I want to store my CGPoint to the NSMutable Array, so , I have method like this:

[self.points addObject:CGPointMake(x, y)];

But I got the error

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 14:31

    Swift 3.x
    // Convert CGPoint to NSValue

    let cgPoint = CGPoint(x: 101.4, y: 101.0)
    let nsValue = NSValue(cgPoint: cgPoint)
    var array = NSArray(object: nsValue)
    

    // Restore it again

    var cgPoint : CGPoint!
    for i in array {
      cgPoint = i as? CGPoint
    }
    

提交回复
热议问题