salocinx salocinx - 4 months ago 28x
iOS Question

Swift: How to convert a list of String to a list of CGPoint?

I am a complete newbie to Swift and didn't found anything on the web. How do I convert a string formatted this way:

let str:String = "0,0 624,0 624,-48 672,-48 672,192"

to an array of CGPoint's ?


This solution uses the CGPointFromString function provided by iOS.

import UIKit

let res = str.componentsSeparatedByString(" ").map { CGPointFromString("{"+$0+"}") }