Skip to content

Instantly share code, notes, and snippets.

@ppeszko
Last active August 12, 2016 11:10
Show Gist options
  • Select an option

  • Save ppeszko/8bbb64c9c5eef0902023c4814aa7a1d3 to your computer and use it in GitHub Desktop.

Select an option

Save ppeszko/8bbb64c9c5eef0902023c4814aa7a1d3 to your computer and use it in GitHub Desktop.
import UIKit
struct Payment { }
enum PaymentResponse {
case Accepted(Payment)
case Rejected(Payment)
}
// It's just an example for notifications. The rest can be safely ignored :)
class SadPaymentViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let notificationCenter = NSNotificationCenter.defaultCenter()
// MARK: ლ( `Д’ ლ)
// This tells Notfication Center that we are interested in updates.
notificationCenter.addObserver(self,
selector: #selector(SadPaymentViewController.paymentNotificationReceived(_:)),
name: "PaymentViewControllerNotificationRejected",
object: nil)
notificationCenter.addObserver(self,
selector: #selector(SadPaymentViewController.paymentNotificationReceived(_:)),
name: "PaymentViewControllerNotificationAccepted",
object: nil)
}
func paymentServiceDidReturn(paymentResponse: PaymentResponse) {
let notificationCenter = NSNotificationCenter.defaultCenter()
switch paymentResponse {
case .Accepted(_):
// MARK: •́︵•̀
// And this is how we post notifications
notificationCenter.postNotificationName("PaymentViewControllerNotificationRejected",
object: nil,
userInfo: nil)
case .Rejected(_):
notificationCenter.postNotificationName("PaymentViewControllerNotificationAccepted",
object: nil,
userInfo: nil)
}
}
func paymentNotificationReceived(notification: NSNotification) {
//FIXIT: Write this code before release, okay? Bye, I'm off for vacation. ᕕ( ᐛ )ᕗ
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment