Doesn't the iPad-simulator launch NavigationView App in Xcode 11 beta 5? - ipad

I am working on a universal-app and want to test it with the iPad-simulator in Xcode beta 5, but it shows me only a white screen. With the iPhone-simulator the app runs.
I have uninstalled Xcode and macOS Catalina completely and reinstalled both, but it doesn't help
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
Text("This is a great app")
}
}
}

I believe if you swipe in from the lefthand side of your screen it may appear.

Related

Does SwiftUI project always start with a UIHostingController

I started a new project in SwiftUI from Xcode's Template and run the app. When debugging the View Hierarchy I can see that the app creates a UIHostingController to wrap the SwiftUI's view.
Has this always been the case or this is an update in some iOS/Xcode version. Is there any version of the SDK that SwiftUI is running without the UIHostingController?
My project will use UIApplication.Window to get the top most UIController to show a SDK's SFAuthenticationViewController which takes a presented UIController as a parameter. Ensuring that the default UIHostingController exists in all versions (>=iOS 15) of the app is the priority concern.
If Apple changed how SwiftUI behaves since its launch (from no UIHostingController to with `UIHostingController) then they might switch it again, so I will go with an alternative approach.
I tried starting a new project on Xcode 14.0 and Xcode 14.2 with iOS 15.0 and iOS 16.2. All showing the default UIHostingController.

Excess padding while importing an Xcode 12 project to Xcode 13 beta 5

I imported my SwiftUI project which was created on Xcode 12 to Xcode 13 beta 5. However, when the app loads there is a lot of excess padding on top of the NavigationView. Has anyone else faced this issue? Because there was nothing such when I created and deployed on Xcode 12. Also, when I relaunch the app manually on my iPhone, the padding goes away for a while, and then randomly appears after a while.
The screen with excess padding: https://i.stack.imgur.com/nOrIH.png
Screen without padding/expected output:
https://i.stack.imgur.com/uFoiu.png
Here's the Minimal Reproducible Example:
struct ContentView: View {
var body: some View {
NavigationView{
VStack {
ForEach(data) { item in
Text(item.category)
}
}
.navigationBarTitle("My Passwords")
}
}
}

Xcode live canvas has different behaviour compared to the real complied version

Currently running iOS 15 (Xcode 13). I'm trying to dismiss views after a navigation link. After coding, I tried it using the Xcode canvas feature. When clicking the "Done" button in the toolbar, expected behaviour occurred. The view dismissed.
However when I compiled the app, by running it on an actual phone. The "Done" but ceases to work as expected (unlike the Xcode Canvas)
Code used to dismiss:
ToolbarItem(placement: .confirmationAction) {
Button("Done") {
print("go back")
self.presentationMode.wrappedValue.dismiss()
}
}
The links below are to videos showing how the behaviours differ:
Xcode Live Canvas behaviour
Complied on real iPhone behaviour
If someone could explain why this occurs / how I could fix it that would be brilliant.
Thanks,
Bradley :)

SwiftUI: Text + TextField in VStack results in "Unable to simultaneously satisfy constraints."

Here some minimalistic example for an app that has a Text and a TextField within a VStack:
import SwiftUI
struct ContentView: View {
#State private var textEntry : String = "Hello World"
var body: some View {
return VStack {
Text(textEntry)
TextField("Enter new text here", text: $textEntry)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
The app works fine, i.e. the Text widget displays what you type into the TextField widget. The problem is that you get an error (or warning) that the layout constrains can not be satisfied:
2020-12-29 10:31:13.800514+0100 SwiftuiTest[32286:2781544] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x600001d50f00 h=--& v=--& _UIButtonBarButton:0x7fba5550cee0.height == 0 (active)>",
"<NSLayoutConstraint:0x600001d4e7b0 _UIUCBKBSelectionBackground:0x7fba5550da00.bottom == _UIButtonBarButton:0x7fba5550cee0.bottom - 6 (active)>",
"<NSLayoutConstraint:0x600001d4e710 V:|-(6)-[_UIUCBKBSelectionBackground:0x7fba5550da00] (active, names: '|':_UIButtonBarButton:0x7fba5550cee0 )>"
)
Is it wrong to use a Stack here? Basically I just want to have a few Button, Text, TextField widgets that use the available height on the display ...
Update:
macOS 11.1
Xcode 12.3 (12C33)
iOS deployment target 14.3
iOS Simulator: e.g. iPad (8th generation)
$ xcodebuild -showsdks
iOS SDKs:
iOS 14.3 -sdk iphoneos14.3
iOS Simulator SDKs:
Simulator - iOS 14.3 -sdk iphonesimulator14.3
macOS SDKs:
DriverKit 20.2 -sdk driverkit.macosx20.2
macOS 11.1 -sdk macosx11.1
tvOS SDKs:
tvOS 14.3 -sdk appletvos14.3
tvOS Simulator SDKs:
Simulator - tvOS 14.3 -sdk appletvsimulator14.3
watchOS SDKs:
watchOS 7.2 -sdk watchos7.2
watchOS Simulator SDKs:
Simulator - watchOS 7.2 -sdk watchsimulator7.2
Project was created in Xcode with interface SwiftUI and life cycle SwiftUI App. This creates two Swift source files, e.g SimpleTestApp.swift and ContentView.swift:
File ContentView.swift was modified as shown above
File SimpleTestApp.swift was left unmodified and has the following content:
import SwiftUI
#main
struct SimpleTestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
If you look at the types referred to in the log _UIButtonBarButton and _UIUCBKBSelectionBackground you can see that the layout exception is happening in private elements you don’t control, down in the UIKit layer below SwiftUI. The names having a _ in front is a big giveaway.
This happens sometimes and unless it’s affecting the rendering of your UI, can be ignored. Annoying but not something you can control. From that perspective you can consider this to be a warning.
This is a bug in TextView and TextField introduced in iOS 14 and affects not only SwiftUI components but also storyboard based UI components. At the moment we'll have to ignore it.

SwiftUI iOS 14.2 beta, text disappearing from medium and large home screen widget?

Anyone else notice text disappearing from medium and large widget sizes? Small widget sizes working fine.
I have an app in the store and have been waiting for an iOS update to fix the flickering widget problem on iOS 14.0.1. I tried the Xcode beta to see if the 14.2 beta fixed the flickering issue, and it looks like it did, BUT now I'm seeing an issue where text shows for a split second and then fades to be completely transparent. If you swipe left or right to another page on the home screen, then swipe back, the text shows up again for a split second and then disappears again.
Anyone else noticing this issue?
Here is a video clip to show what I'm trying to describe. I set it up to show a medium sized widget on top and a small sized widget just below it so you can see that the issue doesn't seem to effect the small sized widget and you can get an idea on what the medium widget should look like.
https://youtu.be/h8szHHXavNo
I did some testing and found it is related to the text size and what simulator / preview device you have selected…
Start a new SwiftUI project in Xcode 12.2 beta 2
Add a Widget extension
Set the text in the body of the widget’s view to 48, example:
var body: some View {
Text(entry.date, style: .time)
.font(.system(size: 48))
}
If you view the preview set to an iPhone 11 Pro Max, the preview will show no text on the widget.
If you view the preview set to an iPod touch (7th generation) the text shows just fine on the widget…
To prove it isn’t the text being too large to fit on the widget, you can change it to:
var body: some View {
Text("T")
.font(.system(size: 48))
}
And it will still show on the iPod touch, but not show on the iPhone 11 Pro Max
Also, if you make text size 47, all of a sudden it shows up on both the iPhone 11 Pro Max and iPod touch previews…
Apparently there is an issue with text larger than 47 on widgets…
I hope this is only an issue in the simulator. I don't have a spare device to install the beta preview.

Resources