Search results for

swiftui

16,612 results found

Post

Replies

Boosts

Views

Activity

SwiftUI on WatchKit ignores Safe Areas
I've started trying too use SwiftUI on with WatchKit, but I'm having problems with getting Views to work within the defined Safe Areas. It seems by default that its working as if I has specified .edgesIgnoringSafeArea had been applied, when it hasn't. Does anyone know why this might be or how to force SwiftUI to work with Safe Areas on WatchKit?
0
0
548
Jul ’19
Reply to Core Data Model SwiftUI
Sorry for asking this newbie question. Let's consider a basic contact list app:Say I have a list of Row elements displaying only a photo and First Name. Tapping on a row will take you to a Detail page that shows other data like last name and date of birth.Am I supposed to create two separate viewmodels - one for the Row view and another for the Detail view?If so, should I be initialising two separate arrays of these when the app loads (and the dataStore gets initialised in SceneDelegate.swift)?When a user is in editing mode in the Detail page, is the SwiftUI View allowed' to call methods in the dataStore class directly? It seems very easy to do this with when I can set the dataStore as an @EnvironmentObject variable.I'm super new to MVVM and would appreciate any form of guidance.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’19
Storing SwiftUI Views in property
I am interested in storing one of several SwiftUI views as a destination for a dynamically generated button. Programmatically, I create a struct to store the modules to be created:struct Module: Identifiable { var id: Int var name: String var destinationView = NewsView() // var destinationView: View - - - does not work }An array exists which stores the modules to be created on the home page view:ForEach(sessionParts[currentSessionPart].modules) { module in Group { NavigationLink(destination: module.destinationView ) { ZStack { HomeScreenNav() // View defining button Text((module.name)) .font(.largeTitle) .color(Color.black) } } } }This works correctly and a button is created that links to the NewsView view. But if I try to define the variable by type View, it does not work. Nor can I overwrite the variable with a different View.I have stretched my limited Swift skills and tried a few things, but have been unable to get closer to a solution. Thanks for any help.
2
0
9.2k
Jul ’19
SwiftUI view and BodyTrackedEntity
In my project I have a SwiftUI that embeds the UIViewController for the body tracking example. This all compiles and runs fine on my iPad.However in my project I have other SwiftUI views. When I am trying to view them in the SwiftUI preview window (I am also on Catalina 10.15 beta 3) it is not able to display this view, even though it has absolutely nothing to do with the BodyTracking example it still complains about this file and displays the message Use of undeclared type 'BodyTrackedEntity' .I have even commented out the PreviewProvider for the BodyTracking view and it still has this error.My guess is that there is an issue with XCode 11 Beta 3 when trying to preview views it looks through every view and compiles all of them to see if they are correct, but it shoud only care about the one I have selected. Also it should know that the BodyTracking code won't work and simply ignore is warnings.Anyone else having these kind of issues when trying to make a SwiftUI based proj
2
0
1.8k
Jul ’19
Content depending height of Lists
Hi,I have the following screen that has two lists in VStacks for each (combining a headline) that I put into another VStack which makes up the screen (see HomeExample).I want the List (or better the VStack that contains a List) to size depending on the content of the List. So, for example, if the first List has just two elements, I want it to be smaller (at least if the second list hast more elements). If both lists have a lot elements, I want them to fair share the space.Is there a way in SwiftUI to archive that?import SwiftUI struct MyList : View { var headline: String var items: [Item] var body: some View { VStack() { Text(headline) .font(.headline) .padding(.top, 6) List { ForEach(items) { item in ItemView(item: item) } } } } } struct ItemView: View { var item: Item var body: some View { HStack { Image(systemName: square.stack.3d.up) VStack(alignment: .leading) { Text(item.headline) .font(.headline) Text(item.subHeadline) .font(.subheadline) } } } } struct Item: Identifiable { var id: UU
0
0
830
Jul ’19
Reply to project does not work on iOS 13 beta 3
Ok, I cleaned up my project completely leaving only a simple view with text label — it didn't help. Then I tried to launch the Landmarks project from the official SwiftUI tutorials, that definitely worked before and and it gave me the same SIGABRT error :-)So the problem is not with our code at least.I also tried to create an empty project in XCode and it worked without issues. Will try to create an empty project and copy all the code there and see if that works, too. Will update here.
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’19
Reply to Index out of range for TextField binding to an element in an array
Hi bfad,I played around with this a littlebit and I think I found a work around for this. Instead of using @State for mylist, if you move your list to a separate class conforming to BindableObject and using to refer to that in the view using @Objectbinding it works fine. See my code below. My threory is that SwiftUI gets confused when you mutate the @State mylist because myList is an array and arrays are structs. I am guessing it has a problem detecting changes when structs are mutated, but it is only a guess.// // ContentView.swift // ForumX // // Created by sumuhan umamaheswarampillai on 11/07/2019. // Copyright © 2019 sumuhan umamaheswarampillai. All rights reserved. // import SwiftUI struct ContentView : View { //@State var myList: [String] = [] @ObjectBinding var myClass: MyClass var body: some View { VStack (alignment: .leading) { AppendButton(myClass: myClass) ListView(myClass: myClass) Spacer() } } } struct AppendButton: View { //@Binding var myList: [String] @ObjectBinding var myCla
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’19
text alignment in SwiftUI
I would like to center align the text inside a TextField. I just couldn't find a way to do it. I know in UIKit you could domytext.textAlignment = .rightCould anyone post the equivenant of this in SwiftUI please?
4
0
19k
Jul ’19
Custom “list” view
In SwiftUI, a `List` will automatically format the sub views you pass it, so something like this:List { Text(A) Text(B) }Will result in both text views being correctly placed, with separators between them etc...Additionally, it is also possible to mix static and dynamically generated data, like this:List { Text(A) ForEach(foo) { fooElement in CustomView(fooElement) } Text(B) ForEach(bar) { barElement in CustomView(barElement) } }My goal is to write my own custom type that would allow this kind of use by its users (ie: a view that lets the users provide views using the new function builder DSL, without requiring them to write their own modifiers to place them on the screen), but I don't know at all what to put in the initialiser of my custom view.The native SwiftUI views are making use of `@ViewBuilder` and receive a generic type conforming to `View`, but the way they are able to extract elements (from, say, a `ForEach` view) is mysterious and I'm pretty sure it's not even possible.An example
0
0
603
Jul ’19
How to send email from SwiftUI view ?
I've been trying to send email from a SwiftUI view (see code further below).However, I'm running into the following issues:Non-class type 'SettingsView' cannot conform to class protocol 'MFMailComposeViewControllerDelegate'But if make SettingsView a class, then I get a ton of errors.Has anyone found a good way to solve this issue?import SwiftUIimport MessageUIstruct SettingsView : View, MFMailComposeViewControllerDelegate { var body: some View { Button(action: emailSupport) { Text(Email support) } } func emailSupport() { if MFMailComposeViewController.canSendMail() { let mail = MFMailComposeViewController() mail.mailComposeDelegate = self mail.setSubject(Some subject) mail.setToRecipients([someemail@example.com]) mail.setMessageBody(Some body, isHTML:false) present(mail, animated: true) } else { // show failure alert } } func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { controller.dismiss(animated: true) }}
3
0
17k
Jul ’19