#Preview {
SwiftUIView()
}
Error:Missing argument for parameter 'isShowing' in call
Whay? can you help me?
Xcode Previews
RSS for tagCreate an app UI and configure almost everything your users see using Xcode Previews.
Posts under Xcode Previews tag
155 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi,
I just learn swiftUI and trying to preview it on my device (iPhone 15 Pro Max), however the app is failed to launch on my device. I haven't change anything on the code yet.
Here's the error message from diagnostic
== PREVIEW UPDATE ERROR:
FailedToLaunchAppError: Failed to launch swplayground.MQ
==================================
| MessageError: Connection interrupted
|
| ==================================
|
| | MessageSendFailure: Message send failure for <ServiceMessage 28: relaunch>
I work on my project on two computers. One of them is older and stuck at Xcode 13. My project targets iOS 15+.
Previously I was able to bounce back and forth between the two, checking code into source control in between.
After doing a bunch of work on one of them over an extended period, I've returned to my older one and checked out the code... only to be unable to build because Xcode balks at every use of #Preview. I didn't change any project settings in the meantime, so I have no idea why this is suddenly a problem...
Edit: It turns out that this is because previous versions of the SDK did not use this macro. Because I created a couple of new SwiftUI files on the newer OS and Xcode/SDK, it plopped #Preview into the new files instead of the previous implementation, PreviewProvider.
I'll leave this post up for anyone who searches on this problem, since I found zero other references in a general Web search.
I am getting Preview Crash. If I remove line 30 below. then the Preview Crash does not occur.
I have Restarted XCode,
I have done a Project Clean,
Then did a project rebuild.
I have also Created a new Project from scratch
Named the project Debug,
Add one new View File named MaskBootCamp
once I select MaskBootCamp
The Preview willl Crash with an Circle with a Red X in the center With Preview Crashed.
If I remove line 22 all is resolved and no exception occurs
Is this a Swift Bug or some error in the coding?
Excepition Report listed below the code. report Below:
** MaskBootCamp .swift **
import SwiftUI
struct MaskBootCamp: View {
@State var rating: Int = 0
var body: some View {
ZStack{
starsView
.overlay(overlayView.mask(starsView))
}
}
private var overlayView: some View {
GeometryReader { geometry in
ZStack(alignment: .leading) {
Rectangle()
.foregroundColor(.yellow)
.frame(width: CGFloat(rating) / 5 * geometry.size.width)
}
//allowsHitTesting(false)
}
}
private var starsView: some View {
HStack{
ForEach(1..<6) {index in
Image(systemName: "star.fill")
.font(.largeTitle)
.foregroundColor(.gray)
.onTapGesture {
rating = index
}
}
}
}
}
#Preview {
MaskBootCamp()
}
The Xcode Canvas Simulator (for Xcode 14 and even 15 ..beta 6) cause multiple springboard and diagnosticd processes to run at nearly 100% CPU , cause the MacBook M1 to heat. This happens every time.
This is usually triggered after the Canvas show an error which live previewing the code as I edit it.
I have tried clearing the derived data but it doesn't seem to help. This happens with all projects. I am unable to use live previews because of this issue.
The are often other processes with the string Poster in them. Like PhotosPosterProvider , CollectionsPoster , ExtragalacticPoster running high on usage at the same time.
Hi all,
when I am trying to build a preview I am always getting the error "Failed to launch app in reasonable time". When clicking on Diagnostics I get the following report information:
AppLaunchTimeoutError: Failed to launch app ”SwiftUI-Weather.app” in reasonable time
The app ”SwiftUI-Weather.app” did not launch on ”iPhone 15 Pro” in 15 seconds.
bundle identifier: tregnet.SwiftUI-Weather
device name: iPhone 15 Pro
path: /Users/MyUser/Library/Developer/Xcode/DerivedData/SwiftUI-Weather-fvxpuqojpxxuqtbuzmjvlatlmuqy/Build/Intermediates.noindex/Previews/SwiftUI-Weather/Products/Debug-iphonesimulator/SwiftUI-Weather.app
Also clicking on "Generate Report" in the Diagnostics menu is not doing anything for me, even after waiting for a few minutes.
Any help would be appreciated.
Greetings
Hey guys, anybody knows how to fix issues with the keyboard on Xcode in preview mode? it used to work well for me but has now stopped working, see details.
Problem statement: Cannot use the keyboard in previews. For example, typing in a textfield does nothing. Everything works well in simulator.
Environment: macOS Monterey 12.6
Xcode 14.1
Thanks in advance for your input.
Hello!
Being a beginner in creating and editing views using swiftUI, I am unsure of the current situation that I am presently in, and would be grateful for any advice or suggestions for the below problem.
For some context, I have recently begun exploring the "Capturing depth using the LiDAR camera" Documentation using AVFoundation and intend to change its ContentView file which is currently written in swiftUI.
The problem: I am unable to preview the SwiftUI code.
When I try to resume the Preview Pane on the right
I'm working on a horizontally scrollable header view. I'd like to implement the following behavior: when users tap on the left/rightmost header items, the header would scroll so they become fully visible. I am using a custom PreferenceKey to report the selected index:
struct SelectedTabPreference: PreferenceKey {
static var defaultValue: Int = 0
static func reduce(value: inout Int, nextValue: () -> Int) {}
}
Then in my view, I wrap my content inside a ScrollViewReader to scroll to the selected header:
struct ContentView: View {
let tabs: [DrawerTab]
@State private var selectedIndex: Int = 0
var body: some View {
ScrollViewReader { scrollProxy in
ScrollView(.horizontal, showsIndicators: false) {
TopTabView(options: tabs, selectedIndex: $selectedIndex)
.padding(32)
.background(Color.clear.preference(key: SelectedTabPreference.self, value: selectedIndex))
}
.onPreferenceChange(SelectedTabPreference.self) { value in
let firstTabSelected = value == 0
let lastTabSelected = value == tabs.count - 1
guard firstTabSelected || lastTabSelected else { return }
withAnimation {
let anchor: UnitPoint = firstTabSelected ? UnitPoint(x: 0.1, y: 0) : UnitPoint(x: 0.9, y: 0)
scrollProxy.scrollTo(tabs[value], anchor: anchor)
}
}
}
}
}
This works well when I run the app, but the Xcode Preview only shows a white screen. In fact, if I include this view as a subview in other views, their previews also break. The Preview only returns to life if I remove the programmatic scrolling:
scrollProxy.scrollTo(tabs[value], anchor: anchor)
I'm pretty sure this has to do with the ScrollViewProxy as my other Preference-based layouts work with Previews, but I don't know how to resolve the issue. Xcode Previews are an integral part of my workflow, and I'd like to avoid losing them if there's a chance.
I am unable to switch from iPhone 15(IOS 17 sim) to iPhone 14 pro(IOS 16.4 sim). I have both iOS 17 and iOS 16.4 simulators installed
p.s : Trying to switch to IOS 16.4 sim because 17 causes my M2 Air overheat alot to the extent that i can't touch it.
When using Xcode's Preview or Simulator, I noticed that my M2 Air will overheat. This hasn't happened before in Ventura or Xcode 14.
Every time when I open the simulator and SwiftUI preview I get an error. How to solve this?
Hello,
SwiftUI previews are not working in my project : when I try to display the preview in Xcode, I got this error :
And if I click on the help icon, here is the complete error message :
RemoteHumanReadableError: Invalid preview service message on ServiceHub channel
==================================
| RemoteHumanReadableError
|
| PropertyListError: Property list missing value for required key ”binaryType”
| Property list: ["agentRole": previews, "environment": {
| "DYLD_FRAMEWORK_PATH" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphonesimulator";
| "DYLD_LIBRARY_PATH" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphonesimulator";
| "OS_ACTIVITY_DT_MODE" = YES;
| "PACKAGE_RESOURCE_BUNDLE_URL" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphoneos";
| "SQLITE_ENABLE_THREAD_ASSERTIONS" = 1;
| "XCODE_RUNNING_FOR_PREVIEWS" = 1;
| "__XCODE_BUILT_PRODUCTS_DIR_PATHS" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphonesimulator";
| "__XPC_DYLD_FRAMEWORK_PATH" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphonesimulator";
| "__XPC_DYLD_LIBRARY_PATH" = "/Users/alexandrecools/Library/Developer/Xcode/DerivedData/MyProject-gqsbendjcwgnvygdhqcoqqznoijh/Build/Intermediates.noindex/Previews/PreviewTesting/Products/Debug-iphonesimulator";
| }, "__unique_service_message_identifier": 4, "deviceEnvironment": {
| "SIMULATOR_CAPABILITIES" = "/Applications/Xcode 14.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/DeviceTypes/iPhone 14 Pro Max.simdevicetype/Contents/Resources/capabilities.plist";
| "SIMULATOR_DEVICE_NAME" = iPhone4Simulator;
| "SIMULATOR_LEGACY_ASSET_SUFFIX" = iphone;
| "SIMULATOR_MAINSCREEN_HEIGHT" = 2796;
| "SIMULATOR_MAINSCREEN_PITCH" = "460.000000";
| "SIMULATOR_MAINSCREEN_SCALE" = "3.000000";
| "SIMULATOR_MAINSCREEN_WIDTH" = 1290;
| "SIMULATOR_MODEL_IDENTIFIER" = "iPhone15,3";
| "SIMULATOR_PRODUCT_CLASS" = D74;
| }, "agentIdentifier": {
| bundleID = "com.apple.dt.XCPreviewAgent";
| discriminant = bundleID;
| }, "displaySize": {
| height = 932;
| width = 430;
| }, "deviceIdentifier": com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro-Max, "processType": application, "arguments": <__NSArray0 0x1b9e04f48>(
|
| )
| , "workspaceID": E4CEE565-58C6-4EB5-94F1-7A9F48791515, "deviceType": simulated, "payloadUsedAgentIdentifier": 1, "frameBufferMaskPath": /Applications/Xcode 14.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/DeviceTypes/iPhone 14 Pro Max.simdevicetype/Contents/Resources/framebuffer.pdf, "displayScale": 3, "bundleID": com.apple.dt.XCPreviewAgent]
==================================
| MessageSendFailure: Message send failure for <ServiceMessage 4: relaunch>
Is there anyone who already encountered this error message? Or maybe anyone who have any idea how to solve it?
Thanks,
Alexandre
Hi,
we recently starting moving toSwiftUI and unable to preview. we are getting a below crash.
App is running using Rosetta on M1 Mac
Xcode 14
iOS 16
All we did is to enable swift previews in build settings.
Crash report for SwiftUI preview:
PotentialCrashError: Update failed
XCPreviewAgent may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application.
==================================
| RemoteHumanReadableError
|
| LoadingError: failed to load library at path "/Users/vamsianguluru/Library/Developer/Xcode/DerivedData/BapineMobile-fiuoxganfwfeexgxiewzascqsimr/Build/Intermediates.noindex/Previews/BapineApp/Products/Debug-iphonesimulator/BiometricLogin.framework/BiometricLogin": Optional(dlopen(/Users/vamsianguluru/Library/Developer/Xcode/DerivedData/BapineMobile-fiuoxganfwfeexgxiewzascqsimr/Build/Intermediates.noindex/Previews/BapineApp/Products/Debug-iphonesimulator/BiometricLogin.framework/BiometricLogin, 0x0000): tried: '/Users/vamsianguluru/Library/Developer/Xcode/DerivedData/BapineMobile-fiuoxganfwfeexgxiewzascqsimr/Build/Intermediates.noindex/Previews/BapineApp/Products/Debug-iphonesimulator/BiometricLogin.framework/BiometricLogin' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Users/vamsianguluru/Library/Developer/Xcode/DerivedData/BapineMobile-fiuoxganfwfeexgxiewzascqsimr/Build/Intermediates.noindex/Previews/BapineApp/Products/Debug-iphonesimulator/BiometricLogin.framework/BiometricLogin' (errno=2), '/Users/vamsianguluru/Library/Developer/Xcode/DerivedData/BapineMobile-fiuoxganfwfeexgxiewzascqsimr/Build/Intermediates.noindex/Previews/BapineApp/Products/Debug-iphonesimulator/BiometricLogin.framework/BiometricLogin' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/BiometricLogin.framework/BiometricLogin' (errno=2))
|
| ==================================
|
| | MessageSendFailure: Message send failure for <ServiceMessage 17: update>
Hello,
I've created multiple Entity in CoreData, that has a relationship to one another. However, I'm unable to create @discardableResult to use in SwiftUI preview.
/// Entity data for use with canvas previews.
static var preview: Entity1 {
let entities1 = Entity1.makePreviews(count: 1)
return entities1[0]
}
@discardableResult
static func makePreviews(count: Int) -> [Entity1] {
var contents = [Entity1]()
let viewContext = PersistenceController.preview.container.viewContext
let persistenceController = PersistenceController.shared
for index in 0..<count {
let entities1 = Entity1(context: viewContext)
entities1.id = UUID()
entities1.title = "Amazing day!"
let photo = Photo(context: viewContext)
let imageData = UIImage(named: "Golden Temple")?.jpegData(compressionQuality: 1) ?? Data()
photo.linkedToJournal = journal
let thumbnail = Thumbnail(context: viewContext)
let thumbnailData = persistenceController.thumbnail(with: imageData)?.jpegData(compressionQuality: 1)
thumbnail.data = thumbnailData
thumbnail.photo = photo
let photoDataObject = PhotoData(context: viewContext)
photoDataObject.data = imageData
photoDataObject.photo = photo
contents.append(entities1)
}
return contents
}
You may also try to use the sample code from https://developer.apple.com/documentation/coredata/sharing_core_data_objects_between_icloud_users to build a SwiftUI Preview.
Appreciate if you could suggest how to build a SwiftUI preview as it saves a lot of development effort and time. Thank you very much!
MacBook Air m2 with Sonoma 14 and Xcode 15.
When running simulator or preview of IOS app, the laptop rapidly heats to an alarming degree. According to activity monitor there is not excessive CPU.
This is the IOS 17 version. I saw a suggestion to try 16.4. But in Xcode 15 I cannot see the pathway to change the IOS version. You can create a simulator for it, but Xcode still only sees IOS 17.
My preview doesn't load, and when starting the scheme, the widget doesn't link with my application
Details:
XCode 15.0
IOS 17
Hardware:
Macbook Pro M2
Ich bin neu bei Xcode und habe einen Fehler gemacht, bei dem ich nicht weiß, wie ich ihn beheben soll.
Das war mein Code zuerst:
#Preview {
AddLektionView().modelContainer(for: Lektion.self)
}
und dann habe ich bemerkt, dass er so aussehen sollte:
#Preview {
AddLektionView().modelContainer(for: Lektion.self, inMemory: true)
}
Nun stehe ich vor dem Problem, dass die Preview die Daten auf Dauer gespeichert hat und ich beim ändern vom Aufbau der Daten, die gespeichert werden sollen, einen Fehler erhalte, da die neue App eine veraltete Datenstruktur von SwiftData lädt, was der App nicht passt. Daraufhin erhalte ich dann einen Fehler, dass die Daten wegen der unbekannten neuen Variable nicht geladen werden können.
Wie kann ich die, von SwiftData geladenen Daten entfernen, sodass die Preview (Canvas) wieder funktioniert? (Eine Neuinstallation von Xcode habe ich schon probiert)
Ich danke für jede Hilfe!
Mit freundlichen Grüßen
Tobias
We have a fairly large app with dozens of dependencies.
SwiftUI Previews take ages to build, even though they are only using a fraction of our code.
I managed to speed them up a bit by disabling most of my custom build phases. But they are still super slow due to how long it takes to build things like Firebase.
Anyone have any ideas here? Is there a way to ensure that previews are only compiling the files that they need to work?
I am not able to present the preview of xcode 15,
I am having the error message "Cannot preview in this file" "Syntax error" but I have no error in xcode.