Func declared but flagged as unresolved identifier

Here an excerpt of my recent little App that is creating a FIFO, writes from low level C into it and tries to obtain the written contents from Swift high level code:



    @IBAction func sendUDP(_ sender: Any) {
            print("calling C and writing to MYFIFO:")
            udpC()
            var textFromFile =  LoadFileAsString(path: "MYFIFO")
        }
    func LoadFileAsString(path: String) -> String? {
            let fm = FileManager()
            let exists = fm.fileExists(atPath: path)
            if(exists){
                let content = fm.contents(atPath: path)
                let contentAsString = String(data: content!, encoding:  
                     String.Encoding.utf8)
                return(contentAsString)
            } 
            return (nil)
        }

Although the function is defined, trying to use it results in an error
Use of unresolved identifier.

Which function cause error? Could you also provide call site?

Sorry to have been unprecise. It's the line where LoadFileAsString is invoked. What do you mean by "provide call site"?

Are all of the lines you show here necessary for the error to occur? For instance, if you comment out the calls to print and udpC, do you still get the error? How about some of the lines in LoadFileAsString? How about the surrounding lines (this must be in a view controller, right)?

Apologies. I had a curly braces misplacement in the code. func LoadFileAsString was nested in another func().
All fine now.

Yup :-) It happens. Respecting indentation can help spotting such :man_facepalming: mistake. Tip: Xcode auto-indents the selection when you hit ctrl-I.

Terms of Service

Privacy Policy

Cookie Policy