Post not yet marked as solved
I'm trying out Xcode 12 (beta) and encountered an issue with TextField when viewing it in a live Preview.
Although the view is interactive (scrolling vertically seems to be OK) and a cursor appears in the TextField view when it is clicked on, keyboard input is ignored.
The same code works as expected in Xcode 11.5. Simulator in both 11.5 and 12 exhibits expected behaviour.
Is this a bug? I know there is an issue with interactivity in Preview with multiple views inside PreviewProvider but I'd assumed this is if you'd added multiple Views to the same body of this struct.
Post not yet marked as solved
Hi there!
I've been messing around in Xcode 12 Beta with SwiftUI and a Core Data Model, and for some reason my ContentView preview in Xcode is failing to load. Here's the error:
"Cannot preview in this file — Connection interrupted: send message to agent"
I've made sure all my target memberships are synchronized, given Xcode 12 Command Line Tools in Preferences>Locations, and tried every other solution I can find out there.
Any ideas?
Post not yet marked as solved
I keep getting a Xcode Previews error in Xcode 12 from a package that imports other packages. As soon as I remove the dependency I'm able to see the SwiftUI preview. I'm only able to use previews in packages that have no dependencies
The error I get is: "LoadingError: failed to load library at path...Library not loaded " then it point to the dependency that it could not load in the current package.
How can I access Xcode Previews from a package that depends on other packages?
I am unable to use the hardware keyboard to enter text in text fields when using Xcode 12 live previews.
Same issue with all preview devices. Running on macOS 10.15.5.
Is there an option I am missing or a workaround for this?
import SwiftUI
struct ContentView: View {
@State private var text = ""
var body: some View {
Form {
TextField("Write something", text: $text)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Post not yet marked as solved
I'm trying to load items from the database into a list, it works fine on device and simulator but Preview will always crash with the following message:
" Cannot preview in this file — Connection interrupted: send message to agent"
Here's my code
struct SettingsView: View {
@Environment(\.managedObjectContext) var moc
@FetchRequest(entity: ChildProfile.entity(), sortDescriptors: []) var children: FetchedResults<ChildProfile>
var body: some View {
VStack {
List {
Section(header: Text("Children")) {
ForEach(children, id: \.id) { child in
ChildRow(child: child)
}
}
}
}
}
}
struct SettingsView_Previews: PreviewProvider {
static let moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
static var previews: some View {
let defaultChild = ChildProfile(context: moc)
defaultChild.id = UUID()
defaultChild.name = "Lex"
return SettingsView().environment(\.managedObjectContext, moc)
}
}
Previewing ChildRow with the same preview code works fine in the canvas
Is this a bug in Xcode or am I missing something?
While working through Part II the Widget code-along from WWDC, I thought I would add a separate preview for each size, just as an exercise for myself.
static var previews: some View {
Group {
EmojiRangerWidgetEntryView(entry: SimpleEntry(date: Date(), configuration: ConfigurationIntent(), character: .panda))
.previewContext(WidgetPreviewContext(family: .systemSmall))
EmojiRangerWidgetEntryView(entry: SimpleEntry(date: Date(), configuration: ConfigurationIntent(), character: .panda)) .previewContext(WidgetPreviewContext(family: .systemMedium))
}
}
}
This works, giving me two previews of the correct size. Unfortunately, the smaller preview is trying to layout the medium's view within its given space.
I'm assuming that this is because the @Environment for the widgetFamily wasn't configured correctly, so I thought I'd add it like this:
.environment(\.widgetFamily, .systemSmall)
I was guessing that something like this might be possible, because I have seen a similar situation where a preview is created for a dark mode like this:
.environment(\.colorScheme, .dark)
Alas, my attempt to set the widgetFamily environment doesn't work. It gives me a this error:
Key path value type 'WritableKeyPath<EnvironmentValues, WidgetFamily>' cannot be converted to contextual type 'KeyPath<EnvironmentValues, WidgetFamily>'
Am I close? Is there some way to inject the widget family environment, or is there a bug that fails to bind the WidgetPreviewContext(family: .systemSmall) that I'm already passing?
SwiftUI previews don't seem to work in Xcode 12, beta 5, when using Firebase Analytics. The app builds and runs fine to simulator or device, but fails generating SwiftUI preview for a widget with the following message:
ld: in /Users/../.../Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector(FIRAnalyticsConnector_e321ed8e3db06efc9803f6c008e67a34.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/.../.../Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It was working fine in beta 4. Anyone else seen this? Any ideas?
After I added Storekit to my App SwiftUI-Previews doesn't work anymore. The App itself builds like a charm but all the Previews are broken with the following Error Message:
No such module '_StoreKit_SwiftUI'
Does anyone else knows this issues and has an idea on how to solve this?
Post not yet marked as solved
Hello,
I'm implementing Sign In With Apple in a SwiftUI application (iOS 14, SwiftUI 2). I'm importing the AuthenticationServices framework. The app build successfully, and can run on an iOS device or simulator. But I cannot preview the view in the Preview / Canvas (it would be easier to design the view).
Cannot find 'SignInWithAppleButton' in scope
Any idea why?
Thanks
Axel
PS: Xcode 12 beta 6, macOS Big Sur beta 5
In my current project, previews barely work. Most of the time, the following error is displayed on top:
Cannot preview in this file -- Unexpected error occurred
Sometimes, refreshing works by clicking the Try Again button, but usually that takes multiple tries. When I click the Diagnostics button, the following error is shown:
HumanReadableSwiftError
ConfigurationError: noPreviewInfos(arch: "x86_64", sdkRoot: "/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk")
This happens both in Xcode 12 and the beta Xcode 12.2. Who has a solution for this?
Post not yet marked as solved
Any help with preview crash on an App that is building just fine and runs on simulator fine?
Are there logs that I can access somehow?
The previews were working just fine, but then stopped and I have reverted all changes since and the previews are still broken.
Post not yet marked as solved
I was practising with SwiftUI and using canvas preview. There's a button to Duplicate Preview (tor right corner above simulator)
How to remove this Duplicated Preview?
Tried selecting the preview and pressing Backspace, cmd+backspace and other possible combinations; choosing another device, relaunching etc
MacOS, 10.15.6
Xcode 12.0
Solved:
Need to delete ContentView() from
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView()
}
}
}
It was too low and didn't fit on the screen so I didn't notice it
When the Xcode Previews app opens on the device, this is the error message in Xcode: RemoteHumanReadableError: Failed to update preview.
Error encountered when sending 'display' message to agent.
I tried cleaning the build folder and quitting then reopening Xcode to no avail.
Using Xcode 12.0.1 previewing on iPhone 11.
Post not yet marked as solved
Hi,
I have been working through some of the SwiftUI tutorials (I really like it so far). Today I was editing a source file and I decided to widen the window a bit. I dragged too far to the right and wound up hiding the Preview. I cannot find any menu item, preference, etc. that allows you to show/hide the Preview. I'd like to get it back but have no idea how. I tried deleting some Xcode preferences but that did not help. I appreciate any advice. This is for Xcode 12.1.
Post not yet marked as solved
hi everyone
I have encountered a problem after updating to Big Sur this morning. my canvas preview won't work despite build succeed.
simulator is working.
the error code is Updating took more than 5 seconds
PreviewUpdateTimedOutError: Updating took more than 5 seconds
Updating a preview from ContentView_Previews in 2.RedMe.app (2495) took more than 5 seconds.
how can I fixed it?
system: Big Sur 11.0.1
Xcode: 12.2 version
many thanks
Post not yet marked as solved
I am experiencing an issue where my Mac's speakers will crackle and pop when running an app on the Simulator or even when previewing SwiftUI with Live Preview.
I am using a 16" MacBook Pro (i9) and I'm running Xcode 12.2 on Big Sur (11.0.1).
Killing coreaudiod temporarily fixes the problem however this is not much of a solution.
Is anyone else having this problem?
Post not yet marked as solved
I have a relatively simple SwiftUI component that is a member of both my iOS App target as well as the corresponding WatchKit Extension.
As long as I select either the App scheme and select only the App target, or
the Watch scheme and select only the WatchKitExtension target
the preview works just fine.
As soon as I include the View in both targets, the preview fails with
The run destination iPhone 12 Pro Max is not valid for Running the scheme 'Trallala WatchKit App'. or
The run destination Apple Watch Series 6 - 44mm is not valid for Running the scheme 'MultiTimer'.
respectively. I get that the creation of the preview depends on the current target, but why does including it in additional targets create this error, and of course more important:
How to address that?
Additional question: Is there a way to create previews for both target platforms side by side?
Thanks a million
Klaus
Post not yet marked as solved
Hello,
Since I added Core Data to my SwiftUI project, preview canva is no more working, showing an error explaining that the update took more than 5 seconds (the app is working correctly in simulator).
I opened the preview diagnostic report folder, and found a file named SerializationErrors.txt, with the following message:
Error Domain=NSCocoaErrorDomain Code=516 "“SizeModel+CoreDataClass.swift” couldn’t be linked to “Intermediates” because an item with the same name already exists."
I feel like there is a problem of refreshing the class generated for my Core data model. I tried to follow some recommendations found on this website, deleting the Library/Developer/Xcode/UserData/Previews/Simulator Devices/, or also Library/Developer/Xcode/DerivedData, and cleaning/closing Xcode, but none of them had any effect on the problem.
Doing so, I noticed that in the Previews folder, two Simulator Devices were generated (one empty "Simulator Devices", and one filled "Simulator%20Devices"), and regenerated even if I clear them. I don't know if it could be related, but I don't know anymore where to search...
Post not yet marked as solved
I've been working for the past day or so to add a very minor feature to one of our UIKit based apps using SwiftUI, as an experiment. Suddenly, this morning, previews stopped working, citing a build error that only occurs when building for preview:
Compiling failed: 'main' attribute cannot be used in a module that contains top-level code
I was editing the view when this started happening, but no fiddling I've done with it since has fixed the issue.
I have tried:
Reverting all changes in Git
Cleaning the build folder (repeatedly)
Touching both the file with the SwiftUI view, and the AppDelegate that's annotated with @main
Closing the project, and Xcode
The project builds and runs just fine: this error only occurs with previews.
I had been working in Xcode 12.5 beta 2 when the problem started, but it persists when I open the project in Xcode 12.3.
Is there some extra build cache that I can go purge?
Post not yet marked as solved
I am working on rebuilding our large app's dependency graph to use Swift Package Manager, replacing CocoaPods. I have it nearly done and am quite happy with the progress so far. However, I've run into a blocker with Xcode's SwiftUI Previews not working, seemingly due to several .binaryTarget dependencies.
I've boiled this down to a simple reproducible case, with this Package.swift:
let package = Package(
name: "MyLibrary",
platforms: [.iOS(.v13)],
products: [.library(name: "MyLibrary", targets: ["MyLibrary"]),],
dependencies: [],
targets: [
.target(name: "MyLibrary", dependencies: ["NewRelic"]),
.binaryTarget(name: "NewRelic",
url: "https://download.newrelic.com/ios_agent/NewRelic_XCFramework_Agent_7.3.0.zip",
checksum: "daaaff7897246e4baddb1b8131a79268de3b6889a48182b4fbdabe5b926d08f4"),
]
)
Here I am using NewRelic as a common 3rd party dependency that vends an .xcframework.zip-- but this is not specific to NewRelic and can be reproduced with many (any?) similar examples.
This package builds a library successfully and works as expected when included in an app.
But when I try to use SwiftUI previews on a trivial view, e.g.:
struct MyLibraryView: View {
var body: some View {
VStack {
Text(verbatim: "Hello World, I'm MyLibraryView")
}
}
}
struct MyLibrary_Previews: PreviewProvider {
static var previews: some View {
return MyLibraryView()
}
}
I end up with this Unexpected duplicate tasks build failure, due to the build system seemingly trying to process the XCFramework twice:
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Using build description from memory
note: Using build description 'e8ea061fcc823688d24edc3f230a0c7c'
note: Build preparation complete
note: Target dependency graph (3 targets)
MyLibrary in MyLibrary
MyLibrary in MyLibrary, depends on:
MyLibrary in MyLibrary (explicit)
MyLibrary in MyLibrary, depends on:
MyLibrary in MyLibrary (explicit)
error: Unexpected duplicate tasks:
1) Command: ProcessXCFramework /Users/mthole/Library/Developer/Xcode/DerivedData/DuplicateTasksOnPreview-bkclfnyhkfofwaaulhpstpdjggqb/SourcePackages/artifacts/DuplicateTasksOnPreview/NewRelic.xcframework ios simulator
2) Command: ProcessXCFramework /Users/mthole/Library/Developer/Xcode/DerivedData/DuplicateTasksOnPreview-bkclfnyhkfofwaaulhpstpdjggqb/SourcePackages/artifacts/DuplicateTasksOnPreview/NewRelic.xcframework ios simulator
I've posted the reproduction case on GitHub here. Tested with Xcode 12.5 Beta 3.
https://github.com/mthole/DuplicateTasksOnPreview