swiftui

iPhone is not available, Target is not found Xcode 12.3

孤者浪人 提交于 2020-12-24 15:06:01
问题 After upgrading Xcode I can not run the my iPhone on the Xcode. My Xcode waiting and waiting finally give a error like that and it stuck. Even though I unplugged the USB cable and delete derived data nothing changed. I faced same problem with upgrade Xcode to 12.0 12.1 and 12.2 Is there any thing missing? What should I do to solve this issue? iPhone is not available. Please reconnect the device. 回答1: Go to this Github repo for 14.2 click here to download the iOS 14.2 file or for 14.3 here 14

How to observe changes in UserDefaults?

坚强是说给别人听的谎言 提交于 2020-12-23 12:11:26
问题 I have an @ObservedObject in my View: struct HomeView: View { @ObservedObject var station = Station() var body: some View { Text(self.station.status) } which updates text based on a String from Station.status : class Station: ObservableObject { @Published var status: String = UserDefaults.standard.string(forKey: "status") ?? "OFFLINE" { didSet { UserDefaults.standard.set(status, forKey: "status") } } However, I need to change the value of status in my AppDelegate , because that is where I

How to observe changes in UserDefaults?

假如想象 提交于 2020-12-23 12:11:12
问题 I have an @ObservedObject in my View: struct HomeView: View { @ObservedObject var station = Station() var body: some View { Text(self.station.status) } which updates text based on a String from Station.status : class Station: ObservableObject { @Published var status: String = UserDefaults.standard.string(forKey: "status") ?? "OFFLINE" { didSet { UserDefaults.standard.set(status, forKey: "status") } } However, I need to change the value of status in my AppDelegate , because that is where I

How use use SwiftUI ForEach with a dictionary [ customEnum : customStrut ] - getting “conform to 'RandomAccessCollection'” error

纵然是瞬间 提交于 2020-12-23 11:59:35
问题 How could I correct this code from failing build? Basically wanting to use ForEach to iterate through a dictionary which is based on a [ customEnum : customStrut ]. Otherwise if this is problematic a different way to achieve that SwiftUI supports? Errors Referencing initializer 'init(_:id:content:)' on 'ForEach' requires that '[GCFilterViewOptions.FilterOptions : GCFilterViewOptions.FilterOptionValues]' conform to 'RandomAccessCollection' Type '(key: GCFilterViewOptions.FilterOptions, value:

Fetch data from CoreData for iOS 14 widget

浪尽此生 提交于 2020-12-22 06:26:20
问题 I want to display data fetched from Core Data in a widget. But @FetchRequest doesn’t work on widgets. As I understand, we have to create an app group and make a shared persistent container. What I want to know is how to read (fetch) data on widgets from that shared persistent container or simply, how to display data fetched from Core Data in widgets . 回答1: First you need to create an AppGroup which will be used to create a Core Data Persistent Container (here is a good explanation how to do

Fetch data from CoreData for iOS 14 widget

若如初见. 提交于 2020-12-22 06:26:13
问题 I want to display data fetched from Core Data in a widget. But @FetchRequest doesn’t work on widgets. As I understand, we have to create an app group and make a shared persistent container. What I want to know is how to read (fetch) data on widgets from that shared persistent container or simply, how to display data fetched from Core Data in widgets . 回答1: First you need to create an AppGroup which will be used to create a Core Data Persistent Container (here is a good explanation how to do

Block scroll down in ScrollView - SwiftUI

↘锁芯ラ 提交于 2020-12-21 05:02:51
问题 How can I block scroll down and only allow scroll up in order to avoid seeing the white space over the rectangle on top when scrolling? struct ContentView: View { var body: some View { GeometryReader { geo in ScrollView { Rectangle() .frame(width: geo.size.width, height: 400) .foregroundColor(.black) Spacer() } } } } 回答1: I assume you want to avoid bounces, here is possible approach (tested with Xcode 12 / iOS 14) struct ContentView: View { var body: some View { GeometryReader { geo in

How to load an image from documents directory on macOS Swift?

折月煮酒 提交于 2020-12-21 03:53:44
问题 I am struggling with loading an image to Image. I am making an MacOS app which is slightly different than for iOS. I searched Internet however I found only several responses how to make it in iOS. Please check the code: import SwiftUI struct ContentView: View { let myUrl = URL(fileURLWithPath: "/Users/codegrinder/Documents/turtlerock.jpg") init() { //TODO Do something with the myUrl which is valid (not nil) } var body: some View { Image("turtlerock") .frame(maxWidth: .infinity, maxHeight:

How to load an image from documents directory on macOS Swift?

五迷三道 提交于 2020-12-21 03:51:13
问题 I am struggling with loading an image to Image. I am making an MacOS app which is slightly different than for iOS. I searched Internet however I found only several responses how to make it in iOS. Please check the code: import SwiftUI struct ContentView: View { let myUrl = URL(fileURLWithPath: "/Users/codegrinder/Documents/turtlerock.jpg") init() { //TODO Do something with the myUrl which is valid (not nil) } var body: some View { Image("turtlerock") .frame(maxWidth: .infinity, maxHeight:

SwiftUI: Cannot dismiss sheet after creating CoreData object

谁说我不能喝 提交于 2020-12-15 07:40:26
问题 I am trying to create a very basic app with two views. The main view displays CoreData objects in a NavigationView and has a toolbar button to open an "add item" modal sheet. The "add item" sheet should be able to insert a new CoreData object and dismiss itself. What I am observing is that the modal sheet can be dismissed as long as it doesn't insert a CoreData object, but once it does interact with CoreData, all my attempts to dismiss the sheet no longer work. Also, when the sheet creates a