Is there any feasible/reasonable way to pass the necessary path info for a UIBezierPath from a remote API? I'm interested in downloading shape information at runtime. Here's a dream-code example of what I mean:
CGPath path = [APIClient downloadPathInfoForObject:clock];
UIBezierPath *bPath = [UIBezierPath bezierPathWithCGPath:path];
How would you send path info from an API, and subsequently unpack it to a CGPath?
I'll probably end up using regular images, but it would be cool to use CAShapeLayers throughout the app. Any ideas?
UIBezierPath supports NSCoding so you should be able to serialize it with NSKeyedArchiver, send it and deserialize it with NSKeyedUnarchiver into another UIBezierPath at the other location.
Example
// Get a base64 encoded archive of the path
UIBezierPath *path = UIBezierPath.path;
NSData *pathData = [NSKeyedArchiver archivedDataWithRootObject:path];
NSString *pathString = [pathData base64Encoding]; // Save it to the API
// ...... sometime in the future
NSString *pathString = [APIClient downloadPathForObject:clock]; // Get the string
NSData *pathData = [[NSData alloc] initWithBase64Encoding:pathString];
UIBezierPath *path = [NSKeyedUnarchiver pathData]; // Same path!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With