Hello,
In the recent update i installed of Mac and Xcode. After working out the initial problem of Simulator runtimes not found, I created a new project with new problem where When i switch to a different file, or Hide and Show Canvas again it just resets to its size (approx. 50%) of Editor. The current solution is to Pin it and it stays there with right size (No matter which file - with any extension - to switch from or to then).
I tried deleting Derived Data folder, Rebooting Mac, Reintsalled Xcode (When Simulator Runtime not found problem) but the problem is there.
I also tried trait property but fixedLayout do not work with iOS.
Xcode Previews
RSS for tagCreate an app UI and configure almost everything your users see using Xcode Previews.
Posts under Xcode Previews tag
79 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello,
Xcode seems to reset the canvas preview every time I open a file that does not have a preview. This is extremely annoying when working with two editor tabs.
The resize happened before only after restarting Xcode since a few weeks it happens always when opening another file.
The preview phone does not even take advantage of the resize.
Is there a way to fix this?
When I work with the file:
After opening a file without preview and going back:
I'm trying to create a preview for my live activities when it's stale, so I created a preview provider. I followed some examples, but XCode says I'm missing preview context. Am I doing something wrong?
I tried adding .previewContext(WidgetPreviewContext(family: .systemSmall)) but that doesn't seem to work.
Hi! I develop an iOS library and I met an issue with SwiftUI previews in iOS app project with my library integrated. After I open preview, build for preview finishes successfully, but preview itself never appears. I failed to find any error messages or any other indicators of what went wrong or how to fix it. Switching to legacy preview execution seems to fix problem, but I think that is not ideal. Could you help fixing this?
Xcode 16.2, Simulator iPhone 16, iOS 18.2
Project to reproduce -
https://drive.google.com/file/d/1cU6JKwshK_wQfe9YIqcMg3UGWq45OYlx/view?usp=sharing
Preview diagnostics - https://drive.google.com/file/d/1kPcgVSSqreiepGuqhdIoCW2rLSicgsWr/view?usp=sharing
It seems like, by default, the preview pane tries to align to 50% of the editor pane's width.
I prefer to shrink the preview pane to around ~30% of the screen so I have more space for code. This used to work fine—at least until I restarted Xcode. I never understood why the setting wouldn’t persist across sessions, but fine, that was a tradeoff I was willing to live with.
However, with Xcode 16.3, it seems like Xcode forgets the manually adjusted preview pane width as soon as I switch to a different file. This has definitely impacted my productivity, as I now find myself readjusting the pane size dozens of times in a single session.
Am I holding it wrong? Is anyone else experiencing this?
And while we’re at it—why not make this a persistent setting so everyone can tweak the width to their liking?
Hi! I´m new developing in this app, I have a problem.
The preview screen is showing me the image bellow, There is no other response, I dont know what could happened.
Thanks!
Hello,
I've got a View that loads data from UserDefaults.
I want to set the value of the UserDefault in the preview so i can see how it looks while developing. However when i am trying to set it in preview, i get the following error when i try set it in preview.
'buildExpression' is unavailable: this expression does not conform to 'View'
What is the correct way to set the user defaults in preview?
import Foundation
class PreferencesViewModel: ObservableObject {
@Published var maximumDistance: Double = UserDefaults.standard.value(for: .maximumDistance) as? Double ?? PreferencesViewModel.maximumDistanceOptions[0] {
didSet {
UserDefaults.standard.set(maximumDistance, for: .maximumDistance)
}
}
#Preview {
let preferencesViewModel = PreferencesViewModel()
preferencesViewModel.maximumDistance = 5.0
PreferencesView()
.environmentObject(PreferencesViewModel())
}
Xcode Preview is not working.
Successed to build Preview but error message displays like below:
I think it's maybe related with loader path followed by error details below.
I created xcproj file using tuist 4.19.0.
How can I fix this issue?
Error Details
Upgrading to Xcode 16.3, all previews across my AppKit project stopped working.
The error message I'm getting is especially baffling. It says the project could not be built with incremental compilation because SWIFT_COMPILATION_MODE is set to "incremental":
I tried clearing DerivedData with no effect. When I click the diagnostics button the information given is not very revealing, at least not to me.
If I open the project in Xcode 16.2 everything works perfectly again.
I switched over to Previews for all new code but this error situation is quite demotivating. Does anyone have any suggestions?
Consider this stripped-down example of a view with a view model:
import Observation
import SwiftUI
struct MainView: View {
@State private var viewModel = ViewModel()
private let items = [0, 1, 2]
var body: some View {
List {
GroupedItemsView(
viewModel : viewModel.groupState,
groupedItems : [(0, items)]
)
}
}
}
fileprivate struct GroupedItemsView<ViewModel: GroupsExpandable>: View {
let viewModel : ViewModel
let groupedItems : [(ViewModel.GroupTag, [Int])]
var body: some View {
ForEach(groupedItems, id: \.0) { groupTag, items in
Text("nothing")
}
}
}
fileprivate protocol GroupsExpandable: AnyObject { // HERE
associatedtype GroupTag: Hashable
}
fileprivate final class GroupState<GroupTag: Hashable>: GroupsExpandable {}
@Observable
fileprivate final class ViewModel {
var groupState = GroupState<Int>()
}
#Preview {
MainView()
}
This compiles and runs fine in the Simulator, but it crashes in the Preview.
However, when I remove the fileprivate modifier before GroupsExpandable (see HERE), it also runs in the Preview.
What is the reason for this? Bug in Preview? Error on my side somewhere?
Thanks.
System is Xcode Version 16.3 (16E140) on a MacBook Pro 2018 (Intel) running Sequoia 15.3.2
Devices are iPhone 16 Pro Max with iOS 18.3.1, compiler is set to Swift 6.
Xcode16.3 SwiftUI Preview Library not loaded: /usr/lib/swift/libswiftWebKit.dylib
Untitled.rtf
So I believe my machine JUST updated to Xcode 16.3 (16E140). But it definitely just installed the latest iOS simulator 18.4.
However, now my preview will sometimes give me the error Failed to launch app ”Picker.app” in reasonable time.
If I add a space in my code, or hit refresh on the Preview, then it will run on the second or third attempt. Sometimes in between the refreshes, the preview will crash, and then it will work again.
Anyone else experiencing this? Any ideas?
Thanks
I attempted to create a SortDescriptor using a method in enum to sort various different models in SwiftUI lists.
But it causes crashes in Xcodes previews but not in the simulator, and I don't know why.
Maybe someone could suggest changes.
extension Item:ListSorting {} //List sorting is a protocol given to various Models
enum ListSortingStyle<T>:String,CaseIterable where T:ListSorting {
case alphabetical = "A…Z"
case alphabeticalReverse = "Z…A"
case createDate = "Newest"
case createDateReverse = "Oldest"
case editDate = "Latest Edit"
case editDateReverse = "Oldest Edit"
/// Returns a SortDescriptor matching the enumeration
func sortDescriptor() -> SortDescriptor<T> {
switch self {
case .alphabetical:
SortDescriptor<T>(\.name, comparator: .localized, order: .forward)
case .alphabeticalReverse:
SortDescriptor<T>(\.name, comparator: .localized, order: .reverse)
case .createDate:
SortDescriptor<T>(\.creationDate, order: .forward)
case .createDateReverse:
SortDescriptor<T>(\.creationDate, order: .reverse)
case .editDate:
SortDescriptor<T>(\.editDate, order: .forward)
case .editDateReverse:
SortDescriptor<T>(\.editDate, order: .reverse)
}
}
}
Which is used in
struct ItemsList: View {
@Environment(\.modelContext) private var modelContext
@Query private var items:[Item] = []
init(sortStyle:ListSortingStyle<Item> = .alphabetical) {
let sortDescriptor = SortDescriptor<Item>(\.name, comparator: .localized, order: .forward) //(1) This works in preview & simulator
//OR
let sortDescriptor2 = sortStyle.sortDescriptor() //(2) This crashes in a preview when used in a fetch not in the iOS simulator
print(sortDescriptor,sortDescriptor2)
let descriptor = FetchDescriptor<Item>(sortBy:[sortDescriptor2])
self._items = Query(descriptor)
}
var body: some View {
...
}
}
As far as I can see both methods create a SortDiscriptor. If I print the sortDescriptor variable in they look almost identical:
//1
SortDescriptor<Item>(
order: Foundation.SortOrder.forward,
keyString: nil,
comparison: Foundation.SortDescriptor<MyApp.Item>.AllowedComparison.comparableString(
(extension in Foundation):Swift.String.StandardComparator(options: __C.NSStringCompareOptions(rawValue: 0),
isLocalized: true,
order: Foundation.SortOrder.forward),
\Item. <computed 0x0000000340213b18 (String)>)
)
//2
SortDescriptor<Item>(
order: Foundation.SortOrder.forward,
keyString: nil,
comparison: Foundation.SortDescriptor<MyApp.Item>.AllowedComparison.comparableString(
(extension in Foundation):Swift.String.StandardComparator(options: __C.NSStringCompareOptions(rawValue: 0),
isLocalized: true,
order: Foundation.SortOrder.forward),
\Item.<computed 0x0000000340022174 (String)>)
)
But the one created with the generic method on the enum crashes with the error message:
CrashReportError: Fatal Error in DataUtilities.swift
MyApp crashed due to fatalError in DataUtilities.swift at line 64.
Couldn't find \Item.<computed 0x0000000340022174 (String)> on Item with fields [SwiftData.Schema.PropertyMetadata ...
I keep running into the following issue when trying to run preview for my application in Xcode.
FailedToLaunchAppError: Failed to launch app.a
/Users/me/Library/Developer/Xcode/DerivedData/a-aloudjuytoewlldqjfxshbjydjeh/Build/Products/Debug/a.app
==================================
| [Remote] JITError
|
| ==================================
|
| | [Remote] XOJITError
| |
| | XOJITError: Could not create code file directory for session: Permission denied`
Hi everyone,
I'm encountering an issue when trying to run Xcode Previews for my HelloWorldApp on a real iPhone device. The app fails to install, and I get the following error message:
Development Environment:
Xcode Version: 16C5032a
macOS Version: 23H420
Test Device (iPhone): iPhone 12 mini, iOS 15.5 (19F77)
MacBook: MacBook Air (M1, arm64e)
Error Message:
Whenever I attempt to preview the app using SwiftUI Previews on my iPhone (iPhone của Định), I get the following installation error:
FailedToInstallAppError: Failed to install ”HelloWorldApp.app”
Could not install the preview host ”HelloWorldApp.app” on iPhone của Định
Here’s part of the detailed log:
agentBundle = com.DihNgx.HelloWorldApp {
url: file:///Users/dihngx/Library/Developer/Xcode/DerivedData/HelloWorldApp-eyeszqttvaydocbdmoiwcczlazrt/Build/Intermediates.noindex/Previews/iphoneos/HelloWorldApp/Products/Debug-iphoneos/HelloWorldApp.app
signingInformation:
Code Signing {
identifier: com.DihNgx.HelloWorldApp
identity: A9A830FA23874E2047C974D6621D441EB9CBC7CC
hasGetTaskAllow: true
isSandboxed: false
}
}
Device Information:
Device Name: iPhone của Định
Device Identifier: 00008101-001C482922C0001E
iOS Version: 15.5
Provisioning profile installed: "iOS Team Provisioning Profile: com.DihNgx.HelloWorldApp"
Steps I’ve already tried (but the issue persists):
Ensured that Xcode recognizes the iPhone and that the device is connected properly.
Checked Code Signing and Provisioning Profile (no issues were shown).
Cleaned the build folder (Cmd + Shift + K) and deleted Derived Data.
I’d really appreciate any advice or suggestions on how to solve this issue. Has anyone else faced a similar error or knows how to fix this? Thanks so much in advance!
I'm having an issue specifically with SwiftUI previews in my iOS project. The project builds and runs fine on devices and simulators (in Rosetta mode), but SwiftUI previews fail to load in both Rosetta and native arm64 simulator environments. The main error in the preview is related to the Alamofire dependency in my SiriKit Intents extension:
Module map file '[DerivedData path]/Build/Products/Debug-iphonesimulator/Alamofire/Alamofire.modulemap' not found
This error repeats for multiple Swift files within my SiriKit Intents extension. Additionally, I'm seeing:
Cannot load underlying module for 'Alamofire
Environment
Xcode version: 16.2
macOS version: Sonoma 14.7
Swift version: 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Dependency management: CocoaPods
Alamofire version: 5.8
My project is a large, older codebase that contains a mix of UIKit, Objective-C and Swift
Architecture Issue: The project only builds successfully in Rosetta mode for simulators. SwiftUI previews are failing in both Rosetta and native arm64 environments. This suggests there may be a fundamental issue with how the preview system interacts with the project's architecture configuration. What I've Tried I've attempted several solutions without success:
Cleaning the build folder (⇧⌘K and Option+⇧⌘K)
Deleting derived data
Reinstalling dependencies
Restarting Xcode
Removing and re-adding Alamofire
Swift Package:
I have an old objc library, that is added as XCFramework to swift package as a binary target.
targets: [
.target(
name: "CoreServices",
dependencies: ["OldContainer"],
path: "CoreServices"
),
.binaryTarget(
name: "OldContainer",
path: "Frameworks/OldContainer.xcframework"
),
]
This serves the purpose, it builds fine and able to run on simulator. However this framework is breaking the Xcode previews.
Error:
== PREVIEW UPDATE ERROR:
[Remote] JITError: Runtime linking failure
Additional Link Time Errors:
Symbols not found: [ _OBJC_CLASS_$_SCSecureServicesFactory ]
==================================
| [Remote] LLVMError
|
| LLVMError: LLVMError(description: "Failed to materialize symbols: { (static-Login, { __replacement_tag$1015 }) }")
== VERSION INFO:
Tools: 16C5032a
OS: 23G93
PID: 38675
Model: MacBook Pro
Arch: arm64e
== ENVIRONMENT:
openFiles = [
/Users/../Documents/GitHub/Packages/Login/Sources/Login/LoginView.swift
]
wantsNewBuildSystem = true
newBuildSystemAvailable = true
activeScheme = Launch
activeRunDestination = iPhone 16 Pro Max variant iphonesimulator arm64
workspaceArena = [x]
buildArena = [x]
buildableEntries = [
Login
Login
]
runMode = JIT Executor
== SELECTED RUN DESTINATION:
Simulator - iOS 18.2 | iphonesimulator | arm64 | iPhone 16 Pro Max | no proxy
== EXECUTION MODE OVERRIDES:
Workspace JIT mode user setting: true
Falling back to Dynamic Replacement: false
Based on the error, SCSecureServicesFactory is an objc file inside the XCFramework. Since this is a binary target, I could not add a swift setting module map flag to the XCFramework.
Is there any workaround to get the previews working ? Or Am I blocked until the library is converted into swift ?
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Swift Packages
Developer Tools
Xcode Previews
I am at a loss as to why, since the latest update, that my preview pane is no longer working. May i have some assistance on the matter? Thank you in advance! 😀✌️
In order to setup a preview, I need to create a Book; to do that, I need to await a function – however, one cannot await inside a Preview:
import SwiftUI
struct BookView: View {
let book: Book
var body: some View {
VStack {
Image(book.thumbnail, scale: 1.0,
label: Text(book.title))
}
}
}
#Preview {
let url = URL(filePath: "/Users/dan/Documents/Curs confirmare RO.pdf")!
// 👇 here, `createBook` should be awaited; but how?
let book = createBook(for: url, of: CGSize(width: 254, height: 254), scale: 1.0)
BookView(book: book)
}
Greetings...
I am trying to use @Namespace for my matchedGeometryEffect use case.
prior to Xcode 15 beta the following code worked just fine:
struct ChapterItem_Previews: PreviewProvider {
@Namespace static var namespace
static var previews: some View {
ChapterItem(namespace: namespace, show: .constant(true))
}
}
However trying to do the same within the new Xcode 15 beta #Preview Macro
#Preview {
@Namespace var namespace
ChapterItem(namespace: namespace, show: .constant(true))
}
produces the following error message:
Ambiguous use of 'Preview(_:traits:body:)'
May I kindly get assistance on the proper way I can get this to work in Xcode 15 beta?
Please be as detail as you can since I'm still new to swiftUI as well Thank You.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Xcode
Xcode Previews
wwdc2023-10252
wwdc2023-10165