From 663d25e5160e97eefed1444bac0b4ac964f3368e Mon Sep 17 00:00:00 2001 From: matt handler Date: Sun, 24 Apr 2011 21:00:46 -0400 Subject: still a bit off from a solid state... added fmdatabase, updated acidcow parser with a formate, added some standard stuff to piccast app delegate, created a section dictionary, did some serializing to/from db for topics, added a bunch of logic to topic view controller, added db table --- Classes/Topic.m | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'Classes/Topic.m') diff --git a/Classes/Topic.m b/Classes/Topic.m index 712519b..65ea506 100644 --- a/Classes/Topic.m +++ b/Classes/Topic.m @@ -7,17 +7,69 @@ // #import "Topic.h" - +#import "FMDatabase.h" +#import "FMResultSet.h" @implementation Topic -@synthesize title, guid, creator, iconUrl, description, releaseDate, category, picCount; +@synthesize guid, title, iconUrl, description, releaseDate, category, picCount; + ++ (Topic *) initFromDatabaseRow:(FMResultSet *)result { + NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; + [dateFormatter setDateStyle:NSDateFormatterLongStyle]; + [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; + [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]]; + + Topic *topic = [[[Topic alloc] init] autorelease]; + + topic.guid = [result stringForColumn:@"link"]; + topic.title = [result stringForColumn:@"title"]; + topic.iconUrl = [result stringForColumn:@"iconUrl"]; + topic.description = [result stringForColumn:@"description"]; + topic.releaseDate = [Topic stringToDate:[result stringForColumn:@"releaseDate"]]; + topic.category = [result stringForColumn:@"category"]; + topic.picCount = [result intForColumn:@"picCount"]; + + return topic; +} + ++ (NSString *) dateToString:(NSDate *)date { + NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; + [dateFormatter setDateStyle:NSDateFormatterLongStyle]; + [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; + [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]]; + + return [dateFormatter stringFromDate:date]; +} + ++ (NSDate *) stringToDate:(NSString *)string { + NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; + [dateFormatter setDateStyle:NSDateFormatterLongStyle]; + [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; + [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]]; + + return [dateFormatter dateFromString:string]; +} + +- (void)serializeToDatabase:(FMDatabase *)db { + //NSLog(@"title: %@", title); + [db executeUpdate:@"INSERT INTO picCasts \ + (foreignId, link, title, description, releaseDate, category, iconUrl, picCount) \ + VALUES \ + (?, ?, ?, ?, ?, ?, ?, ?)", + 12, guid, title, description, [Topic dateToString:releaseDate], category, picCount]; + //NSLog(@"insert id:%d error: %@", [db lastInsertRowId], [db lastErrorMessage]); + + // [NSString stringWithFormat:@"number %d", i], + // [NSNumber numberWithInt:i], + // [NSDate date], + // [NSNumber numberWithFloat:2.2f]]; +} - (void)dealloc { [picCount release]; [guid release]; [title release]; - [creator release]; [description release]; [releaseDate release]; [category release]; -- cgit v1.2.3