PDA

View Full Version : NSString to NSSize




larswik
May 28, 2013, 06:20 PM
Hey, I am scratching my head solving this. I have a QTMovie object and I am using the Method 'movieAttributes' to get the Attributes of the object. It returns an NSDictionary and it NSLogs just fine.

The returned NSDictionary is holding NSStrings and I am interested in QTMovieCurrentSizeAttribute. When I NSLog the Dict it prints this


QTMovieCurrentSizeAttribute = "NSSize: {1920, 1080}";


I need to convert this NSString to an NSSize struct. It says it is NSSize.

I know this wont work since it is an NSString, but how do I convert a String to a struct?


NSSize frameSize = [qtDict objectForKey:@"QTMovieCurrentSizeAttribute"];


Is there an easier way to convert it besides spiting up the string?



larswik
May 28, 2013, 06:54 PM
I found the answer with a little further reading in the Docs. Although it returns an NSDictinalry with strings I could use the NSValue, stated here in the docs

The current time of a QTMovie object; the value for this key is of type NSValue, interpreted as a QTTime structure.
This attribute can be read and written. This attribute can be read and written when the movie has been initialized with QTMovieOpenForPlaybackAttribute set to YES.


So needing this (incorrect code)

NSSize frameSize = [qtDict objectForKey:@"QTMovieNaturalSizeAttribute"];


it is accomplished like this


NSValue *xyData = [qtAtributesDict objectForKey:QTMovieNaturalSizeAttribute];
NSSize xySize = [xyValue sizeValue];
NSLog(@"Frame Size: %.0f : %.0f", xySize.width, xySize.height);


In case anyone else runs in to this issue, that is how I solved it.