Cannot convert value of type [AnyObject] to expected argument type [SKAction]
Use the Append() method.
anArray.append("This String")
Cannot convert value of type '[AnyObject]'to type 'NSArray' in coercion
Look at reverse()
return type. You should cast it to Array
:
var tempArr2 = Array(tempArr.reverse())
Cannot convert value of type 'String' to expected argument type 'SKNode'
The problem
You are using self
before the object initialisation.
Infact writing this
let ball = childNodeWithName(BallCategoryName) as! SKSpriteNode
is equals to writing this
let ball = self.childNodeWithName(BallCategoryName) as! SKSpriteNode
But during the properties initialisation the current instance of GameScene
does not exists yet! So there's no self
yet.
And this is a good thing because if the compiled had allowed this code, it would have crashed at runtime since there is no ball
node in you Scene
yet (again because there is no Scene yet).
Solution
I suggest you to
- turn your stored property into a computed property
- use a lowercase character for the first name of a property like this
ballCategoryName
- prefer conditional casting (as? instead of as!)
- turn the global constant
ballCategoryName
into a stored property
The code
class GameScene: SKScene {
let ballCategoryName: String = "ball"
var ball: SKSpriteNode? {
return childNodeWithName(ballCategoryName) as? SKSpriteNode
}
}
Cannot convert value of type 'Object.Type' to expected argument type 'Object'
You should refer to the current instance of Maze
as self
.
Notice in each example the use of the unowned
or weak
keywords here, to prevent a strong reference between Maze
and MazeRat
.
However, since self
isn't available yet as rat
hasn't been initialized - you need to give rat
an initial value first.
Example:
class Maze {
private(set) var rat: MazeRat!
init() {
rat = nil
rat = MazeRat(maze: self)
}
}
class MazeRat {
unowned let maze: Maze
init(maze: Maze) {
self.maze = maze
}
}
Another method is to initialize MazeRat
, then set the maze
instance, like so:
class Maze {
let rat: MazeRat
init() {
rat = MazeRat()
rat.maze = self
}
}
class MazeRat {
weak var maze: Maze?
init() {}
}
cannot convert value of type inout CGAffineTransform to expected argument
I suggest changing your code to:
var mirroring = CGAffineTransformMakeScale(1.0, -1.0) // flip horizontal
var mirrorPath : CGMutablePath! = CGPathCreateMutable()
CGPathAddPath(mirrorPath, &mirroring, newPath.CGPath)
let newFollow = SKAction.followPath(mirrorPath, asOffset: false, orientToPath: true, speed: 200)
player.runAction(SKAction.repeatActionForever(newFollow).reversedAction(),withKey:"followPath")
From Apple's documentation Interacting with C API's
Constant Pointers
When a function is declared as taking a UnsafePointer argument,
it can accept any of the following:
- nil, which is passed as a null pointer.
- An UnsafePointer,
UnsafeMutablePointer, or AutoreleasingUnsafeMutablePointer
value, which is converted to UnsafePointer if necessary.- A
String value, if Type is Int8 or UInt8. The string will automatically
be converted to UTF8 in a buffer, and a pointer to that buffer is
passed to the function.- An inout expression whose left-hand side
operand is of type Type, which is passed as a pointer to the address
of the left-hand side identifier.- A [Type] value, which is passed as a
pointer to the start of the array.
The 4th bullet is the one that tells us you can send &mirroring
for the argument that is expecting UnsafePointer<CGAffineTransform>
.
Cannot call value of non-function type '((AnyObject) - AnyObject?)!' - Swift 3
The syntax has changed from:
let x = myData.objectForKey("myKey")
to:
let x = myData.object(forKey:"myKey")
in Swift 3.
Example:
var x : AnyObject = ["Hello" : "Goodbye"] as AnyObject
x.object(forKey:"Hello")
Related Topics
How to Query Firebase Data Childbyautoid
How to Set a Custom Annotations for All Points Except for User Location
Lazy Initialization and Deinit
Parse Codable Classes and Avoid Repetition
Reload Tableview After Clicking The Button Present Inside One of The Tableview Cell in Swift
Pass and Print All Cases in an Enum in Swift
Swift "Print" Doesn't Appear in Stdout But 3Rd Party C Library Logs Do When Running in Docker on Ecs
Swift How to Make List Start at The Top with No Padding
Crashlytics Doesn't Work with Xcode 10 Beta
How to Dynamically Hide Navigation Back Button in Swiftui
Using Nsdate to Get Date for Easter
Add a File Generated by Run Script into The Test Target Compilation List in Xcode
Xcode 6.1 Swift Extensions - Sourcekit Service Crash
Swift: Guard Let and Where - The Priority
Parsing JSON from Url Ends Up with an Error - Swift 5
Error When Running Coreml in The Background: Error Computing Nn Outputs Error
Swift Combine: Turn a Publisher into a Read-Only Currentvaluesubject