Skip to content

Instantly share code, notes, and snippets.

@douglashill
Last active August 14, 2016 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save douglashill/2ceaf9a9efd22fb302d30a1d1ba67112 to your computer and use it in GitHub Desktop.
Save douglashill/2ceaf9a9efd22fb302d30a1d1ba67112 to your computer and use it in GitHub Desktop.
Can’t pass LazyMapCollection to Objective-C API
import Foundation
let dictionary = ["one": 1, "two": 2]
let lazyValues = dictionary.values
let jsonData = try JSONSerialization.data(withJSONObject: lazyValues, options: [])
// ❗️ Argument type 'LazyMapCollection<Dictionary<String, Int>, Int>' does not conform to expected type 'AnyObject'
import Foundation
extension LazyMapCollection {
func array() -> [Element] {
var elements: [Element] = []
for element in self {
elements.append(element)
}
return elements
}
}
let dictionary = ["one": 1, "two": 2]
let lazyValues = dictionary.values
let valuesArray = lazyValues.array()
let jsonData = try JSONSerialization.data(withJSONObject: valuesArray, options: [])
// ✅
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment