Error expected after top level declarator swift 3 năm 2024

I'm developing an iPhone application and my project just started to pop the following error on one file:

I have been looking for solutions to this problem, and none have proven useful.

I'm using XCode 4.6.2 under Mountain Lion 10.8.3, with deployment target 5.0 and compiler Apple LLVM compiler 4.2.

I really don't know why this is happening, haven't even modified this file for a while. It happens for both device and Simulator

This document is made available under a Creative Commons Attribution 4.0 International (CC BY 4.0) License.

Swift and the Swift logo are trademarks of Apple Inc.

Privacy Policy Cookies

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Your line numbers don't match up to your actual code. Most likely you forgot to

include something because it's complaining about an incomplete type. If it isn't too long, can you post the beginning of the file up to the function, and where you call it from?

Otherwise, make a copy of your code and delete any extraneous code that doesn't contribute towards the error.

Last edited on

If I had to guess, the problem is before this code.

So, before this code there was a struct. If I typed "typedef" before struct it works, otherwise it didn't. why that?

We cannot comment on what we cannot see.

I expect you left out a semi-colon. I am having to use psychic powers for this, though; you're bad at C++, but you're truly awful at asking questions.

I am attempting to create a C++ file called Fish and to display the fish's num in my SwiftUI app. However, I am encountering the errors "expected ';' after top level declarator" and "unknown type name 'class'; did you mean 'Class'?". It appears that Xcode thinks that the file is a C file. How should I address these errors?

Replies

Did you set the build setting to C++ / Objective-C++ (objcxx)? I created a tiny test project to exercise this tech and I got exactly this error because that build setting defaults to C / Objective-C (objc).

Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = "eskimo" + "1" + "@" + "apple.com"

Set "Supported Languages" to exactly objective-c++ in "Build Settings", then everything works as expected. @jinyangz