Newest 'swiftui' Questions - Stack Overflow

Questions tagged [swiftui]

SwiftUI is Apple's declarative Swift API for defining graphical user interfaces. Use this tag for questions about SwiftUI on any platform.

0
votes
0answers
3 views

How to Modally push next Screen to be full in SwiftUI

how can I push a next SwiftUI View but present it over the full screen without swiping down feature like the Xcode 10 modal presentation. My current implementation, but it's not pushing onto the ...
0
votes
0answers
2 views

Is there a way to change the stroke/fill color of a sf symbol icon in swiftui?

I am looking for a way to change the stroke / fill color of a sf symbol icon in swiftui. I have tried .background(Color.red) but that just changes the background of the whole icon (no change is ...
0
votes
0answers
10 views

@ObjectBinding Does Not Work with a Protocol

I have a SwiftUI view that has a @ObjectBinding progression: Progressable like this: struct ProgressBarComponent : View { @ObjectBinding var progression: Progressable var progressAnimation: ...
1
vote
2answers
24 views

In SwiftUI how can I animate a button offset when displayed

In SwiftUI, I want a button to appear from off screen by dropping in from the top into a final position when the view is initially displayed, I'm not asking for animation when the button is pressed. ...
1
vote
1answer
24 views

How does one enable selections in SwiftUI's List

I am trying to create a simple multiple selection List with SwiftUI. I am unable to make it work. List takes a second argument which is a SelectionManager, so I tried creating a concrete ...
1
vote
1answer
30 views

SwiftUI or Beta-State leads to crash?

I'm experiencing weird behavior with SwiftUI and xCode 11 Beta 2, and I'm wondering whether it's related to wrong code or the beta-state. I have following code: import SwiftUI import Combine struct ...
0
votes
0answers
20 views

Xcode SwiftUI how to scroll the Preview Canvas?

I have started working with SwiftUI Demo. But I am not able to scroll the Preview canvas in Xcode. Yes there is button for zooming like - 100 + . I have seen a video where person is scrolling ...
0
votes
0answers
58 views

SwiftUI - Half modal?

I'm trying to recreate a Modal just like Safari in iOS13 in SwiftUI: Here's what it looks like: Does anyone know if this is possible in SwiftUI? I want to show a small half modal, with the option to ...
0
votes
1answer
37 views

Deciding what data model to use for simple time tracking app

I’m creating an app that is very simple in terms of the data it needs to store but as I am brand new to app development I’m looking for advice on what is the best method to store/retrieve/change the ...
2
votes
1answer
56 views

SwiftUI: Putting multiple BindableObjects into Environment

In SwiftUI it is possible to use the environmentObject method of the View object to put a single BindableObject into the environment. What if I want to put multiple BindableObjects at the same time ...
1
vote
0answers
20 views

SwiftUI memory leak when using UIViewControllerRepresentable

I have created a very simple example of how a UIViewController represented by UIViewControllerRepresentable is never deallocated. import SwiftUI struct ContentView : View { @State private var ...
2
votes
1answer
73 views

Is there a way to bind an optional to a Toggle / Slider with SwiftUI

I have a UInt? (optional) property in my data model that I am trying to bind to a Toggle and Slider with SwiftUI. I am trying to get to something like this: maximumRingsShownCount have value 4 (not ...
0
votes
1answer
29 views

Open multiple preview same time in SwiftUI

I know we can open multiple previews of different screen at same time in SwiftUI. Can anyone help me with the steps to achieve that.
-1
votes
1answer
49 views

What is firstIndex in SwiftUI - Swift

While following the Apple tutorial about SwiftUI I found this: 1| var landmarkIndex: Int { 2| userData.landmarks.firstIndex(where: { $0.id == landmark.id })! 3| } Inside the tutorial line 2 isn't ...
1
vote
2answers
31 views

How to set alignment in main body view?

I am trying to align an Image in the first body view to the top but can not find a way to do this. I want set an alignment to .top like you would do in a ZStack, like this: ZStack(alignment: .top) { ...
1
vote
1answer
60 views

How can I access a property of a subclass of UIView in a SwiftUI View?

I made a simple application. I made a subclass of a UIView which presents a UIButton. Whenever I tap the button, the value of the "number" property increases by 1. I integrated this custom UIView in a ...
1
vote
0answers
37 views

SwiftUI: Access @EnvironmentObject from AppDelegate

I want to use the applicationWillTerminate function to save some user defaults before the app closes. The data I want to save is stored in an EnvironmentObject. How can I access it from the ...
0
votes
2answers
26 views

SwiftUI - centre content on a List

How can I make this arrow on the centre of the list? struct ProductsList : View { var body: some View { VStack { List { Image(systemName: "shift") } } } }
-1
votes
1answer
33 views

SwiftUI @State var initialization issue

I would like to initialise the value of an @State var in SwiftUI trough the init() method of a Struct, so it can take the proper text from a prepared dictionary for manipulation purposes in a ...
2
votes
2answers
51 views

Best-practices to download data from server in SwiftUI

My question is a conceptual question. I have the following code: struct CategoriesList : View { @State private var categories: [CategoryMetadata] = [] var body: some View { ...
1
vote
1answer
31 views

SwiftUI - Segment Control with Lists

Im trying to make a Segment Control that handles Lists and/or Vstacks I was able to make a Segment Control with text, but not Lists import SwiftUI struct MaterialSegmentControl : View { @State ...
1
vote
1answer
36 views

SwiftUI dynamic List with Sections does not Layout correctly

I'm trying to create a simple dynamic list grouped into sections. (SwiftUI iOS13 Xcode11 beta 2) A simple static example would be : struct StaticListView : View { var body: some View { ...
1
vote
1answer
32 views

SwiftUI ForEach of dictionary identified issue

Using the given code below I try to iterate over the dictionary wordList which fails with the issue Instance method 'identified(by:)' requires that '(key: Int, value: [String : String])' conform to '...
0
votes
2answers
101 views

SwiftUI @Binding Initialize

Been playing around with SwiftUI and understood the concept of BindableObjects etc so far (at least I hope I do). I bumped into a stupid problem I can't seem to find an answer for: How do you ...
-9
votes
0answers
53 views

Recently Apple introduced the SwiftUI What is new in this update?

SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift. I want to know that in terms of coding what is new coming with SwiftUI?
1
vote
2answers
51 views

Type of expression is ambiguous without more context in Xcode 11

I'm trying to refer to an [Item] list within an @EnvironmentObject however when accessing it within a SwiftUI List, I get the error. What I don't understand is, this error doesn't pop up when ...
5
votes
2answers
92 views

This SwiftUI animation should only fade out. Why does it move to the right?

I'm having a hard time understanding why this happens. I reduced the problem to its minimum expression. I have a single Text view, that when removed, should just fade out. The .transition(.opacity) ...
1
vote
1answer
50 views

How should I comprehend the NavigationView declaration Code in SwiftUI

The declaration of 'NavigationView' in SwiftUI is so confusing.(Maybe I don't good at the Swift.) In the declaration 'NavigationView' is a struct, but the initializer even has no body, just like a ...
0
votes
2answers
151 views

Xcode 11 beta swift ui preview not showing

Just playing with Swift UI basic app and the preview canvas is not showing even though I'm in canvas mode. App runs, and I have this little snippet what am I missing? #if DEBUG struct ...
1
vote
1answer
82 views

SwiftUI ScrollView only scroll in one direction

Trying to make a custom list using a view as the list row style (to get rid of the ugly line separates in the list by default). However, once I put my ZStack rows inside a scroll view, the scroll ...
-1
votes
1answer
38 views

How to use Realm with Swiftui

I have been trying to figure out how to use Realm with SwiftUI. The problem is that SwiftUI and Realm both have a List type. When you import SwiftUI into your Realm model to make the class a ...
1
vote
2answers
87 views

Changing the color of a button in SwiftUI based on disabled or not

I have a textfield with a send button that's a systemImage arrow. I want the foreground color of the image to change depending on whether the textField is empty or not. (I.e. the button is gray, and ...
0
votes
2answers
75 views

SwiftUI iterating through dictionary with ForEach

Is there a way to iterate through a Dictionary in a ForEach loop? Xcode says Generic struct 'ForEach' requires that '[String : Int]' conform to 'RandomAccessCollection' so is there a way to make ...
0
votes
1answer
52 views

Aligning Contained Views in SwiftUI

OK. I am working on reproducing this project as a pure SwiftUI View. I have my work cut out for me. I know that the system is still pretty buggy. The first update helped a lot, but there's still ...
3
votes
1answer
53 views

In SwiftUI, what's the difference between .modifier and .layout

I cannot seem to find any difference between applying a ViewModifier using either .modifier or .layout. They both produce the same result. Anyone knows what's the difference between these two. There's ...
0
votes
0answers
30 views

App launches in simulator and preview but not on real iPhone or iPad [duplicate]

I try to create an app with the new SwiftUI framework and it works fine in the preview and the simulators. But when I connect my iPhone (XR) or iPad (6th Gen) (both running iOS 13 beta 2), the app ...
0
votes
2answers
69 views

There doesn't appear to be support for UITabBar in SwiftUI. Workarounds?

SwiftUI doesn't appear to support UITabBar. How can I integrate that capability? Merely wrapping the view like one would a (eg) MKMapView, doesn't work because of its need for deep integration with ...
-4
votes
0answers
35 views

Thread 1: EXC_BAD_ACCESS (code=2, address=0x102044190) Error when trying to run SwiftUI 'Hello World' application on iPhone XS Max

When creating a new SwiftUI / Single View project and attempting to run on my device I'm getting; Thread 1: EXC_BAD_ACCESS (code=2, address=0x102044190) @ line 26 of SceneDelegate.swift I haven't ...
0
votes
0answers
45 views

Cannot find memory leak, possibly due to SwiftUI

Problem I profiled my app and found that I have memory leaks. Unfortunately, I'm unsure how to diagnose it in this case. Here is what the memory leaks show in Instruments: Question It says that ...
-3
votes
1answer
119 views

How can I scrollToTop in SwiftUI

I am learning SwiftUI, but I have a problem... How can I scroll to top in ScrollView when the SegmentedControl value changed? This is code for the main view to show Data: var body: some View { ...
0
votes
0answers
34 views

How to realize a function to supervise when I scroll to the end of List() in swiftUI?

I don't know how to make swiftUI know when I scroll to the end of a List. The key problem is, I can't use .onAppear() function in the element in List(). I tried to develop a ios app demo, using List()...
0
votes
2answers
77 views

How to set a background color for the viewController in swiftUI?

I have been trying to set a background color for the whole viewController in swiftUI but I habe not able to. The view does no take the attribute .backgroundColor . I have tried using the ....
1
vote
0answers
58 views

How do I make my SwiftUI UIViewRepresentable respect intrinsicContentSize in previews?

When I create a view in SwiftUI and render it in an Xcode preview, using PreviewLayout.sizeThatFits, the preview adjusts its size according to its content. When I import a UIKIt view using ...
0
votes
1answer
94 views

SwiftUI : Segue navigation

I am trying to pass data from one screen to another, is it possible to create segue in swiftUI and use below method? prepare(for segue: UIStoryboardSegue, sender: Any?)
0
votes
1answer
32 views

Xcode Non public API

When I upload a test build using the default SwiftUI project and nothing else, just as it begins negotiating API with iTunes Connect, the upload terminates with error that build is using non-public ...
2
votes
1answer
56 views

Extra spacing in NavigationBarTitle in SwiftUI

I have a detail view that displays with an absurd amount of spacing and I can't figure out why. struct MessageDetailView : View { var friend: Friend var body: some View { ...
0
votes
1answer
51 views

How can I access TapGesture() action/result outside of a struct

I would like to grab the results from "(dream)" and display in another Text and/or View(), (As well as add up with results from other functions) My problem is I cannot work out how to access the ...
1
vote
1answer
87 views

Why The Navigation Title doesn't show up using SwiftUI?

I am learning SwiftUI using apple's official tutorial: https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation Everything works perfectly until I try to show navigation title on ...
3
votes
1answer
88 views

Make a grid of buttons of same width and height in SwiftUI

I'm trying to create a Calculator using SwiftUI, I'm struggling right now on creating the Grid of buttons to fill the available space horizontally Right now I'm just trying to make the buttons fill a ...
0
votes
1answer
96 views

Implement a collection view SwiftUI

How do I implement a collection view (that is, rectangles arranged in a grid) in SwiftUI? I've tried ForEach-ing over a range of values, then using the counter as an index for an Array but have had ...