swiftui

SwifUI onAppear gets called twice

别等时光非礼了梦想. 提交于 2020-12-08 06:54:16
问题 Q1: Why are onAppears called twice? Q2: Alternatively, where can I make my network call? I have placed onAppears at a few different place in my code and they are all called twice. Ultimately, I'm trying to make a network call before displaying the next view so if you know of a way to do that without using onAppear, I'm all ears. I have also tried to place and remove a ForEach inside my Lists and it doesn't change anything. Xcode 12 Beta 3 -> Target iOs 14 CoreData enabled but not used yet

SwifUI onAppear gets called twice

孤人 提交于 2020-12-08 06:53:08
问题 Q1: Why are onAppears called twice? Q2: Alternatively, where can I make my network call? I have placed onAppears at a few different place in my code and they are all called twice. Ultimately, I'm trying to make a network call before displaying the next view so if you know of a way to do that without using onAppear, I'm all ears. I have also tried to place and remove a ForEach inside my Lists and it doesn't change anything. Xcode 12 Beta 3 -> Target iOs 14 CoreData enabled but not used yet

What is the use of “Preview Assets” assets catalog in Xcode 11 beta?

限于喜欢 提交于 2020-12-08 06:35:04
问题 What is the use of "Preview Assets" assets catalog in Xcode 11 beta? I have just created new project with SwiftUI. I have checked release notes of Xcode 11 beta but there is no information about this assets catalog. What is the use of it? 回答1: Now, when you layout your views you can preview it in Canvas (the window from the right side of the code editor). Obviously, some images and other data for your app you can get only in runtime, from your API for example. So all stubs can be placed into

What is the use of “Preview Assets” assets catalog in Xcode 11 beta?

社会主义新天地 提交于 2020-12-08 06:33:17
问题 What is the use of "Preview Assets" assets catalog in Xcode 11 beta? I have just created new project with SwiftUI. I have checked release notes of Xcode 11 beta but there is no information about this assets catalog. What is the use of it? 回答1: Now, when you layout your views you can preview it in Canvas (the window from the right side of the code editor). Obviously, some images and other data for your app you can get only in runtime, from your API for example. So all stubs can be placed into

SwiftUI - how to update data with fetchRequest in init

断了今生、忘了曾经 提交于 2020-12-08 02:17:30
问题 I am doing a CoreData fetch inside my init() method of the View. I am not using FetchRequest in SwiftUI, as I need a predicate based on a parameter which is send to the View aswell. Using that parameter in the @FetchRequest will cause an error, as the variable has not been initialized. I am doing following fetch Request inside the init() //FetchRequest let fetch : NSFetchRequest<Article> self.articleRows = [Article]() fetch = Article.fetchRequest() as! NSFetchRequest<Article> fetch.predicate

Images inaccessible from asset catalog in a SwiftUI framework

耗尽温柔 提交于 2020-12-07 04:55:22
问题 I've created an iOS framework that contains a single SwiftUI View . I've then added an Asset Catalog with a single image. Trying to access that image from the SwiftUI view doesn't do anything - I see a blank image. Image("MyImage") The Xcode Preview doesn't show anything, nor does the view show anything for a test target I wrote that uses the framework. So the question is - how do I bundle images with a framework that uses SwiftUI? Is this not supported? The only way I could get this to work

Images inaccessible from asset catalog in a SwiftUI framework

天涯浪子 提交于 2020-12-07 04:54:36
问题 I've created an iOS framework that contains a single SwiftUI View . I've then added an Asset Catalog with a single image. Trying to access that image from the SwiftUI view doesn't do anything - I see a blank image. Image("MyImage") The Xcode Preview doesn't show anything, nor does the view show anything for a test target I wrote that uses the framework. So the question is - how do I bundle images with a framework that uses SwiftUI? Is this not supported? The only way I could get this to work

SwiftUI - Hiding LazyVGrid causes memory leak

吃可爱长大的小学妹 提交于 2020-12-07 04:36:47
问题 I have a LazyVGrid that displays some data fetched from a remote API. When hiding the LazyVGrid via a button press, I encounter a memory leak. This seems to happen only if there is more content than can be displayed inside of LazyVGrid . I have prepared some code for you to reproduce this leak. Is there something flaut with this code, or ist that a bug on apples side? Maybe theres a workaround? import SwiftUI import Foundation import Combine enum FakeAPI { static var fakeData: [Result] {

Change Button Anchor Point SwiftUI

梦想的初衷 提交于 2020-12-06 21:47:03
问题 I'm attempting to alter the anchor point for what determines the center of a Button. The following code puts the button at the top left corner of the frame. Button(action: { print(self.note) }) { Text(note) } .position(x: 0.0, y: 0.0) If I use .offset instead, then it will work. I would like it to be centered within it's frame though. Is there a way to change the anchor point? 回答1: You may need to turn on the frame of the parent container, so that you can use frame alignment. var body: some

Change Button Anchor Point SwiftUI

倖福魔咒の 提交于 2020-12-06 21:33:47
问题 I'm attempting to alter the anchor point for what determines the center of a Button. The following code puts the button at the top left corner of the frame. Button(action: { print(self.note) }) { Text(note) } .position(x: 0.0, y: 0.0) If I use .offset instead, then it will work. I would like it to be centered within it's frame though. Is there a way to change the anchor point? 回答1: You may need to turn on the frame of the parent container, so that you can use frame alignment. var body: some