salocinx salocinx -5 years ago 258
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 ?

Answer Source

This solution uses the CGPointFromString function provided by iOS.

import UIKit

let res = str.componentsSeparatedByString(" ").map { CGPointFromString("{"+$0+"}") }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download