• Home
  • iPhone
  • Exploring the Foundation Framework in in iPhone - NS Data Class

Exploring the Foundation Framework in in iPhone - NS Data Class

  • (4.0)
  • | 1336 Ratings


NSData and its mutable subclass NSMutableData provide data objects, object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation Objects.

NSData creates static Data Objects, and NSMutableData creates dynamic data objects. NSData and NSMutableData are typically used for data storage and are also useful in Distributed Objects applications, where data contained in data objects can be copied or moved between applications.

Mindmajix Offers iPhone App Development Training with industry experts through online.

The size of the data is subject to a theoretical limit of about 8 ExaBytes (in practice, the limit should not be a factor).

      UIImage *IMG  =[UIImage imageNamed:@  “1.jpg”];
      NSLog (@  “img is %@”,img);

// How to convert image object to data:

NSData*data =  UIImage JPEG Representation (img,1);
NSLog(@  “ image  data is %@”,data);

// converting the png Image object to data:

NSData  *data2  =  UIImage PNGRepresentation  (img);
NSLog (@ “ png Image data is %@”, data2);

//How to know size of an image:

Int size = [data length];
If (size /1024>0)
  NSLog (@  “ image size is %d  kb”,  size/1024);
NSLog (@ “image size is %d Bytes , size);

//how to convert data to image object:

UIImage *img2 = [UIImage ImageWithData : data];
NSLog(@ “the image is %@”,img2);

//how to append data:

NSMutableData*mutData= [[NSMutableData alloc]init];
[MutData appendData : data];
NSLog (@ “the mutable data is %@”, mutData);

//getting URL image as data:

NSData *URL  data = [NSData  datawithContentsOfURL :
[NSURL URLwithString:@”]];
UIImage   *URLImage   =[UIImage ImageWithData : URL data];
NSLog (@ “data length is %d kb ,[URL data length]1024];

//Setting the image as background image for view:

self view background color=[UIColor Color with PatternImage: URLImage];

Frequently Asked iPhone Interview Questions & Answers

Subscribe For Free Demo

Free Demo for Corporate & Online Trainings.

Ravindra Savaram
About The Author

Ravindra Savaram is a Content Lead at His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter. Protection Status