Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 1.08 KB

File metadata and controls

40 lines (31 loc) · 1.08 KB
title Best Practices with iOS and NativeScript
contributors
NathanWalker
rigor789

Delegates, delegates, DELEGATES!!

Always retain custom delegate implementations that you use in a your own custom iOS classes. Not doing so can cause your delegate to get garbage collected early and functionality not working as expected.

For example:

  • BAD
let applePayController: PKPaymentAuthorizationViewController

applePayController =
  PKPaymentAuthorizationViewController.alloc().initWithPaymentRequest(
    paymentRequest,
  )
applePayController.delegate =
  PKPaymentAuthorizationViewControllerDelegateImpl.initWithOwner(this)
  • GOOD
let applePayController: PKPaymentAuthorizationViewController
let applePayControllerDelegate: PKPaymentAuthorizationViewControllerDelegateImpl

applePayController =
  PKPaymentAuthorizationViewController.alloc().initWithPaymentRequest(
    paymentRequest,
  )
applePayControllerDelegate =
  PKPaymentAuthorizationViewControllerDelegateImpl.initWithOwner(this)
applePayController.delegate = applePayControllerDelegate