Advertisement
Guest User

Any nicer way than this???

a guest
Jan 24th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.61 KB | None | 0 0
  1. // Case 1:
  2. let indexText = atIndex != nil ? "-\(atIndex!)" : ""
  3.  
  4. // Case 2:
  5. let myArray = someObject != nil ? [someObject!] : []
  6.  
  7. // Longer solution
  8. var myArray = []
  9. if let obj = someObject {
  10.    myArray = [obj]
  11. }
  12.  
  13. // Other similar cases :)
  14. let myPrice: GraphQL.PriceInput? = price != nil ? GraphQL.PriceInput(amount: price!.amount, currency: price!.currency) : nil
  15. // ------------------------------------
  16. let width = ad.width != nil ? R.string.localizable.ad_details_attr_measurement_centimetres(Double(ad.width!)) : nil
  17. // ------------------------------------
  18. return intValue != nil ? String(intValue!) : nil
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement