I'm getting extraneous argument label 'contentsOf:' in call
array.append(contentsOf: test)
error when trying to run this code in playground:
import Cocoa
var array:[Any] = []
let test = [""]
array.append(contentsOf: [""])
array.append(contentsOf: test)
Why is this happening? As I understand, there are two equal arrays with empty string.
To answer your specific question in the comments, in that case you just need to cast so Swift knows you're aware. In this case since SKShapeNode
downcasts to SKNode
just fine, you can just cast with as
. If you were doing a cast that may fail, you'd need to use as?
and safely unwrap to be sure.
var allNodes: [SKNode] = []
let onlyShapeNodes: [SKShapeNode] = []
allNodes.append(contentsOf: onlyShapeNodes as [SKNode])
For the original generic example this would work as well.
var array: [Any] = []
let test = ["", ""]
array.append(contentsOf: [""] as [Any])
array.append(contentsOf: test as [Any])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With