struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewDevice(PreviewDevice(rawValue: "iPhone 11"))
}
}
However, the device is not shown in the preview. I ran "xcrun simctl list devicetypes" in terminal which does show the simulator. Is this normal behavior or am I missing something. The goal is that I want to show how the app looks with the iPhone resolution. I am using xCode 13.
I have meet same issue at Xcode Version 14.1 (14B47b).
In my case ,this is because an unavailable simulator model has been selected like "iPhone 11",Xcode automatically chooses a available preview device based on your currently selected run destination.
Like this:
(selected iPhone SE2 but automatically chooses iPhone14 Pro)
Press control and option, click previewDevice, and then select an available model in the inspector can fix it:
(iPhone 14 selected, preview shows as expected)
If there is no model you want in these options, you can add it in the menu Window -> Devices and Simulators first.
Hope this helps you.
Related
I have a SwiftUI App which uses regular Button views and our customers use AssistiveTouch's DwellControl feature quite often. On iOS 13 DwellControl was working fine but on iOS 14 beta 8 DwellControl fails to be able click on those buttons.
The Buttons can be tapped by finger and clicked with the normal mouse but not with the DwellControl feature.
I have tried adding accessibility traits like isButton, but nothing works.
Has anyone encountered the same problem and has a solution or any insight at all? I know this is quite niche but any help is appreciated!
EDIT:
I have tested it with a very simple example, including one a Button and it works fine. It seems to be a side effect of some sorts in my specific App.
I have several ZStacks which show and hide some views like modals and popovers. Could this be the source of failure?
What I don't get is that the Buttons can be tapped and clicked... If a view was blocking the Button then this shouldn't be possible right?
I have tried Release and Debug builds which does not make a difference.
When DwellControl is activated and the cursor is on the Button that shall be clicked, tapping doesn't work either. But when the cursor is nowhere near the Button, tapping works fine.
I have send a report via Feedback to Apple.
EDIT:
I found the cause. ScrollView somehow prevents all DwellControl clicks from happening. That happens whenever a ScrollView is somewhere present in one of the Views.
Minimal example:
struct ContentView: View {
#State var show = false
var body: some View {
ZStack {
ScrollView {
Button(action: {
print("This should be printed but isn't....")
}, label: {
Text("Button in ScrollView")
})
}
}
}
}
I know its niche but maybe someone needs this.
There are other components which are affected and cause the same behaviour:
ScrollView
TextField
Slider
Stepper
UIViewRepresentable
For me this is a big issue, since our customers use DwellControl quite often.
EDIT:
This can be replicated in the newest iOS 14.2 beta 1:
import SwiftUI
#main
struct TempSwitUIApp: App {
#State private var text: String = "I am a text"
var body: some Scene {
WindowGroup {
Button(action: {
print("\(UUID()) \(self.text)")
}, label: {
Text("Print text to the console")
})
TextField("Hello", text: self.$text)
}
}
}
I updated my issue with Apple but haven't heard from them yet.
Using iOS 14 and Xcode 12.0 beta 6 if I try and use a simple TextField anywhere
import SwiftUI
struct ContentView: View {
#State private var name: String = "Tim"
var body: some View {
VStack {
TextField("Enter your name", text: $name)
Text("Hello, \(name)!")
}
}
}
the keyboard opens but then the CPU goes to 99%/100% and app is frozen.
Is this a known issue? How do I fix it?
This bug exists since the 14.0 betas and has not been fixed so far :/ I tried to search for workarounds or solutions but there seems to be none at the moment.
Once the user activates an input field, the CPU goes to 95%-100% and stays there until you actually quit the app.
I found some reason, If you use some .onAppear listener, When device keyboard is opened, application is being crazy if you set or change any #EnvironmentObject variable using .onAppear listener anywhere on your app. But it is not for all .onAppear... it was really weird. I searched piece by piece those when I have noticed.
Using Xcode 12 beta (12A6159) on macOS Catalina 10.15.5 (19F101) when I press "Back" button in NavigationView, navigating back from a pushed View, I see this warning in the console.
[UIContextMenuInteraction] Attempting -[UIContextMenuInteraction
dismissMenu], when not in an active state. This is a client error most
often caused by calling dismiss more than once during a given
lifecycle. (<_UIVariableGestureContextMenuInteraction:
0x6000037689a0>)
I did not get this warning on Xcode 11.5.
The code is dead simple:
var body: some View {
NavigationView {
NavigationLink(destination: gameScreen) {
Text("Start game")
}
}
}
After having navigated to gameScreen and then pressing the "Back" button in the NavigationBar I see the logged warning in the console.
I have not upgraded to any of the new SwiftUI stuff like App or SceneBuilder etc...
My SwiftUI Canvas has disappeared. Has it crashed? I don't see any output in the console.
I have macOS 10.15 Catalina (the requirement for SwiftUI) and Xcode 11+.
Solution 1
If your SwiftUI view were named "TestView," the following would be necessary to display the Canvas:
#if DEBUG
struct TestView_Previews : PreviewProvider {
static var previews: some View {
TestView()
}
}
#endif
Simply copy the above code and change the instances of "TestView" to whatever your file is called. Click "Resume" and the canvas should load up.
Solution 2
If the above did not work, try to clear the derived data from the machine by first closing Xcode, then navigating in Finder to
~/Library/Developer/Xcode/DerivedData
Drag all of the files to the trash and restart Xcode. Don't worry, none of your code will be deleted, this is just the data that Xcode creates to help it to compile your project faster.
I'm running XCode 8.1 and can not get my IBInspectable attributes appearing in Xcode. Any known issues with XCode 8.1 (swift 3) in this area? Or any issues with what I'm trying to do here?
Steps:
Create a simple IOS app
Created the following "customControl" class
In the app storyboard, drag a UIView onto the storyboard, and then change the class type of the "customControl"
I note XCode going through the "refresh views" stage, however no items get added to the "user defined runtime attributes" area?
Code:
import UIKit
#IBDesignable
class customControl : UIView {
#IBInspectable
var customAttribute: UIColor = UIColor.blue
}