Skip to content

Instantly share code, notes, and snippets.

@DonMag
Last active February 23, 2017 15:09
Show Gist options
  • Select an option

  • Save DonMag/70850f23b0f1b66380bd64b8222df857 to your computer and use it in GitHub Desktop.

Select an option

Save DonMag/70850f23b0f1b66380bd64b8222df857 to your computer and use it in GitHub Desktop.
Display select Contact view
Did user hit Cancel? If yes, get out
User selected a Contact - call custom "save()" function
In save() function:
Does Contact have multiple Phones?
If no, continue to next part of save() function
If yes, has multiple Phones
Has user already selected a phone?
If yes, continue to next part of save() function
If no, show phone selection
In phone selection
Did user hit Cancel? If yes, get out
User selected a phone, call custom save() function
In save() function:
Does Contact have multiple emails?
If no, continue to next part of save() function
If yes, has multiple emails
Has user already selected a email?
If yes, continue to next part of save() function
If no, show email selection
In email selection
Did user hit Cancel? If yes, get out
User selected a email, call custom save() function
In save() function:
we've confirmed only one phone, or we have a user selected phone
we've confirmed only one email, or we have a user selected email
Save Contact info how you want it
Display saved confirmation
Go on / back to where you want the user to be
------------------------------------------------------------------------
var selectedPhone
var selected email
func chooseContact() {
showContactPicker() {
completion:
// if user selected cancel, stop process and return to where the user was
if result == cancel {
callCancelFunc()
} else {
// user chose a Contact,
if phoneCount == 1 {
selectedPhone = phone
}
if emailCount == 1 {
selectedEmail = email
}
callSaveFunc()
}
}
}
func callCancelFunc() {
// dismiss VC or pop stack or rewind segue... whatever got us here
}
func callSaveFunc() {
// is there more than one phone number? have we already selected?
if phoneCount > 1 && selectedPhone == "" {
callChoosePhoneFunc()
return
}
// is there more than one email?
if emailCount > 1 && selectedEmail == "" {
callChooseEmailFunc()
return
}
// do the actual save, and then
// dismiss VC or pop stack or rewind segue... whatever got us here
}
func callChoosePhoneFunc() {
showChoosePhoneAlert() {
completion:
// if user selected cancel, stop process and return to where the user was
if result == cancel {
callCancelFunc()
} else {
// user chose a Phone
selectedPhone = selection
callSaveFunc()
}
}
}
func callChooseEmailFunc() {
showChooseEmailAlert() {
completion:
// if user selected cancel, stop process and return to where the user was
if result == cancel {
callCancelFunc()
} else {
// user chose an email
selectedEmail = selection
callSaveFunc()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment