Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. struct Foo {
  2. var bar:Dictionary<String, Any> = [:]
  3. }
  4.  
  5. extension Foo {
  6. init(json: [String: Any]) {
  7. if let bar = json["bar"] {
  8. self.bar = bar as! Dictionary<String, Any>
  9. }
  10. }
  11. }
  12.  
  13. let param:Dictionary<String, Any> = ["bar": 12]
  14. let options = Foo(param)
  15.  
  16. if (options.bar != [:]) {
  17. // ok, the bar is set - do something
  18. }
  19.  
  20. Binary operator '!=' cannot be applied to operands of type 'Dictionary<String, Any>' and '[AnyHashable : Any]'
  21.  
  22. if let bar = json["bar"] {
  23. self.bar = bar as! Dictionary<String, Any>
  24. }
  25.  
  26. extension Foo {
  27. init(json: [String: Any]) {
  28.  
  29. if let _ = json["bar"] {
  30.  
  31. self.bar = json
  32. }
  33. }
  34. }
  35.  
  36. let param:Dictionary<String, Any> = ["bar": 12]
  37. let options = Foo(json: param)
  38.  
  39. if (options.bar.isEmpty) {
  40. print("empty")
  41. }else{
  42. print("not emtpy")
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement