Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Expected expression in Swift key path" Error while Refactoring code with Extensions

I have been trying refactor code by thanking functions and adding them in a separate file extension of a ViewController

What I have in this extension is a function that adds gesture recognizers to some views that have references to functions that I have placed in other file extension of the same ViewController. On build I am getting this error "Expected expression in Swift key path"

What is causing this error?

like image 597
ISS Avatar asked Oct 23 '18 09:10

ISS


2 Answers

I got this error when I accidentally left a backslash after a bracket in my object init:

init(for note: Note, atAnchor anchor: ARAnchor) {\

    let billboardNode = note.type.basicNode

    self.node = billboardNode
    self.text = note.description ?? "[No Text]"
    self.type = note.type
    addText()
}

Removing the backslash fixed the error. Check out this answer by user eharo2 for details about why!

like image 184
Edmund Holderbaum Avatar answered Sep 17 '22 03:09

Edmund Holderbaum


Maybe you have typo, for example:

\//
//  MyClass.swift
//  yyy
//
//  Created by xxx on 4/25/19.
//  Copyright © 2019 xxx. All rights reserved.
//

import Foundation

class MyClass {

}

In this Case I accidentally wrote '\' at start.

like image 35
levan Avatar answered Sep 20 '22 03:09

levan