Created
February 27, 2010 17:45
-
-
Save quique123/316842 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PeopleListViewController.m | |
// Paparazzi | |
// | |
// Created by Marcio Valenzuela on 2/20/10. | |
// Copyright 2010 Personal. All rights reserved. | |
// | |
#import "PeopleListViewController.h" | |
@implementation PeopleListViewController | |
@synthesize filePath;//, managedObjectContext; | |
-(void)viewDidLoad { | |
[super viewDidLoad]; | |
[self loadCoreData]; | |
//[self getCoreData]; | |
} | |
-(void)viewWillAppear:(BOOL)animated{ | |
[super viewWillAppear:animated]; | |
} | |
- (void)didReceiveMemoryWarning { | |
// Releases the view if it doesn't have a superview. | |
[super didReceiveMemoryWarning]; | |
} | |
- (void)viewDidUnload { | |
// Release any retained subviews of the main view. | |
// e.g. self.myOutlet = nil; | |
} | |
- (void)dealloc { | |
[super dealloc]; | |
} | |
-(void)loadCoreData{ | |
NSLog(@"Entering loadCoreData"); | |
// call singleton and make context | |
FlickrFetcher *myConnection=[FlickrFetcher sharedInstance]; | |
//Check if db exists, otherwise call plist file and populate | |
if ([myConnection databaseExists]==YES){ | |
NSLog(@"db EXISTS!"); | |
[self getCoreData];} | |
else { | |
NSLog(@"db doesnt exit, CREATE IT!"); | |
NSManagedObjectContext *managedObjectContext=[myConnection managedObjectContext]; | |
NSLog(@"file context created!"); | |
// GET PLIST FILE INFO | |
filePath = [[NSBundle mainBundle] pathForResource:@"FakeData" ofType:@"plist"]; | |
if (filePath){ | |
NSLog(@"file path gotten!"); | |
// CREATE FLICKR ARRAY FROM PLIST FILE PATH | |
NSArray *twitterIds = [NSArray arrayWithContentsOfFile:filePath]; | |
NSLog(@"array created!"); | |
for (NSDictionary *dict in twitterIds){ | |
// Step 1: Create Object | |
NSLog(@"creating newPhoto object!"); | |
Photo *newPhoto = (Photo*)[NSEntityDescription insertNewObjectForEntityForName:@"Photo" inManagedObjectContext:managedObjectContext]; | |
// Step 2: Set Properties | |
NSLog(@"Entering Photo Name:%@",[dict objectForKey:@"name"]); | |
[newPhoto setPhotoName:[dict objectForKey:@"name"]]; | |
NSLog(@"SettingPhotoURL:%@",[dict objectForKey:@"path"]); | |
[newPhoto setPhotoURL:[dict objectForKey:@"path"]]; | |
NSLog(@"SettingOwnerName:%@",[dict objectForKey:@"user"]); | |
[newPhoto setOwnerName:[dict objectForKey:@"user"]]; | |
}// for dictionary loop, create object and set properties | |
NSError *error; | |
if(![managedObjectContext save:&error]){ | |
NSLog(@"Error:%@",error); | |
}// if my context saves with error, log the error | |
}//if filepath exists | |
}//else if db doesnt exist | |
} | |
-(void)getCoreData{ | |
NSLog(@"Entering getCoreData"); | |
FlickrFetcher *myConnection=[FlickrFetcher sharedInstance]; | |
NSManagedObjectContext *managedObjectContext=[myConnection managedObjectContext]; | |
//Get Core Data from Flickr CD db | |
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; | |
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Photo" | |
inManagedObjectContext:managedObjectContext]; | |
[fetchRequest setEntity:entity]; | |
NSError *error; | |
NSLog(@"Error:%@",error); | |
NSArray *items = [managedObjectContext | |
executeFetchRequest:fetchRequest error:&error]; | |
NSLog(@"Error:%@",error); | |
[fetchRequest release]; | |
NSLog(@"%@", items); | |
NSLog(@"Leaving getCOreData"); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment