41,767 questions
3
votes
2
answers
1k
views
Why/when are uninitialized non-optional values allowed in Swift for EnvironmentObjects?
In Swift, this crashes at runtime:
class EmptyData: BindableObject {
let didChange = PassthroughSubject<EmptyData, Never>()
}
struct RandomView : View {
@EnvironmentObject var ...
9
votes
2
answers
2k
views
Issue when using Xcode 11 running Canvas on macOS Catalina
I have Catalina macOS version (10.15) installed and still the canvas is not showing up.
The error message I get from Xcode is
Select a scheme that builds a target which contains the current file,
...
0
votes
1
answer
71
views
How do I load a View with a View name? For example, I have a struct TextPage: View , how do I load this View via the string TextPage?
How do I load a View with a View name? For example, I have a struct TextPage: View , how do I load this View via the string TextPage ?
2
votes
0
answers
920
views
Reading EnvironmentObject<T> outside View.body
I constructed a BindableObject tied to my custom view.
I wanna update the array of items in this class
// in my vm:
class ViewModel {
func fetched() {
listView....
1
vote
2
answers
782
views
Adjusting width / horizontalAlignment with SwiftUI
I have the following layout achieved in SwiftUI:
VStack {
TextField(...)
TextField(...)
Button(...)
}
I tried making my VStack to be 50% of the superview, so I added the following modifier:
...
1
vote
1
answer
1k
views
Setting a height in a View and ignoring safe top edge
I want to display an MKMapView with a height that is the half of the screen's height and ignoring the top edge. This is my code:
import SwiftUI
import MapKit
struct ContentView : View {
var body:...
1
vote
0
answers
238
views
Migrate UITableView's and UICollectionView's Xib in SwiftUI
I have converted my existing Xib UI in SwiftUI.
Is it possible to use SwiftUI in existing UITableView and UICollectionView?
Here is the code i have done in SwiftUI
struct LandmarkList: View {
@...
3
votes
1
answer
9k
views
Using swiftUI how can i add datePicker only while textField is in editing mode?
I have added datePicker for now inside HStack. I want to show datePicker only when textField is in editing mode.
struct EditProfile: View {
@Binding var profile: Profile
var body: some View {
...
1
vote
1
answer
2k
views
Immutable some view body variable/opaque return in View
In Swift 5.1 there are opaque types. I see that e.g. body is a required protocol variable. It's contract is defined as follows:
var body: Self.Body { get }
It means we should be able to mark body as ...
118
votes
2
answers
13k
views
What enables SwiftUI's DSL?
It seems like Apple's new SwiftUI framework uses a new kind of syntax that effectively builds a tuple, but has another syntax:
var body: some View {
VStack(alignment: .leading) {
Text("...
1
vote
1
answer
169
views
What is the layout system?
In UIKit we used the autolayout system. What layout system does SwiftUI use?
How does it layout the UIView in the canvas?
14
votes
3
answers
7k
views
Order of modifiers in SwiftUI view impacts view appearance
I'm following the first tutorial in Apple's series explaining how to create & combine views in a SwiftUI application.
In step 8 of section 6 in the tutorial, we need to insert the following code:
...
3
votes
2
answers
3k
views
identified(by: \.self) - what does it do? [duplicate]
In this video: https://developer.apple.com/videos/play/wwdc2019/103/, the following snippet of code is shown at around 15:30:
...
ForEach(ContentSizeCategory.common.identified(by: \.self))
...
What ...
2
votes
1
answer
1k
views
SwiftUI - Preview canvas gives Coordinated install error
I am trying to run the Landmark sample for the SwiftUI, but getting following error
Error Domain=IXErrorDomain Code=29 "A coordinated install for com.example.apple-samplecode.Landmarks is already ...
6
votes
1
answer
8k
views
How to open SwiftUI preview side by side to the code? [duplicate]
I have created new app with swiftUI in xcode11. and not able to find Xcode preview like shown in wwdc19.
2
votes
2
answers
2k
views
Swift compiler issue when running Xcode 11 using SwiftUI [duplicate]
I'm trying to get my SwiftUI Demo running but I get weird compiler issues:
'Color' is not convertible to 'Color?'
Unable to infer complex closure return type; add explicit type to disambiguate
...
2
votes
1
answer
244
views
What is the property / $property syntax for bindings?
As seen in the handling user input tutorial.
struct LandmarkList: View {
@State var showFavoritesOnly = true
var body: some View {
NavigationView {
List {
...