I've trying to add a SwiftUI view to an existing UIKit + Storyboards based tvOS project. The actual build works fine and I can run in the simulator & see my SwiftUI view, but when I resume the SwiftUI preview I get 'Failed to build MyClass.swift' with the following diagnostics:
I saw this similar SO post regarding the -bundle and -bitcode_bundle cannot be used together error, but my configuration is already the way the answer suggests (setting the Mach-O type to Executable and ensuring no Bundle Loader is set).
There's also a warning about /Applications/Xcode.app/Contents/SharedFrameworks-appletvsimulator not being found. That directory certainly does not exist, but nowhere in my project is SharedFrameworks-appletvsimulator referenced that I can find. Also, if I create a new SwiftUI project it doesn't complain about that.
The SwiftUI code is literally just a new "Hello World" SwiftUI file from the Xcode template - I haven't modified it at all.
Does anyone have any ideas what's going on here or how to fix it?
For me the fix was disabling the code coverage option:
Go to your scheme menu -> select edit scheme -> go to the "Test" section on the left side menu -> uncheck the Code Coverage mark
I'm using Xcode 12.5
iOS minimum target 13.4
There are diffrent reasons for the preview to fails and several posts about it , for example:
This Question
Related
I recently updated my Qt version from 5.12.3 to 5.15.2. I rebuilt an application that uses a qt virtualkeyboard in QML using InputPanel {}. The virtual keyboard is defined in main as qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));. Everything works in release mode but when I run in debug mode I get the following application output from qt creator:
Program: C:\Qt\5.15.2\msvc2019_64\bin\Qt5Cored.dll
Module: 5.15.2
File: qvirtualkeyboardinputcontext_p.cpp
Line: 221
ASSERT: "!this->inputPanel" in file qvirtualkeyboardinputcontext_p.cpp, line 221
I inspected the source file on Github for 5.15.2 and the line number points to method void QVirtualKeyboardInputContextPrivate::registerInputPanel(QObject *inputPanel) with Q_ASSERT(!this->inputPanel);. I wanted to compare this method with Github for 5.12.3 but it looks like this method was added after 5.12.3 hence why I didn't see the error before.
Now, my understanding is that Q_ASSERT(bool) will call qFatal() when the flag is false. If inputPanel is of type QObject* should the Q_ASSERT be Q_ASSERT(this->inputPanel)? The Q_ASSERT should only trigger when the pointer is a nullptr. Or maybe I'm just confused?
There was already an existing bug report on Qt's bug tracker. Previously I only searched by virtualkeyboard and not InputPanel. The bug report is here. BTW, it looks like this is only an issue in debug mode and a workaround is to click the ignore button several times to continue in debug mode.
Edit: Qt responded that this assert check is to make sure that there is only 1 InputPanel component in the whole application. So, I am not sure how InputPanel is suppose to work when we have multiple dynamic views in a MVVM architecture design where each view has it's own self contained InputPanel.
Edit2: Updating per my last edit comment. I put the InputPanel at the main qml file that controls the StackView and the views that are dynamically loaded are able to use the same InputPanel.
I am developing a QT GUI for my application using QT Creator (4.11.0).
Recently, our IT updated my OS to Ubuntu 20.04 (from 18.04) - maybe the error is related to that.
I have not touched to project in some month but yesterday wanted to continue developing it.
However, within the IDE there are now thousands of errors highlighted at almost every line of my code. (with highlighted I mean that there is this red background and a red dot beside the line number)
On the very top, it says:
Warning: The code model could not parse an included file, which might lead to incorrect code completion and highlighting, for example.
cstddef:50:10: fatal error: 'stddef.h' file not found
...
The errors that are listed in the IDE are very wired like:
type `QMainWindow`is not a direct or virtual base of `MainWindow` (my class is called `MainWindow`)
I'm pretty sure it is not related to my code:
the code compiles and works fine - it is really just the IDE that is highlighting errors at every line of my code.
I have the same code on a Windows Computer and there no errors are listed in the IDE.
even if I start a brand new QT Widget project the errors appear within the template code provided by the QT Creator.
Since the GCC version changed with the update of the OS, I thought maybe I have to define a new KIT but this also did not help.
Is there anything I can do to fix the issue?
Do I have to reinstall the QT Creator?
I know, pictures are not very well-liked but here I think it might help to understand what I mean with "IDE is highlighting errors":
1. First
~/.profile :
CPATH="/usr/include/clang/10/include:$CPATH"
C_INCLUDE_PATH="/usr/include/clang/10/include:$C_INCLUDE_PATH"
CPLUS_INCLUDE_PATH="/usr/include/clang/10/include:$CPLUS_INCLUDE_PATH"
export CPATH
export C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH
maybe /usr/include/clang/10/include see in you file system.
2. Second
Logout / login.
3. Third
Specifying Build Settings (Projects -> Build -> in every config build) in Build Environment section: [unset] CPATH, C_INCLUDE_PATH and CPLUS_INCLUDE_PATH
or [edit] replace this variable with the necessary values
I fixed this issue by sudo apt install clang-8.
Source: https://bugs.launchpad.net/ubuntu/+source/qtcreator/+bug/1890434
I build an app with the 2nd beta of Xcode 11, using SwiftUI, and everything worked completely fine, but now, with the 3rd beta, the app isn't even build. I get errors like "Use of undeclared type 'View'", "Unknown attribute 'State'" etc. What can I do? Is the problem in my code or is it just a bug?
The problem is when I'm trying to build the app to run on my Mac (with UIKit for Mac)
#State var score = 0
The error is "Unknown attribute 'State'"
struct ContentView : View {
/*...*/
}
The error is "Use of undeclared type 'View'"
Got same issue on Xcode 11.2. Found out that the reason was that somewhere in same module I declared protocol State {}. This breaks compiler without any reasonable errors.
This is from the Xcode 11 Beta 3 Release Notes.
Known Issues
Xcode 11 doesn’t support working with SwiftUI in an iPad app brought to macOS. (41416222, 51201699)
I downloaded the Xcode 11 Beta 3 myself just to confirm the errors you mentioned, and I had the same issues when trying to build a SwiftUI project for Mac.
I would suggest going back to using Xcode Beta 2 if possible. Unfortunately, Apple doesn't provide download links to previous betas, so hopefully you have a Time Machine backup or Beta 2 still installed on your computer. Otherwise, you might be out of luck until the next beta is released.
I was getting the same "Unknown attribute 'State'" issue in Beta 5. But I was doing "#state" and not "#State". Case matters. It's hard to notice because both ways are shown as purple.
If you are doing a Kotlin multi-platform project, check if your shared module has a component named "State".
Instead #main, please replace #UIApplicationMain.
I've attached screenshots.
https://prnt.sc/vimvwn
I got the same error while trying to compile a Swift project created with Xcode 13 on Xcode 11. The problem was that the newer version uses the SDK 12.1 while the older one uses the SDK 10.15. To let the project compile on the older Xcode/SDK I just performed these steps:
remove the #main attribute from the swift source code
add Cocoa.framework in the section Frameworks, Libraries, and Embedded Content
add a file named main.m to the project (no bridge header) with this content:
#include <Cocoa/Cocoa.h>
int main(int argc, const char * argv[]) {
return NSApplicationMain(argc, argv);
}
I'm trying to run the Automatic Preview in Xcode 11, however even though the project builds successfully, the automatic preview fails giving me the error Failed to build ContentView.swift. Failed to code sign ContentView.swift.
I have just created the project without any modifications to the auto generated code. Even the code signing has also been set properly. Note I'm using the Free Apple Developer Account. Could this cause any problem?
Following is the code from ContentView.swift file:
import SwiftUI
struct ContentView : View {
var body: some View {
Text("Hello World")
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
First select the Xcode using following command
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
Then run
sudo xcodebuild -license
Hope it is helpful
I solved that problem by going to the Xcode - Preferences -> Locations and assigning the Command Line Tools to Xcode 11. Also keep in mind that it is a beta, so it is unstable.
I had this problem as I was using // to comment beside my curly brackets to check I had them all in the right spot in my screen code. Xcode seems to cope with a few but once the screen gets too large and too many comments......
Now I comment on the line below and no problems!
Xcode SwiftUI Previews may occasionally fail with an error message about a modified .h file, such as “file Header.h has been modified since the module file Module.pcm was built: mtime changed.” (85938686)
Workaround: Delete the Clang module cache by running the following command in Terminal:
rm -rf "$TMPDIR/../C/clang/ModuleCache"
Then try to preview the file again.
https://developer.apple.com/documentation/Xcode-Release-Notes/xcode-13_3-release-notes
I had this problem too. I solved it by moving the file location of the file I was trying to preview. When the file was created it was down below the resources folder, so I moved it up and then preview worked.
I am currently having this problem with XCode 12.2, it says "Failed to build ContentView.swift." and when you click on the information's button it says "Extra tokens at end of #SourceLocation".
Apparetly that was because i wrote a "// Comment" in the same line, next to a variable definition, so i solved this only moving the comment to the next line.
I don't know who i can help this, but just wanted to share it.
Regards!
Change your iOS version to the latest one. It will solve your issue.
Renaming main project solved same issue on my Mac.
Rename the blue file in your project navigation.
I encountered this problem too. I download Xcode beta-1 before I download macOS 10.15. Then after my system upgrade to 10.15, the preview function didn't work. It turns out that Apple has released Xcode beta-2 version recently, so I downloaded and it worked. So, KEEP THE NEWEST VERSION OF XCODE!!!!
I just installed RubyMotion on my iMac.
I created my first app - Hello
This is the code:
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
#window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
#window.rootViewController = HelloViewController.alloc.init
#window.rootViewController.wantsFullScreenLayout = true
#window.makeKeyAndVisible
true
end
end
I run $ Rake and the IOS Simulator start up. And I get this error:
2014-04-25 18:58:03.157 Hello[10488:70b] Cannot find executable for CFBundle 0x8d8a130 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle> (not loaded)
I tried this from another question:
Temporary workaround: click iOS Simulator > Reset Content and Settings... and run again.
But, that didn't fix it.
Thanks for the help!
It's a relatively harmless (I believe) bug in the iOS 7 SDK.
https://devforums.apple.com/message/940094#940094
I had the same issue and found your post when searching for a solution. My application appeared to be running fine but I was still getting this message I was able to eliminate the message on my machine, here is what I had to do;
Stop all execution on the simulator.
Go to the simulator's home screen using shift-command-h.
Delete the app from the simulator device by holding a click on my program until the delete icon appeared, then click the X to delete.
In the iOS Simulator select Reset Content and Settings.
Clean the project in Xcode, shift-command-k.
Build it and run it.
Note, I was doing steps 4 & 5 but that wasn't working. It wasn't until I added step 3 (as crazy as it sounds) that it cleared my message.
Hope this works for you!
--Dave
Perhaps deleting the app, resetting, and restarting the iOS simulator would work.