ios
ios

Reputation: 6164

How to Convert data obtained from Sqlite database into NSArray to NSData in iPhone SDK

In My iPhone App,

I am converting my image in to NSData format and storing it into sqlite database Table in dataType="BLOB",

But, I am retriving that image (stored in NSData format) into NSArray Format from database,

The Problem is I am not able to convert NSArray to NSData ( Which would Help me to get my image back into NSData format )

Please Help and Suggest, Thanks

Upvotes: 2

Views: 1012

Answers (3)

aelam
aelam

Reputation: 2916

Your requirement is so odd.

  1. you can store image in local file system with the file name in sqlite
  2. if you really want images store in sqlite, you can every image in sqlite separately rather than archive images in NSArray than convert to NSData

Upvotes: 1

mrburns05
mrburns05

Reputation: 11

UIImage *imgData = [UIImage imageWithData:[yourArray objectAtIndex:theIndex]];

for multiple images in one array you can loop it

like

for (int i = 0;i<[yourArray count];i++) {
      UIImage *img = [UIImage imageWithData:[yourArray objectAtIndex:i];
      //do something here with each image
      // for example, add it to an ImageView
}

P.S. if theres only one image, its index is 0 hope this helps

Upvotes: 0

Andiih
Andiih

Reputation: 12413

Use NSKeyedArchiver How to convert NSArray to NSData?

Upvotes: 0

Related Questions