swiftui

SwiftUI List with Section Index on right hand side?

最后都变了- 提交于 2021-02-05 20:33:34
问题 Is it possible to have a List with an index on the right hand side, like the example below in SwiftUI? 回答1: I was looking for a solution to the same question , but it currently the only option that we might have right now is using UITableView as View. import SwiftUI import UIKit struct TableView: UIViewRepresentable { func makeUIView(context: Context) -> UITableView { let tableView = UITableView(frame: .zero, style: .plain) tableView.delegate = context.coordinator tableView.dataSource =

Missing argument for parameter 'user' in call SwiftUI

元气小坏坏 提交于 2021-02-05 12:32:47
问题 Please help, it is driving me nuts. I have a constant in ProfileViewModel (let user: UserModel) The UserModel is Identifiable in UserModel file I also initiate the user: UserModel in ProfileViewModel. In HomeView I added the (let profileVM: ProfileViewModel) constant This allows me to retrieve a user profile image through "profileVM.user.profileImageURL. In my MainView I load the HomeView() based on being logged in or not I am asked to pass the profileVM and user let constants within HomeView

Reload view when @Published is changed

血红的双手。 提交于 2021-02-05 11:49:32
问题 I want to be able to scan barcodes, then show the barcode at the bottom of the screen in a sheet, or a separate view. When I update the 'barcode' variable which is @Published and accessed in other methods with @ObserveableObject, it doesn't update the view with the data from the barcode. Content View class ScannedCode: ObservableObject { @Published var barcode = "" } struct ContentView: View { @ObservedObject var barcode = ScannedCode() var body: some View { ZStack { ScannerView()

Reload view when @Published is changed

耗尽温柔 提交于 2021-02-05 11:48:06
问题 I want to be able to scan barcodes, then show the barcode at the bottom of the screen in a sheet, or a separate view. When I update the 'barcode' variable which is @Published and accessed in other methods with @ObserveableObject, it doesn't update the view with the data from the barcode. Content View class ScannedCode: ObservableObject { @Published var barcode = "" } struct ContentView: View { @ObservedObject var barcode = ScannedCode() var body: some View { ZStack { ScannerView()

Pure SwiftUI login, signup, register flow, is it possible?

喜夏-厌秋 提交于 2021-02-05 11:43:27
问题 Im new to ios development and I have come straight into SwiftUI and Xcode 12. I'm trying to understand the flow for login from a login screen that after you input your credentials you are presented with a tabview screen. When the app first loads, its presented with the login and after login is successful the token from the server is returned and saved and further starting of the app checks for token and displays appropriate view WindowGroup { if token == nil { LoginView() } else { TabView() }

Problem saving data, using CoreData with SwiftUI

你离开我真会死。 提交于 2021-02-05 11:15:29
问题 I just started using CoreData with SwiftUI . After following this series of tutorial. And I am facing a situation where I cannot save data as I expect. Here is the relevant code: struct MyView: View { ...... @Environment(\.managedObjectContext) var managedObjectContext func setData() { print(#function) ..... let myData = SomeEntity(context: self.managedObjectContext) myData.name = "myName" myData...... do { try self.managedObjectContext.save() } catch let error { // Handle the Core Data error

Make SwiftUI Rectangle same height or width as another Rectangle

十年热恋 提交于 2021-02-05 09:47:20
问题 For a SwiftUI layout in a macOS app, I have three Rectangles as shown below: The code to produce this layout is: import SwiftUI struct ContentView: View { var body: some View { VStack { HStack { ZStack { Rectangle() .fill(Color.purple) .frame(width: 20) Text("1") .font(.subheadline) .foregroundColor(.white) } ZStack { Rectangle() .fill(Color.orange) Text("2") .font(.subheadline) .foregroundColor(.white) } } HStack { ZStack { Rectangle() .fill(Color.red) .frame(height: 20) Text("3") .font(

Make SwiftUI Rectangle same height or width as another Rectangle

可紊 提交于 2021-02-05 09:47:13
问题 For a SwiftUI layout in a macOS app, I have three Rectangles as shown below: The code to produce this layout is: import SwiftUI struct ContentView: View { var body: some View { VStack { HStack { ZStack { Rectangle() .fill(Color.purple) .frame(width: 20) Text("1") .font(.subheadline) .foregroundColor(.white) } ZStack { Rectangle() .fill(Color.orange) Text("2") .font(.subheadline) .foregroundColor(.white) } } HStack { ZStack { Rectangle() .fill(Color.red) .frame(height: 20) Text("3") .font(

Background Image and canvas with pencilKit Swiftui

旧时模样 提交于 2021-02-05 09:01:56
问题 I'm learning about PencilKit. I have a canvas, and I want to set a background image that we can draw on it. When I save my canvas, I want my background image to be visible But I have an error : Cannot convert value of type 'Image' to expected argument type 'UIImage?' Image("badmintoncourt") is an image from my assets I can't find out how to solve it, but I maybe not in the right way to add a background image to my canvas struct Home : View { @State var canvas = PKCanvasView() @Environment(\

Background Image and canvas with pencilKit Swiftui

北慕城南 提交于 2021-02-05 09:01:31
问题 I'm learning about PencilKit. I have a canvas, and I want to set a background image that we can draw on it. When I save my canvas, I want my background image to be visible But I have an error : Cannot convert value of type 'Image' to expected argument type 'UIImage?' Image("badmintoncourt") is an image from my assets I can't find out how to solve it, but I maybe not in the right way to add a background image to my canvas struct Home : View { @State var canvas = PKCanvasView() @Environment(\