Swift 4.2 - Value of type '(____) -> () -> (____)' has no member 'childNode'

Standard

I created a custom class in swift to manage my main menu for a game I'm making I linked it to the SKScene file and tried to create a constant to access the variable and I got this error: Cannot use instance member 'childNode' within property initializer.

import SpriteKit
import GameplayKit

class MainMenu: SKScene {

    let startGameButton:SKSpriteNode = self.childNode(withName: "SpriteName")

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    }
}

Does anyone know whats happening? If not is there another way to access sprites.

uliwitness

Initial values for let variables must be constants that can be initialized before the init() method is executed. That in turn means they can't reference self.

One workaround for that is making them lazy instance variables, which get initialized when they are first used (which, by definition, can't happen before init() has returned a reference to the object). In that case, the lazy variable would be initialized with the result from a closure.

Change:

let startGameButton:SKSpriteNode = self.childNode(withName: "SpriteName")

to

lazy var startGameButton:SKSpriteNode = self.childNode(withName: "SpriteName") as! SKSpriteNode

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Value of type '' has no member '' in swift

Value of type 'EditProfileVc' has no member 'storageRef' in swift 4

Value of type AppDelegate has no member managedObjectContext in swift 4

Swift 2: Value of type 'Set<UITouch>' has no member 'anyObject'

Swift 5 Value of type has no member

Value of type 'String' has no member 'range' in Swift

Swift: Value of type 'string' has no member 'length'

Swift - Value of Type ViewController has no member *functionName*

Swift Value of type 'SKNode' has no member 'particleBirthRate'

Value of type has no member

Swift error: Value of type 'NSObject - > () 'AnimalListTableViewController' has no member 'tableView'

Swift 2.2: Value of type 'Element' (aka 'AnyObject') has no member 'objectID'

Value of type 'String' has no member 'stringByRemovingPercentEncoding in Swift 3

Swift: Alamofire Value of type 'Self' (Request) has no member 'responseJSON' extension

Error: value of type 'String' has no member 'hasSuffix' in Swift switch

Error: value of type 'String' has no member 'Generator' in Swift

iOS Swift: Value of type 'NotificationCenter' has no member 'publisher'

Swift 3.0: Value of type 'IndexSet' has no member 'enumerateIndexesUsingBlock'

Value of type 'Result<String>' has no member 'error' [Alamofire, Swift 5]

Swift For Loop Value of type 'AnyObject?' has no member 'Generator'

Swift 3 Value of type 'Any?' has no member 'object'

Swift 3 conversion : value of type 'characterset' has no member 'characterIsMember'

Value of type '(UIDatePicker) -> ()' has no member 'date' In swift 5

Swift and Firebase: Value of type User has no member asDict()

Value of type 'StartMorgagesViewPage2' has no member 'pdfData2'

Value of type 'UITableViewCell' has no member

Value of type * has no member 'rx'

Value of type 'NavigationController' has no member

Swift: "Value of type 'Any' has no member 'map'" with array returned as type Any

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive