Some times we need to do a big project in xcode
we should try to make datacotroller deferent than our codes
make a data controller
@interface DataController : NSObject {
NSMutableArray *list;
NSMutableArray *namelist;
NSMutableArray *mobiles;
NSMutableData *tdata;
NSMutableArray *ids;
NSMutableArray *sgns;
NSMutableArray *Emails;
NSMutableArray *Fexs;
NSMutableArray *Birthdays;
NSMutableArray *Annidays;
NSString *searchfilter;
}
- (unsigned)countOfList;
-(NSMutableArray *) GetList;
-(NSMutableArray *) GetIds;
-(NSMutableArray *) Getsgns;
-(NSMutableArray *) Getmobiles;
-(NSMutableArray *) GetEmails;
-(NSMutableArray *) GetFexs;
-(NSMutableArray *) GetBirthdays;
-(NSMutableArray *) GetAnniversarydays;
-(void) SetFilter:(NSString *)search;
-(NSString *)searchfilter;
- (void)createDemoData:(NSString *)search;
@end
and implement it as data layer
#import "DataController.h"
#import "DataSet.h"
#import "WebServiceHelper.h"
@interface DataController ()
@property (nonatomic, copy, readwrite) NSMutableArray *list;
@property (nonatomic, copy, readwrite) NSMutableArray *namelist;
@property (nonatomic, copy, readwrite) NSMutableArray *ids;
@property (nonatomic, copy, readwrite) NSMutableArray *sgns;
@property (nonatomic, copy, readwrite) NSMutableArray *Emails;
@property (nonatomic, copy, readwrite) NSMutableArray *Fexs;
@property (nonatomic, copy, readwrite) NSMutableArray *mobiles;
@property (nonatomic, copy, readwrite) NSMutableArray *Birthdays;
@property (nonatomic, copy, readwrite) NSMutableArray *Annidays;
@property (nonatomic, copy, readwrite) NSString *searchfilter;
- (void)createDemoData:(NSString *)search;
@end
@implementation DataController
@synthesize list;
@synthesize namelist;
@synthesize ids,Annidays;
@synthesize sgns,mobiles,Emails,Fexs,Birthdays;
@synthesize searchfilter;
- (id)init {
if (self = [super init]) {
searchfilter = [[NSString alloc] init];
}
return self;
}
- (void)setList:(NSMutableArray *)newList {
if (list != newList) {
[list release];
list = [newList mutableCopy];
}
}
- (unsigned)countOfList {
return [list count];
}
-(void)SetFilter:(NSString *)search
{
searchfilter=search;
[self createDemoData:searchfilter];
}
- (void)dealloc {
[searchfilter release];
[ids release];
[namelist release];
[list release];
[super dealloc];
}
- (void)createDemoData:(NSString *)search
{
WebServiceHelper *DataCon = [[WebServiceHelper alloc] init];
DataCon.XMLNameSpace = @"http://tempuri.org/";
DataCon.XMLURLAddress = @"http://urdomain.com/webservicefolder/service1.asmx";
DataCon.MethodName = @"MyMethodName";
DataCon.MethodParameters = [[NSMutableDictionary alloc] init];
[DataCon.MethodParameters setObject:[[NSUserDefaults standardUserDefaults] stringForKey:@"name_preference"] forKey:@"UserName"];
[DataCon.MethodParameters setObject:[[NSUserDefaults standardUserDefaults] stringForKey:@"password_preference"] forKey:@"Password"];
[DataCon.MethodParameters setObject:search forKey:@"GroupId"];
tdata = [DataCon initiateConnection];
DataSet *dsMyDataSet = [[DataSet alloc] initWithXMLData:tdata];
NSMutableArray *Name = [[NSMutableDictionary alloc] init];
NSMutableArray *ID = [[NSMutableDictionary alloc] init];
NSMutableArray *SGN = [[NSMutableDictionary alloc]init];
NSMutableArray *mob = [[NSMutableDictionary alloc]init];
NSMutableArray *mobarr = [[NSMutableArray alloc] init];
NSMutableArray *em = [[NSMutableDictionary alloc]init];
NSMutableArray *emarr = [[NSMutableArray alloc]init];
NSMutableArray *fe = [[NSMutableDictionary alloc]init];
NSMutableArray *fearr = [[NSMutableArray alloc]init];
NSMutableArray *bd = [[NSMutableDictionary alloc]init];
NSMutableArray *bdarr = [[NSMutableArray alloc]init];
NSMutableArray *an = [[NSMutableDictionary alloc]init];
NSMutableArray *anarr = [[NSMutableArray alloc]init];
ID = [dsMyDataSet getRowsForTableAndColumn:@"_x0030_" col:@"Id"];
Name = [dsMyDataSet getRowsForTableAndColumn:@"_x0030_" col:@"DisplayName"];
SGN = [dsMyDataSet getRowsForTableAndColumn:@"_x0030_" col:@"SubGroupName"];
mob = [dsMyDataSet getRowsForTableAndColumn:@"_x0030_" col:@"DisplayPhone"];
em = [dsMyDataSet getRowsForTableAndColumn:@"_x0030_" col:@"DisplayEmail"];
fe = [dsMyDataSet getRowsForTableAndColumn:@"_x0030_" col:@"DisplayFax"];
bd = [dsMyDataSet getRowsForTableAndColumn:@"_x0030_" col:@"Birthday"];
an = [dsMyDataSet getRowsForTableAndColumn:@"_x0030_" col:@"Anniversary"];
NSEnumerator *mobIterator= [mob objectEnumerator];
NSString *mobnm;
while(mobnm = [mobIterator nextObject])
{
if([mobnm isEqualToString:@"@#$%"])
{
[mobarr addObject:@""];
}
else
{
[mobarr addObject:mobnm];
}
}
NSEnumerator *emIterator= [em objectEnumerator];
NSString *emnm;
while(emnm = [emIterator nextObject])
{
if([emnm isEqualToString:@"@#$%"])
{
[emarr addObject:@""];
}
else
{
[emarr addObject:[NSString stringWithString:emnm]];
}
}
NSEnumerator *feIterator= [fe objectEnumerator];
NSString *fenm;
while(fenm = [feIterator nextObject])
{
if([fenm isEqualToString:@"@#$%"])
{
[fearr addObject:@""];
}
else
{
[fearr addObject:fenm];
}
}
NSEnumerator *dateIterator= [bd objectEnumerator];
NSString *datestring;
while(datestring = [dateIterator nextObject])
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss-'06:00'"];
NSDate *date = [dateFormatter dateFromString:datestring];
[dateFormatter setDateFormat:@"dd MMM "];
if(date==nil)
{
}
else {
[bdarr addObject:[dateFormatter stringFromDate:date]];
}
}
NSEnumerator *anIterator= [an objectEnumerator];
NSString *anstring;
while(anstring = [anIterator nextObject])
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss-'06:00'"];
NSDate *date = [dateFormatter dateFromString:anstring];
[dateFormatter setDateFormat:@"dd MMM "];
if(date==nil)
{
}
else {
[anarr addObject:[dateFormatter stringFromDate:date]];
}
}
self.namelist = Name;
self.list = playList;
self.ids = ID;
self.sgns = SGN;
self.mobiles = mobarr;
self.Emails = emarr;
self.Fexs = fearr;
self.Birthdays = bdarr;
self.Annidays = anarr;
[an release];
[anarr release];
[SGN release];
[ID release];
[Name release];
[emarr release];
[em release];
[mob release];
[mobarr release];
[fearr release];
[fe release];
[bd release];
[bdarr release];
}
-(NSMutableArray *) GetList
{
return self.namelist;
}
-(NSMutableArray *) GetIds
{
return self.ids;
}
-(NSMutableArray *) Getsgns
{
return self.sgns;
}
-(NSMutableArray *) Getmobiles
{
return self.mobiles;
}
-(NSMutableArray *) GetEmails
{
return self.Emails;
}
-(NSMutableArray *) GetFexs
{
return self.Fexs;
}
-(NSMutableArray *) GetBirthdays
{
return self.Birthdays;
}
-(NSMutableArray *) GetAnniversarydays
{
return self.Annidays;
}
@end
now you are following good structure in xcode ...
Enjoy!!
No comments:
Post a Comment