Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGPointFromString, but for OS X

Tags:

macos

ios

porting

I'm trying to follow a tutorial for making an iOS game in SpriteKit, but also simultaneously porting it to OS X. (When I'm making my own game, I intend to do exactly that, plus it helps the learning sink in a little bit more than just copying spoon fed code)

So far, everything has gone spritely (pun intended) and I've been able to troubleshoot or research every problem I've come across, but alas, it could only last so long. It's probably something stupid simple too, but it evades me.

I'm trying to pull in a string from a plist dictionary

self.position = CGPointFromString( [ characterData objectForKey:@"StartLocation"]);

StartLocation is the key for the coordinates, in the format of "{0,0}".

When building for iOS, it works beautifully. When building for OS X, it fails. I believe the issue lies with "CGPointFromString" being unique to the iOS development environment. It only appears in iOS documentation. The thing is, I can't find any OSX equivalents.

I realize that I could PROBABLY get it to work by breaking the coordinates into two float values with two separate dictionary entries for x and y, but I don't know if the writer of the tutorial did this intentionally and that would break something down the road, plus I want to know how to convert from one data type to another on OS X too.

Please help! /Thank you!

like image 935
mredig Avatar asked Nov 12 '13 23:11

mredig


2 Answers

On OSX you have NSPointFromString but not CGPointFromString. You also have NSPointToCGPoint and NSPointFromCGPoint if you want typecast them.

like image 51
Emmanuel Avatar answered Sep 30 '22 05:09

Emmanuel


Not as direct but this works:

NSPoint cocoaPoint = NSPointFromString(theString);
CGPoint point = NSPointToCGPoint(cocoaPoint);
like image 44
Lance Avatar answered Sep 30 '22 06:09

Lance