Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 06-17-2010, 10:25 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default Saving parsed details to an Array

Hello,

I've managed to parse details from a blog post and I'm trying to save them to an array and then to a database. The code is below:

Code:

Code:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{     
	//NSLog(@"ended element: %@", elementName);
	if ([elementName isEqualToString:@"item"]) {
		
		//Stephen Start
		//NSFetchRequest *request = [[NSFetchRequest alloc] init];
		//NSEntityDescription *entity = [NSEntityDescription entityForName:@"Tabrss" inManagedObjectContext:managedObjectContext];
		//[request setEntity:entity];
		//NSError *error;
				
		Tabrss *newTAB_RSS = [NSEntityDescription 
							   insertNewObjectForEntityForName:@"Tabrss"
							   inManagedObjectContext: self.managedObjectContext];
		//Stephen Stop
		
		// save values to an item, then store that item into the array...
		[item setObject:currentTitle forKey:@"title"];
		[item setObject:currentLink forKey:@"link"];
		[item setObject:currentSummary forKey:@"summary"];
		[item setObject:currentDate forKey:@"date"];
		
		//newTAB_RSS.xtitle = [item setObject:currentTitle forKey:@"title"];
		//newTAB_RSS.xlink = currentLink forKey:@"link";
		//newTAB_RSS.xsummary = currentSummary;
		//newTAB_RSS.xdate = currentDate;
		
		//[item setObject:currentTitle forKey:@"title"];
		//[item setObject:currentLink forKey:@"link"];
		//[item setObject:currentSummary forKey:@"summary"];
		//[item setObject:currentDate forKey:@"date"];
		
		
		//Stephen Start
		[stories addObject:[item copy]];
		[stories addObject:newTAB_RSS];
I've been playing around with it a bit, but can't manage to get it working. How do I assign values from the ITEM to my STORIES array. The line "[stories addObject:newTAB_RSS];" should then write it to the database.

Thanks in advance for the help.

Regards,
stephen is offline   Reply With Quote
Old 06-24-2010, 06:06 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Okay, I managed to get it working, the code below is probably not the cleanest solution but it works:

Code:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{     
	//NSLog(@"ended element: %@", elementName);
	if ([elementName isEqualToString:@"workout"]) {
				
		Tabrss *newTAB_RSS = [NSEntityDescription 
							   insertNewObjectForEntityForName:@"Tabrss"
							   inManagedObjectContext: self.managedObjectContext];
		
		// save values to an item, then store that item into the array...
		[item setObject:currentID forKey:@"id"];
		[item setObject:currentUserID forKey:@"user_id"];
		[item setObject:currentWalkID forKey:@"walk_id"];
		[item setObject:currentDate forKey:@"date"];
		[item setObject:currentDistance forKey:@"distance"];
		[item setObject:currentRepeats forKey:@"repeats"];
		[item setObject:currentType forKey:@"type"];
		[item setObject:currentIntensity forKey:@"intensity"];
		[item setObject:currentComments forKey:@"comments"];
		[item setObject:currentTime forKey:@"time"];
		[item setObject:currentWeight forKey:@"weight"];
		[item setObject:currentHeight forKey:@"height"];
		
		newTAB_RSS.ID = currentID;
		newTAB_RSS.UserID = currentUserID;
		newTAB_RSS.WalkID = currentWalkID;
		newTAB_RSS.xDate = currentDate;
		newTAB_RSS.Distance = currentDistance;
		newTAB_RSS.Repeats = currentRepeats;
		newTAB_RSS.Type = currentType;
		newTAB_RSS.Intensity = currentIntensity;
		newTAB_RSS.Comments = currentComments;
		newTAB_RSS.xTime = currentTime;
		newTAB_RSS.Weight = currentWeight;
		newTAB_RSS.Height = currentHeight;
		
		[self.stories addObject:newTAB_RSS];		
	}	
}
stephen is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 379
9 members and 370 guests
.Snipe, AragornSG, baja_yu, ChrisYates, davejas69, guusleijsten, hussain1982, Kryckter, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:35 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0