Used to compile in previous Xcode 12.5.0?

Hi I'm a newbie to swift, but there is nothing more irritating than having something that used to compile in Xcode 12.4.X.... I'm importing AppKit and it does not say the function call has been depreciated, but Xcode is saying it can't find it?

import SwiftUI
import Foundation
import Cocoa
import AppKit

struct ContentView: View {
var body: some View {
Text("Hello, world!")
.padding()
let path = URL(fileURLWithPath: "Users/jrh")
activateFileViewerSelecting(_, path: [URL])
// * Error Cannot find in activateFileViewerSelecting.... in scope *****. I'm at a loss
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

I moved this topic to "Using Swift" because it's not about compiler development.

You're right that activateFileViewerSelecting is not deprecated, but that's not where the problem is. Your code does not compile because the body function is a ResultBuilder function, ViewBuilder specifically in this case. All of ViewBuilder's buildBlock functions take only parameters of View-conforming types, so within body the compiler expects each statement to return a value of View-conforming type. However, the following 2 statements don't:

let path = URL(fileURLWithPath: "Users/jrh")
activateFileViewerSelecting(_, path: [URL])

Both = and activateFileViewerSelecting return Void, which does not conform to View. The compiler "thinks" that there might be overloads of activateFileViewerSelecting that return values of View-conforming types. However it could not find any, because there isn't any overload that returns a value of View-conforming type, so it provides an error message that says it cannot find the right activateFileViewerSelecting in scope.

Thank you wowbagger. I'll try to post my questions in "Using Swift" when they are this type of question. They almost need a topic "Swift questions for the inexperienced". Thanks again. -Jim

One other note, It had been a month or so since I looked at this. I often use a terminal and command line and write "swift" programs to try and learn swift. It turns out I had a version that works/ed in a command line using activateFileViewerSelecting(...). So I probably never had it working in Xcode12.5.x... Wowbagger, you have been great !!! Thank you for responding to my beginner swift questions.

Terms of Service

Privacy Policy

Cookie Policy