M2 Air overheating with Xcode 15.0.1
Xcode Previews
RSS for tagCreate an app UI and configure almost everything your users see using Xcode Previews.
Posts under Xcode Previews tag
153 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Is it possible to create one-to-many relationships between optional objects in SwiftData Xcode Previews? The below code I call from #Preview crashes the canvas on the post.authors?.append(tempAuthors.randomElement()!) when I try to append an array to an optional array. I can append the previewAuthors array to the authors array in the simulator or on device, but it crashes in Preview. My running theory is it has something to do with being in memory since this works on device, but I'm not sure that I missed something super obvious.
static func previews(_ count: Int) -> [Post] {
let previewAuthors = [Author(name: "..."), Author(name: "...")]
var posts: [Post] = []
for i in 0..<count {
let post = Post(title: "Title \(i)")
post.authors?.append(previewAuthors.randomElement()!)
posts.append(post)
}
return posts
}
Hello
I am in need of help to try and understand what is going on with XCode and Previews when using Swift Data.
I have the following path:
View 1 (Calandar Screen) -> Passes Model -> View 2 (Details Screen)
I have a situation where when working on View 2 it will not run in Preview mode when the Pin is not selected. However if I pin View 1 and then go to work on View 2 preview works fine.
Now I am guessing that this might have something to do with Swift Data and by having View 1 open it generates the Model to be passed but I might be wrong?
I am also struggling to understand and read the error log that excode generates.
I have Preview setup in View 2 as follows
#Preview {
DiaryReadView(diaryModel: DiaryModel())
.environmentObject(NavigationStateManager())
.modelContainer(for: [DiaryModel.self], inMemory: true)
}
Error Log
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------
Incident Identifier: 5C8FAD15-959E-4E0A-AFF4-55A739D54110
CrashReporter Key: CC891733-97EE-34E0-EDB7-394B181A2623
Hardware Model: iMac20,1
Process: Diary [36381]
Path: /Users/USER/Library/Developer/Xcode/UserData/Previews/Simulator Devices/78258A6C-0145-4E82-ACCD-1F0539F2148A/data/Containers/Bundle/Application/970BD3F5-925F-47BD-A214-7F7B0226A04F/Diary.app/Diary
Identifier: OR-1
Version: 1.0 (1)
Code Type: X86-64 (Native)
Role: Foreground
Parent Process: launchd_sim [29471]
Coalition: com.apple.CoreSimulator.SimDevice.78258A6C-0145-4E82-ACCD-1F0539F2148A [78195]
Responsible Process: SimulatorTrampoline [48509]
Date/Time: 2023-10-24 10:55:15.3444 +0100
Launch Time: 2023-10-24 10:55:14.7909 +0100
OS Version: macOS 14.0 (23A344)
Release Type: User
Report Version: 104
Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Termination Reason: SIGNAL 4 Illegal instruction: 4
Terminating Process: exc handler [36381]
Triggered by Thread: 0
Thread 0 Crashed:
0 libswiftCore.dylib 0x7ff814aa36f2 0x7ff814a76000 + 186098
1 SwiftData 0x7ff84952f7dd 0x7ff849514000 + 112605
2 SwiftData 0x7ff8495b1746 0x7ff849514000 + 644934
3 SwiftData 0x7ff8495b64c9 0x7ff849514000 + 664777
4 SwiftData 0x7ff84956f726 0x7ff849514000 + 374566
5 Diary 0x10a4e9635 DiaryModel.init() + 357 (@__swiftmacro_5Diary0A5Model0B0fMm_.swift:2)
6 Diary 0x10a4e94c2 DiaryModel.__allocating_init() + 34
7 DiaryReadView.1.preview-thunk.dylib 0x10bf15533 closure #1 in static $s025Diary_PreviewReplacement_A10ReadView_133_E76E9AE78936AC4C16C3EA33E995B161Ll0B0fMf_15PreviewRegistryfMu_.makePreview() + 51 (@__swiftmacro_025Diary_PreviewReplacement_A10ReadView_133_E76E9AE78936AC4C16C3EA33E995B161Ll0B0fMf_.swift:9)
8 PreviewsInjection 0x10ac7f386 0x10ac41000 + 254854
9 PreviewsInjection 0x10ac8025d 0x10ac41000 + 258653
10 libswift_Concurrency.dylib 0x7ff85b04c76c 0x7ff85b03b000 + 71532
11 PreviewsInjection 0x10ac7f0e5 0x10ac41000 + 254181
12 PreviewsInjection 0x10ac83108 0x10ac41000 + 270600
13 PreviewsInjection 0x10ac83c1c 0x10ac41000 + 273436
14 PreviewsInjection 0x10ac70a0d 0x10ac41000 + 195085
15 PreviewsInjection 0x10ac7387a 0x10ac41000 + 206970
16 PreviewsInjection 0x10ac5a630 0x10ac41000 + 103984
17 PreviewsInjection 0x10ac5aaf4 0x10ac41000 + 105204
18 PreviewsInjection 0x10ac753f0 0x10ac41000 + 214000
19 PreviewsInjection 0x10ac493f3 0x10ac41000 + 33779
20 PreviewsInjection 0x10ac48a85 0x10ac41000 + 31365
21 PreviewsFoundation 0x10b741df9 0x10b6a1000 + 658937
22 libdispatch.dylib 0x7ff800156a90 0x7ff800155000 + 6800
23 libdispatch.dylib 0x7ff800157d3a 0x7ff800155000 + 11578
24 libdispatch.dylib 0x7ff800166ac0 0x7ff800155000 + 72384
25 libdispatch.dylib 0x7ff800166526 0x7ff800155000 + 70950
26 CoreFoundation 0x7ff8003f5850 0x7ff800368000 + 579664
27 CoreFoundation 0x7ff8003f018b 0x7ff800368000 + 557451
28 CoreFoundation 0x7ff8003ef409 0x7ff800368000 + 553993
29 GraphicsServices 0x7ff80fcdd187 0x7ff80fcda000 + 12679
30 UIKitCore 0x7ff805b703a2 0x7ff804b95000 + 16626594
31 UIKitCore 0x7ff805b74e10 0x7ff804b95000 + 16645648
32 SwiftUI 0x7ff84a61077e 0x7ff8495ce000 + 17049470
33 SwiftUI 0x7ff84a610637 0x7ff8495ce000 + 17049143
34 SwiftUI 0x7ff84a2bcaa5 0x7ff8495ce000 + 13560485
35 Diary 0x10a4ffade static DiaryApp.$main() + 30
36 Diary 0x10a500099 main + 9 (DiaryApp.swift:12)
37 dyld_sim 0x10ab023ee start_sim + 10
38 dyld 0x10cd9c3a6 0x10cd96000 + 25510
For the PreviewProvider, is it possible to set the ios version which the preview will be made for or the preview will always use the latest ios version (e.g. ios 17)?
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?
== DATE:
Thursday, October 26, 2023 at 13:06:58 China Standard Time
2023-10-26T05:06:58Z
== PREVIEW UPDATE ERROR:
FailedToLaunchAppError: Failed to launch com.***
==================================
| MessageError: Unexpected message object
|
| Unexpected message object: expected ProcessID, got Optional(6872)
Hi,
I am getting an error in the preview section for the watchOS application. But it works when I build it. I get the like following errors in Preview. How can I solve it?
no such module 'QuartzCore'
Compile RoundedCorners.swift (arm64):
/Users/msy/Library/Developer/Xcode/DerivedData/TestApp-gkorwbacqzvxvgcmrpdkaxfxnnmu/SourcePackages/checkouts/lottie-ios/Sources/Private/CoreAnimation/Animations/CAAnimation+TimingConfiguration.swift:4:8: error: no such module 'QuartzCore'
import QuartzCore
^
Compile Shape.swift (arm64):
/Users/msy/Library/Developer/Xcode/DerivedData/TestApp-gkorwbacqzvxvgcmrpdkaxfxnnmu/SourcePackages/checkouts/lottie-ios/Sources/Private/CoreAnimation/Animations/CAAnimation+TimingConfiguration.swift:4:8: error: no such module 'QuartzCore'
import QuartzCore
^
Compile LottieAnimationView.swift (arm64):
/Users/msy/Library/Developer/Xcode/DerivedData/TestApp-gkorwbacqzvxvgcmrpdkaxfxnnmu/SourcePackages/checkouts/lottie-ios/Sources/Private/CoreAnimation/Animations/CAAnimation+TimingConfiguration.swift:4:8: error: no such module 'QuartzCore'
import QuartzCore
^
Copy FirebaseAnalyticsSwift.swiftmodule (arm64):
error: /Users/msy/Library/Developer/Xcode/DerivedData/TestApp-gkorwbacqzvxvgcmrpdkaxfxnnmu/Build/Intermediates.noindex/Previews/TestApp Mobil Watch App/Intermediates.noindex/Firebase.build/Debug-watchsimulator/FirebaseAnalyticsSwift.build/Objects-normal/arm64/FirebaseAnalyticsSwift.swiftmodule: No such file or directory (in target 'FirebaseAnalyticsSwift' from project 'Firebase')
Following the new Xcode update 15.0.1, when my preview loads a process called nsurlsessiond is triggered and it is downloading more data. How do I solve this problem?
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
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
Every time when I open the simulator and SwiftUI preview I get an error. How to solve this?
Hi, I am trying to use SwiftUI in my project where I was using UIKit only, until now. The problem is that Preview in Xcode is not working even for very simple View with Text("Hello World"). Code is correct and project is possible to build and run. Even when I try to select real device (real iPhone) I can see Preview in my device. But preview in simulator is not working. Can someone help me with this? I am attaching diagnostic from Xcode and file from ~/Library/Logs/DiagnosticReports/
Thanks for help
xcode_preview.txt
findmylocated-2023-11-08-133122.ips.txt
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.
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.
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 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()
}
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.
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>
#Preview {
SwiftUIView()
}
Error:Missing argument for parameter 'isShowing' in call
Whay? can you help me?