How to convert CGPoint in NSValue in swift?

Dharmesh Kheni picture Dharmesh Kheni · Oct 8, 2014 · Viewed 10.2k times · Source

As my question title says how can I convert CGPoint into NSValues so I can store then Into array In swift.

In objective-C we can do it like this:

  // CGPoint converted to NSValue
     CGPoint point = CGPointMake(9, 9);
     NSValue *pointObj = [NSValue valueWithCGPoint:point];

But can anybody tell me that how can I do this in swift?

Thanks In Advance.

Answer

derdida picture derdida · Oct 8, 2014

Try something like that:

let point = CGPointMake(9, 9)
var pointObj = NSValue(CGPoint: point)