swiftui

Xcode 11 beta swift ui preview not showing

不羁的心 提交于 2020-12-28 04:31:37
问题 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 ContentView_Previews : PreviewProvider { static var previews: some View { ContentView() } } #endif 回答1: To preview and interact with views from the canvas in Xcode, ensure your Mac is running on Catalina MacOS . https://developer.apple.com/tutorials/swiftui/creating-and-combining-views Please check apple

Get light or dark variant of a color declared in assets

↘锁芯ラ 提交于 2020-12-27 06:12:42
问题 In my assets I have declared a theme color in two variants for both light and dark appearances, which works great. However, I have a specific place in the app where I need to use the light variant of the color regardless of whether dark mode is enabled or not. Is there any other way of getting that color in code, other than declaring the same color as a separate one with only a single variant? 回答1: In SwiftUI if there is need to use light variant for some subview it is enough to force specify

Get light or dark variant of a color declared in assets

孤街浪徒 提交于 2020-12-27 06:12:13
问题 In my assets I have declared a theme color in two variants for both light and dark appearances, which works great. However, I have a specific place in the app where I need to use the light variant of the color regardless of whether dark mode is enabled or not. Is there any other way of getting that color in code, other than declaring the same color as a separate one with only a single variant? 回答1: In SwiftUI if there is need to use light variant for some subview it is enough to force specify

SwiftUI delete rows from a list

為{幸葍}努か 提交于 2020-12-26 20:18:06
问题 As you can see from the image I have a list of colors, I would like to be able to also give the possibility to delete a color from the array . I tried to add a list and then call the onDelete call on ForEach , but it's not working well it gives me problems. Then in addition to this I would like the list to be the size of the contained elements. Error: Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift, line 444 Can anyone give me some advice? Code: import SwiftUI struct

Using SwiftUI, Core Data, and one-to-many relationships, why does the list not update when adding a row on the Many side

流过昼夜 提交于 2020-12-26 10:59:07
问题 I have a SwiftUI project with Core Data. The data model is a simple one-to-many and two primary views which each have a textfield at the top and a button to add a new item to the list view below. The first view is for the One side of the relation and the second for the Many. So, the NavigationLink in the first opens the second and passes the One object. Pretty standard stuff, it would seem. The methodology for creating the One works and the list below gets updated immediately when the managed

Using SwiftUI, Core Data, and one-to-many relationships, why does the list not update when adding a row on the Many side

笑着哭i 提交于 2020-12-26 10:58:13
问题 I have a SwiftUI project with Core Data. The data model is a simple one-to-many and two primary views which each have a textfield at the top and a button to add a new item to the list view below. The first view is for the One side of the relation and the second for the Many. So, the NavigationLink in the first opens the second and passes the One object. Pretty standard stuff, it would seem. The methodology for creating the One works and the list below gets updated immediately when the managed

How To Position Views Relative To Their Top Left Corner In SwiftUI

≡放荡痞女 提交于 2020-12-26 09:13:25
问题 How do I position views relative to their top left corner in swiftUI? The "position" modifier moves the views relative to their center coordinates. So .position(x: 0, y: 0) places a views center coordinate in the top left of the screen. I want to place a views top left coordinate in the top left of the screen, How do I do this? struct HomeView: View { var body: some View { VStack(alignment: .leading) { Text("Top Text") .font(.system(size: 20)) .fontWeight(.medium) Text("Bottom Text") .font(

How To Position Views Relative To Their Top Left Corner In SwiftUI

别来无恙 提交于 2020-12-26 09:10:46
问题 How do I position views relative to their top left corner in swiftUI? The "position" modifier moves the views relative to their center coordinates. So .position(x: 0, y: 0) places a views center coordinate in the top left of the screen. I want to place a views top left coordinate in the top left of the screen, How do I do this? struct HomeView: View { var body: some View { VStack(alignment: .leading) { Text("Top Text") .font(.system(size: 20)) .fontWeight(.medium) Text("Bottom Text") .font(

Sharing Data with AppGroup

北战南征 提交于 2020-12-26 09:06:16
问题 I want to share one variable from my UIKit File to my Widget Extension created with SwiftUI. I followed this here. Please look at the answer from J Arango. But i dont understand the last part there. I have to use import MySharedObjects . So I did this: import MySharedObject struct testing { let mySharedObject = MySharedObject(name: "My Name", lastName: "My Last Name") do { let data = try JSONEncoder().encode(mySharedObject) /// Make sure to use your "App Group" container suite name when

Run code during app launch in SwiftUI 2.0

拈花ヽ惹草 提交于 2020-12-26 08:47:14
问题 In my App struct, I have a small function that checks to see if the user has opened the app before. If not, it shows an onboarding view with a few questions. Right now, I just have a .onAppear attached to both the Onboarding and ContentView to run the function, but when you launch the app, the Onboarding view flashes for a quick second. How can I run the function during launch, so the Onboarding view doesn't flash in for a second? Here's my App struct: import SwiftUI @main struct TestApp: App