Saturday, June 1, 2013

NSData initWithData example in Objective C (iOS).


NSData initWithData

Returns a data object initialized with the contents of another data object.

- (id)initWithData:(NSData *)data

Parameters
data
A data object.

Return Value of [NSData initWithData]
A data object initialized with the contents data. The returned object might be different than the original receiver.

NSData initWithData example.
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"Pacific_Map" ofType:@"png"];
NSURL* urlEx = [NSURL fileURLWithPath:imagePath];
NSData* mapExIMGData = [[NSData alloc] initWithContentsOfURL: urlEx];

UIImage* imgEx = [[UIImage alloc] initWithData:mapExIMGData];

mapImageViewEx.image = imgEx;

End of NSData initWithData example article.