Database Reference
In-Depth Information
alert. addTextFieldWithConfigurationHandler {
(textField: UITextField !) in
textField. placeholder = "Qualifying Zone"
}
alert. addAction ( UIAlertAction (title: "Save" ,
style: . Default , handler: { (action: UIAlertAction !) in
println ( "Saved" )
let nameTextField = alert. textFields ! [ 0 ] as UITextField
let zoneTextField = alert. textFields ! [ 1 ] as UITextField
let team =
NSEntityDescription . insertNewObjectForEntityForName ( "Team" ,
inManagedObjectContext: self . coreDataStack . context ) as Team
team. teamName = nameTextField. text
team. qualifyingZone = zoneTextField. text
team. imageName = "wenderland-flag"
self . coreDataStack . saveContext ()
}))
alert. addAction ( UIAlertAction (title: "Cancel" ,
style: . Default , handler: { (action: UIAlertAction !) in
println ( "Cancel" )
}))
presentViewController (alert, animated: true , completion: nil )
}
This is a fairly long, but simple to understand method. When the user taps the Add
button, it presents an alert view prompting the user to enter a new team.
The alert view has two text fields: one for entering a team name and another for
entering the qualifying zone. Tapping “Save” commits the change and inserts the
new team into Core Data's persistent store.
The action is already connected in the storyboard, so there's nothing more for you
to do.
Build and run the app one more time. If you're running on a device, shake it. If
you're running on the Simulator, press Command+Control+Z to simulate a shake
event.
Search WWH ::




Custom Search