开发者

Easiest way to store a "table" of data in Objective-C for sorting?

Say I have a data table with 3 fields:

uid {1,2,3}
username {john,bob,martha}
address {"1234 asdf way","5432 12th st", "9875 asdf drvie" }

If I wanted the ability to sort on any of these fields, what would be a sugges开发者_如何学运维ted method of storing this data?


You could store it in an NSArray of NSDictionary, then use the method sortedArrayUsingComparator: to sort on any attribute.


Jus create a class

    @interface Bio:nsobject
     {
     NSString * UID;
     NSString * Username;
     NSString * Address;
     }
   @end

  -(NSMutableArray *) GetALLBio()
   {
  //object for array
    NSmutableArray *arr=[[NSMutableArray alloc]init];
  //
  //sqlite record iteration starts
  Bio *obj=[[Bio alloc]init];//create instance of bio class
  obj.uid=get the record from sqlite current row iteration
  obj.username.....
  obj.address...

 [arr addobject:obj];
//sqlite record iteration ends
 return  arr;
 }

ViewCOntroller

DAL *dobj=[[DAL alloc]init];
 NSMutableArray* arobj=[[NSmutableArray alloc]init]; 
 arobj=[dobj GetALLBio];
 for(id in arobj)
 {
 id.UID
 id.UserName
 id.Address
 }

i hope it helps likwise u could create a separate DAL.....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜