Search results for

swiftui

16,623 results found

Post

Replies

Boosts

Views

Activity

Reply to How to initialise a @Binding
I found the answer after watching the WWDC talk on DataFlow through swiftUI. @Binding is used to pass read/write data from one view to the other. @Binding can never be 'The source of truth'. It is just a reference to a 'source of truth' that already exists.'Source of truth' is the original data that the view refers to (. To create a 'source of truth' with read-only acces you can use plain swift properties in the view struct. (Or use @Environment). If you need read/write access you have two options1) @State. You can use this option when the data you are using is completely local to the view (Such as your scroll position) which has no meening in your model2) BindableObject. Use this when you have data in your model that the view needs to read and write to.So @Binding is only a bridge that connects existing sources of data such as @State or @ObjectBinding. It can also access other Bindings as well.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’19
Switching to another view.
Hi, I'm trying to play with new SwiftUI, by trying to create a simple app. But I'm stuck a bit.My task is to create two screens: the login and dashboard screen.I've started with creating a single view app using SwiftUI, then created a view for the login screen, all fine. Now I need to close this view and open another. Before SwiftUI it was simple, I would do it with two storyboards one for the login screen, the second one for the dashboard and other navigation chains. Once the backend succeeded with login, I would change the storyboard with the dashboard one. On logout, back to the login storyboard.Now, using the SwiftUI I need to do the same.Currently, the only feasible way is to create the same two storyboards, then create UIHostingViewController for each view and so on.Is that the way it should work, or I've missed something? Should it also work without Viewcontrollers and Storyboards?Thanks in advance.
0
0
365
Aug ’19
Can Apple Put Example Code on GitHub?
I've observed that Apple is making a lot of changes to SwiftUI and Combine between beta releases. It's my opinion that the community would be better served if Apple put the example code on GitHub, which would allow us to see the changes as the APIs evolve.It would also help us if Apple updated the examples for each beta release. At this point, there are examples that do not build.
1
0
746
Aug ’19
Reply to Core Data Model SwiftUI
With the new @FetchRequest property wrapper, core data fetches can occur directly in the view, per below forum discussion:https://forums.developer.apple.com/message/374407#374407SceneDelegate:import UIKit import SwiftUI class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { let appDelegate = UIApplication.shared.delegate as! AppDelegate let context = appDelegate.persistentContainer.viewContext if let windowScene = scene as? UIWindowScene { let window = UIWindow(windowScene: windowScene) window.rootViewController = UIHostingController(rootView: ContentView().environment(.managedObjectContext, context)) self.window = window window.makeKeyAndVisible() } }ContentView:import SwiftUI import CoreData struct ContentView: View { @Environment(.managedObjectContext) var managedObjectContext @FetchRequest(fetchRequest: fetchRequest(), animation: nil) var pe
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’19
When adding multiple TextFields only last will show keyboard
I have a 3 TextFields in SwiftUI. one on top and two side by side underneath that.VStack{ //TF1 TextField(Duty, text: $dutyNumber) .textFieldStyle(RoundedBorderTextFieldStyle()) .padding([.leading], 50) .multilineTextAlignment(.center) .keyboardType(.numberPad) HStack{ //TF2 TextField(Start time, text: $dutyStartTime) .textFieldStyle(RoundedBorderTextFieldStyle()) .padding([.leading], 50) .multilineTextAlignment(.center) .keyboardType(.numberPad) //TF3 TextField(Finish time, text: $dutyFinishTime) .textFieldStyle(RoundedBorderTextFieldStyle()) .padding([.leading], 50) .multilineTextAlignment(.center) .keyboardType(.numberPad) } }However only the last textfield TF3 is interactive. Cannot select the first two TF1 & TF2. Can Tab into them with keyboard but cannot select them with a finger tap. If I change the order from TF1, TF2, TF3 to TF1, TF3, TF2 for example. Then TF2 is now interactive but TF1 & TF3 are not. Is this a bug with adding multiple TextFields in SwiftUI or am I missing s
1
0
2.6k
Aug ’19
Reply to How to implement Camera in SwiftUI?
Could you explain what you are looking for ?Is it a general question about using AVPlayer in SwiftUI ?If so, may have a look here:https://stackoverflow.com/questions/57024870/swiftui-beta-5-how-to-properly-code-avplayer-after-loading-a-video-from-the-de
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’19
Return to storyboard after segue to UIHostingController
HiI have implemented a set of SwiftUI views into an existing app that uses a storyboard. Using a UIHostingController I can navigate to my SwiftUI views perfectly. I am struggling to understand how I return to the storyboard view controller as I don't seem to be able to get a handle to the UIHostingController from within SwiftUI to pop it.Hopefully someone can help 🙂Thanks in advance,Mike.
3
0
2.1k
Aug ’19
Reply to Is SwiftUI backwards compatible with iOS 12 and below?
I'm extremely disappointed since I learned that SwiftUI is available from iOS13 only!This is ridiculous! I have many application that I'd like to renew, robust with this new programming structure but now I realise this will not happen. Sad.By disabling some iOS13 related properties e.g. color themes, sf icons and such they should allow us to compile SwiftUI for at least iOS10If they want to make Swift / SwiftUI best prog.lang. they have to consider this.Ever WWDC opening is starting with their billions of dollars budget information etc. so hire some developers for backward compatibility.Regards
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’19
Reply to Bug in Navigation From Section Rows
Found what I guess one could call a fix. Instead of using VStacks, use Groups. Working code is below.import SwiftUI struct NavLink : View { var body: some View { NavigationView { List { Section (header: Text(Section Header 1).font(.headline)) { Group { HStack { NavigationLink(destination: Text(This will go to view 1.)) { Text(Text1: ) .bold() Text(More text 1) } } HStack { NavigationLink(destination: Text(This will go to view 2.)) { Text(Text2: ) .bold() Text(More text 2) } } } } Section (header: Text(Section Header 2).font(.headline)) { Group { HStack { NavigationLink(destination: Text(This will go to view 3.)) { Text(Text3: ) .bold() Text(More text 3) } } HStack { NavigationLink(destination: Text(This will go to view 4.)) { Text(Text4: ) .bold() Text(More text 4) } } } } } .navigationBarTitle(Text(NavLink Demo), displayMode: .automatic) .listStyle(GroupedListStyle()) } } } #if DEBUG struct NavLink_Previews : PreviewProvider { static var previews: some View { NavLink() } } #endif
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’19
Building Lists & Navigation: Extra argument 'id' in call
I was going this tutorial:https://developer.apple.com/tutorials/swiftui/building-lists-and-navigationI got to the Generating Previews section:https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation#generating-previews-dynamicallyIt appears the code in Step 3 is broken. In particular Line 18 of LandmarkList.swift.ForEach([iPhone SE, iPhone XS Max], id: .self) { deviceName in LandmarkList()XCode complains about id: .selfExtra argument 'id' in callDoes anyone know why this is broken in their completed code? Thanks in advance.
5
0
2.1k
Aug ’19
Reply to UIViewControllerRepresentable and CNContactPickerViewController
With a big thank you to you, I can say that with the help from your example and a bit more digging, I was able to get mine to work. Here's the code below.import Foundation import SwiftUI import EventKitUI let eventStore = EKEventStore() struct EKEventWrapper: UIViewControllerRepresentable { typealias UIViewControllerType = EKEventEditViewController var theEvent = EKEvent.init(eventStore: eventStore) var coordinator = Coordinator() func makeUIViewController(context: UIViewControllerRepresentableContext<EKEventWrapper>) -> EKEventWrapper.UIViewControllerType { theEvent.startDate = Date() theEvent.endDate = Date() theEvent.title = The Main Event! let calendar = EKCalendar.init(for: .event, eventStore: eventStore) theEvent.calendar = calendar let controller = EKEventEditViewController() controller.event = theEvent controller.editViewDelegate = coordinator as EKEventEditViewDelegate return controller } func updateUIViewController(_ uiViewController: EKEventWrapper.UIViewControllerType, context: U
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’19