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.
Xcode Previews
RSS for tagCreate an app UI and configure almost everything your users see using Xcode Previews.
Posts under Xcode Previews tag
163 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
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?
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.
(Cross post from: Stack Overflow - https://stackoverflow.com/questions/64096402/swiftui-preview-sheet-w-o-running-live-preview)
Is it possible to create a SwiftUI preview of a presented sheet without running the Live Preview? For example:
struct Sheet_Previews: PreviewProvider {
static var previews: some View {
Text("Background").sheet(isPresented: .constant(true)) {
Text("Sheet")
}
}
}
The above results in the following preview:
(See image 1 on Stack Overflow - https://stackoverflow.com/questions/64096402/swiftui-preview-sheet-w-o-running-live-preview)
In order for the sheet content to be presented in the preview, you must run the Live Preview:
(See image 2 on Stack Overflow - https://stackoverflow.com/questions/64096402/swiftui-preview-sheet-w-o-running-live-preview)
Repro steps: Create new project
Create WidgetKit extension (verify that previews work)
Create dummy framework (verify that previews still work)
Link dummy framework to the widget extension
At that point, preview stops working with the following error:
"RemoteHumanReadableError
ProcessError: Failed to launch widget extension: The operation couldn’t be completed. (CHSErrorDomain error 1050.)"
What can I do to make this work?
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?
Hi everyone,
I'm trying to follow the Landmarks project tutorial and got stuck in the second part, in the second section (Create the Row View), step 6 where it says "Modify the text view to use the landmark property’s name." This must be done in the LandmarkRow.swift file.
https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation
The tutorial shows that after doing this, the preview will display the name of the landmark (Turtle Rock) instead of the usual "Hello world" greeting. But my replacement is not happening. Moreover, from this point on, the preview stops working. There are no error messages in the code, except for the message that the preview could not be performed.
I checked and rewrote the code several times, replaced the data source files, but nothing helped.
At the same time, the preview works well in other view files.
I can't figure out what's wrong with my code? Any ideas as to what the reason will be is appreciated.
Below is the code of two files, the LandmarkRow.swift, where view does not work, the second is ModelData.swift and it is related to the previous one.
LandmarkRow.swift
import SwiftUI
struct LandmarkRow: View {
var landmark: Landmark
var body: some View {
HStack {
landmark.image
.resizable()
.frame(width: 50, height: 50)
Text(landmark.name)
Spacer()
}
}
}
struct LandmarkRow_Previews: PreviewProvider {
static var previews: some View {
LandmarkRow(landmark: landmarks[0])
}
}
ModelData.swift
import Foundation
var landmarks: [Landmark] = load("landmarkData.json")
func loadT: Decodable(_ filename: String) - T {
let data: Data
guard let file = Bundle.main.url(forResource: filename, withExtension: nil)
else {
fatalError("Couldn't find \(filename) in main bundle")
}
do {
data = try Data(contentsOf: file)
} catch {
fatalError("Couldn't load \(filename) from main bundle:\n\(error)")
}
do {
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
} catch {
fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)")
}
}
I have an iOS app by using a swift package to hold most of the logic. However, the previews of SwiftUI views often fail with following error:
HumanReadableSwiftError
BuildError: failedToGenerateThunkInfo(Error Domain=com.apple.xcbuild Code=19 "could not generate preview info: noTargetBuildGraph" UserInfo={NSLocalizedDescription=could not generate preview info: noTargetBuildGraph})
To reproduce this, please clone https://github.com/pointfreeco/isowords and check for preview of ChangelogView.
SwiftUI Preview Don't work.
Progress Preparing iPhone Simulator for Previews.
SwiftUI
Xcode version 13.0
macOS Big Sur version 11.6
The Build for Previews builds all my targets including the test targets. Is there a way to configure the relevant targets? I do not see an option in the schema editor, and disabling Find Implicit Dependencies has no effect either.
Every time I work with Xcode Simulator or SwiftUI's Xcode Previews my Mac freezes and reboots. I get below report after restart:
panic(cpu 1 caller 0xffffff7fae0e7505): "Submission on work queue 33 failed due to insufficient space!\n" @IGGuC.cpp:2899
Panicked task 0xffffff95219449c0: 4 threads: pid 1358: SimMetalHost
Backtrace (CPU 1), panicked thread: 0xffffff9520c88540, Frame : Return Address
0xffffffe5a9882de0 : 0xffffff8015a81c8d
0xffffffe5a9882e30 : 0xffffff8015be1596
0xffffffe5a9882e70 : 0xffffff8015bd0963
0xffffffe5a9882ec0 : 0xffffff8015a21a70
0xffffffe5a9882ee0 : 0xffffff8015a8205d
0xffffffe5a9883000 : 0xffffff8015a81816
0xffffffe5a9883060 : 0xffffff8016315163
0xffffffe5a9883150 : 0xffffff7fae0e7505
0xffffffe5a9883160 : 0xffffff7fae05ecf7
0xffffffe5a9883250 : 0xffffff7fae084844
0xffffffe5a9883280 : 0xffffff7fae08f6e5
0xffffffe5a98832f0 : 0xffffff7fae9d75b7
0xffffffe5a9883330 : 0xffffff7fae06c73d
0xffffffe5a9883350 : 0xffffff7fae06cb5d
0xffffffe5a98833c0 : 0xffffff7fae09b89e
0xffffffe5a98835e0 : 0xffffff7fae070ed4
0xffffffe5a9883620 : 0xffffff7fae9ed118
0xffffffe5a9883650 : 0xffffff7fae070b00
0xffffffe5a9883690 : 0xffffff7fae9ed2a7
0xffffffe5a98836d0 : 0xffffff7fae9ed996
0xffffffe5a9883970 : 0xffffff7fae0714f4
0xffffffe5a98839a0 : 0xffffff7fae9ee8f1
0xffffffe5a9883a30 : 0xffffff7fae9ec94b
0xffffffe5a9883a90 : 0xffffff7fae9ec741
0xffffffe5a9883ae0 : 0xffffff7fae9eb81d
0xffffffe5a9883b20 : 0xffffff7fae071137
0xffffffe5a9883b60 : 0xffffff8016283a8c
0xffffffe5a9883cc0 : 0xffffff8015b872e6
0xffffffe5a9883dd0 : 0xffffff8015a5c9ab
0xffffffe5a9883e60 : 0xffffff8015a731f9
0xffffffe5a9883ef0 : 0xffffff8015bb35aa
0xffffffe5a9883fa0 : 0xffffff8015a22256
Kernel Extensions in backtrace:
com.apple.iokit.IOAcceleratorFamily2(462.8)[F0D1B5AF-356A-3F86-8829-8F00218602CB]@0xffffff7fae9a6000->0xffffff7faea10fff
dependency: com.apple.driver.AppleMobileFileIntegrity(1.0.5)[2B96E04B-E2A5-3296-AF14-6A766880A652]@0xffffff80171a1000->0xffffff80171c2fff
dependency: com.apple.iokit.IOGraphicsFamily(597)[BBEE13AB-2291-37D9-AAE4-9E565E8950A5]@0xffffff7faeb3f000->0xffffff7faeb6dfff
dependency: com.apple.iokit.IOPCIFamily(2.9)[654ABF9D-EB24-3B64-AB1C-EC2AC8357192]@0xffffff8018624000->0xffffff801864ffff
dependency: com.apple.iokit.IOReportFamily(47)[5578189C-7C1D-3158-B357-F8D6A216DCE1]@0xffffff8018661000->0xffffff8018663fff
dependency: com.apple.iokit.IOSurface(302.14)[F0BF8EFA-AA35-37B5-B3AB-A8BCF5E62024]@0xffffff8018794000->0xffffff80187b0fff
com.apple.driver.AppleIntelKBLGraphics(18.0.7)[1A72DE92-F799-3EFF-8AD4-B662C53C36AD]@0xffffff7fae059000->0xffffff7fae117fff
dependency: com.apple.iokit.IOAcceleratorFamily2(462.8)[F0D1B5AF-356A-3F86-8829-8F00218602CB]@0xffffff7fae9a6000->0xffffff7faea10fff
dependency: com.apple.iokit.IOGraphicsFamily(597)[BBEE13AB-2291-37D9-AAE4-9E565E8950A5]@0xffffff7faeb3f000->0xffffff7faeb6dfff
dependency: com.apple.iokit.IOPCIFamily(2.9)[654ABF9D-EB24-3B64-AB1C-EC2AC8357192]@0xffffff8018624000->0xffffff801864ffff
dependency: com.apple.iokit.IOSurface(302.14)[F0BF8EFA-AA35-37B5-B3AB-A8BCF5E62024]@0xffffff8018794000->0xffffff80187b0fff
Process name corresponding to current thread (0xffffff9520c88540): SimMetalHost (iPhone 12: default
Boot args: chunklist-security-epoch=0 -chunklist-no-rev2-dev chunklist-security-epoch=0 -chunklist-no-rev2-dev
Mac OS version:
21F79
Kernel version:
Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
Kernel UUID: 3C587984-4004-3C76-8ADF-997822977184
KernelCache slide: 0x0000000015800000
KernelCache base: 0xffffff8015a00000
Kernel slide: 0x0000000015810000
Kernel text base: 0xffffff8015a10000
__HIB text base: 0xffffff8015900000
System model name: Macmini8,1 (Mac-7BA5B2DFE22DDD8C)
System shutdown begun: NO
Hibernation exit count: 0
System uptime in nanoseconds: 2335401059040
Last Sleep: absolute base_tsc base_nano
Uptime : 0x0000021fc0c0295e
Sleep : 0x000000c429fd13d9 0x00000000bae420b6 0x000000a6581a552b
Wake : 0x000000c435bb1b42 0x00000000bae11627 0x000000c4332c18c2
Compressor Info: 24% of compressed pages limit (OK) and 12% of segments limit (OK) with 5 swapfiles and OK swap space
Zone info:
Zone map: 0xffffff805595c000 - 0xffffffa05595c000
. PGZ : 0xffffff805595c000 - 0xffffff805695d000
. VM : 0xffffff805695d000 - 0xffffff85233c3000
. RO : 0xffffff85233c3000 - 0xffffff86bcc8f000
. GEN0 : 0xffffff86bcc8f000 - 0xffffff8b896f5000
. GEN1 : 0xffffff8b896f5000 - 0xffffff905615b000
. GEN2 : 0xffffff905615b000 - 0xffffff9522bc1000
. GEN3 : 0xffffff9522bc1000 - 0xffffff99ef628000
. DATA : 0xffffff99ef628000 - 0xffffffa05595c000
Metadata: 0xffffffa079aee000 - 0xffffffa099aee000
Bitmaps : 0xffffffa099aee000 - 0xffffffa09caee000
last started kext at 1655076280961: >usb.cdc.acm 5.0.0 (addr 0xffffff7fae81d000, size 12288)
last stopped kext at 1766102575761: >usb.serial 6.0.0 (addr 0xffffff7fae893000, size 20480)
loaded kexts:
AGPM 129
!APlatformEnabler 2.7.0d0
X86PlatformShim 1.0.0
@filesystems.autofs 3.0
!AGFXHDA 140.3
!AUpstreamUserClient 3.6.9
!AMCCSControl 1.16
!ABridgeAudio!C 240.6
!AGraphicsDevicePolicy 6.5.7
BridgeAudioCommunication 240.6
!AAVEBridge 6.1
!A!IKBLGraphics 18.0.7
@AGDCPluginDisplayMetrics 6.5.7
pmtelemetry 1
!A!ICFLGraphicsFramebuffer 18.0.7
|IOUserEthernet 1.0.1
usb.!UUserHCI 1
!A!IPCHPMC 2.0.1
!AHV 1
!ADiskImages2 126.100.13
!A!ISlowAdaptiveClocking 4.0.0
!AThunderboltIP 4.0.3
BCMWLANFirmware4387.Hashstore 1
BCMWLANFirmware4378.Hashstore 1
BCMWLANFirmware4377.Hashstore 1
BCMWLANFirmware4364.Hashstore 1
BCMWLANFirmware4355.Hashstore 1
!AFileSystemDriver 3.0.1
@filesystems.tmpfs 1
@filesystems.lifs 1
@filesystems.hfs.kext 583.100.10
@BootCache 40
@!AFSCompression.!AFSCompressionTypeZlib 1.0.0
@!AFSCompression.!AFSCompressionTypeDataless 1.0.0d1
@filesystems.apfs 1934.121.2
!ABCMWLANBusInterfacePCIeMac 1
!ASDXC 3.2.1
|!ABCM5701Ethernet 11.0.0
@private.KextAudit 1.0
!AACPIButtons 6.1
!ASMBIOS 2.1
!AACPIEC 6.1
!AAPIC 1.7
@!ASystemPolicy 2.0.0
@nke.applicationfirewall 402
|IOKitRegistryCompatibility 1
|EndpointSecurity 1
@Dont_Steal_Mac_OS_X 7.0.0
@kec.!AEncryptedArchive 1
!UMergeNub 900.4.2
IO!BHIDDriver 9.0.0
driverkit.serial 6.0.0
@kext.triggers 1.0
!ASMBus!C 1.0.18d1
!AAudioClockLibs 140.1
!A!ILpssUARTv1 3.0.60
!A!ILpssUARTCommon 3.0.60
!AOnboardSerial 1.0
usb.IOUSBHostHIDDevice 1.2
|IOAudio!F 340.2
@vecLib.kext 1.2.0
!AGraphicsControl 6.5.7
|IONDRVSupport 597
X86PlatformPlugin 1.0.0
..............
Below is my system configuration:
Model Name: Mac mini
Model Identifier: Macmini8,1
Processor Name: 6-Core Intel Core i5
Processor Speed: 3 GHz
Number of Processors: 1
Total Number of Cores: 6
Memory: 8 GB
System Version: macOS 12.4 (21F79)
Any help would be appreciated, thanks!
The the enhancements to Xcode Previews in Xcode 14 are very helpful.
I just had a situation where I wanted to take a screen capture of a preview of a view. Is there a built-in way to do that from Xcode, similar to taking a screen capture of the simulator screen?
I realize I can just use a system-level screen capture, but then I have to adjust the size of what I capture to the area of the view in the preview.
It would be great to just be able to have a button or shortcut and have the correct area captured.
Failed to decode landmarksData.json from bundle because it appears to be invalid JSON.
Full disclosure - Im extremely new to this and am playing around with the swift tutorials to see what it can do and see if I could build an app.
Any advice is appreciated.
I added a few locations to the SwiftUI Tutorial for Lanmarks and this is what happened. I have checked that JSON file and all commas are in the correct place everything is correct but im getting this error. Not sure what im doing incorrectly.
Can anyone give me assistance on how to fix this. I can only preview favorite button, circle image and map. Everything else appears as Fatal Error in ModelData.
HI,
I have an issue displaying SwiftUI previews with Xcode 14.
My project has iOS and an watchOS Target. It also includes a lot of SPM, most of them only used by the PhoneApp. The project build successfully for both iOS and watchOS.
I can see that when building the watch target, only SPM that are included in this target are build for for watchOS
The issue is when I try to build a swiftUI preview of the watch target. In this case I can see on the build for Preview log that Xcode try to build ALL spm defined in the Xcode project, including the one that are not used by the watch Target,
As a lot if spm are for iOS only, and doesn't build for watchOS, the build for preview fails, and I'm unable to preview my swiftUI views on the AppeWatch.
Note that my project is working fine on Xcode 13.
This issue is easy to reproduce in any Xcode projects containing a iOS and watchOS target by adding a SPM that is only for iOS.
Any workaround to fix this issue ?
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>
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 I have a problem with xCode, I have this error : Cannot find « string » in scope.
Thank you so much for your help
Photos:
My code:
//
// AuthviewModel.swift
// iSpeak
//
// Created by Sayan on 21.11.22.
//
import Foundation
import Firebase
class AuthViewModel: ObservableObject {
var manager = FirebaseManager.shared
@Published var isFinishedConnecting: Bool = false
@Published var isAuth: Bool = false
@Published var showError: Bool = false
var errorString: String = ""
var datas: [String: Any] = [:]
var auth: Auth {
return manager.auth
}
init() {
observeAuthentication()
}
func observeAuthentication() {
auth.addStateDidChangeListener(handleChangeListener)
}
func handleChangeListener(auth: Auth, user: User?) {
self.isFinishedConnecting = true
self.isAuth = user != nil
}
func signIn(email: String, password: String) {
guard checkValue(_string: email, value: "adresse email") else { return }
guard checkValue(_string: password, value: "Mot de passe") else { return }
}
func createUser() {
}
func checkValue(_string: String, value: String) -> Bool {
let isNotEmpty = string != ""
self.errorString = !isNotEmpty ? "" : "Merci d'entrer (value) pour continuer"
self.showError = !isNotEmpty
return isNotEmpty
}
}
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!
Recently have been working on this project just fine... had an app throw a warning for some malware called InstallCore. Removed the malware and now I am getting this on every preview, regardless of the device preview type.
I've tried clearing derived data, cache, etc. No dice.
Could not install the preview host "AppName.app" on iPhone 14 Pro Max: Failed to get parent identifier for BUNDLEIDENTIFIER.
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.