Skip to content

Instantly share code, notes, and snippets.

@rhysforyou
Created September 8, 2011 10:39
Show Gist options
  • Select an option

  • Save rhysforyou/1203112 to your computer and use it in GitHub Desktop.

Select an option

Save rhysforyou/1203112 to your computer and use it in GitHub Desktop.
- (void)addEvent
{
CLLocation *location = [locationManager location];
if (!location) {
return;
}
Event *event = (Event *)[NSEntityDescription insertNewObjectForEntityForName:@"Event"
inManagedObjectContext:managedObjectContext];
CLLocationCoordinate2D coordinate = [location coordinate];
[event setLatitude:[NSNumber numberWithDouble:coordinate.latitude]];
[event setLongitiude:[NSNumber numberWithDouble:coordinate.longitude]];
[event setCreationDate:[NSDate date]];
NSError *error = nil;
if (![managedObjectContext save:&error]) {
// Handle the error.
}
[eventsArray insertObject:event atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
atScrollPosition:UITableViewScrollPositionTop
animated:YES];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment