Database Reference
In-Depth Information
completion:
nil
)
}
Tapping on Rate now brings up an alert view with a single text field, a cancel button
and a save button. Tapping the save button calls the method
updateRating
, which…
Whoops, you haven't defined it yet. Appease Xcode by implementing it below:
func
updateRating(numericString:
String
) {
currentBowtie
.
rating
= (numericString
as
NSString)
.
doubleValue
var
error:
NSError
?
if
!
managedContext
.
save
(&error) {
println
(
"Could not save
\(error)
,
\(error!.
userInfo
)
"
)
}
populate
(
currentBowtie
)
}
You convert the text from the alert view's text field into a double and use it to
update the current bow ties rating property.
Finally, you commit your changes as usual by saving the managed context and
refresh the UI to see your changes in real time.
Try it out. Build and run the app and tap
Rate
:
Enter any decimal number from 0 to 5 and tap
Save
. As you would expect, the
rating label updates to the new value you entered.
Now tap
Rate
one more time. Remember the timeless elegance of a red bow tie?
Let's say you like it so much that you decide to rate it a 6 out of 5. Tap
Save
to
refresh the user interface: