swiftui

UICollectionView with SwiftUI + Drag and drop reordering possible?

假装没事ソ 提交于 2021-01-27 07:51:12
问题 I'm implementing a UICollectionView inside my SwiftUI View (also with SwiftUI View cells). So I have a Hosting+Representable Combo. Now I want to reorder my cells through drag and drop, but nothing happens. The idea is to use a longpressGesture together with the given functions canMoveItemAt and moveItemAt. Here is the full code: import SwiftUI import UIKit struct ContentView: View { var body: some View { CollectionComponent() } } struct CollectionComponent : UIViewRepresentable { func

SwiftUI - Dynamic List filtering animation flies to right side when data source is empty

会有一股神秘感。 提交于 2021-01-27 06:19:20
问题 I have a List that gets data from my people array and displays their names. I'm also filtering the list so that it only shows the names that contain the text field's text, which is searchText . Here's my code: struct Person: Identifiable { let id = UUID() /// required for the List var name = "" } struct ContentView: View { @State var searchText = "" var people = [ /// the data source Person(name: "Alex"), Person(name: "Ally"), Person(name: "Allie"), Person(name: "Bob"), Person(name: "Tim"),

Xcode 11.3 - Unable to run on device

你说的曾经没有我的故事 提交于 2021-01-27 04:14:30
问题 I've been working on an app within Xcode that runs fine on the simulator. I wanted to try it on my device. However, I've been encountering a frustratingly vague issue every time I try to install/run it on my device. The installation fails and the message I get includes: Unable to install "AppName" Domain: com.apple.dtdevicekit Code: -402620415 -- App installation failed Domain: com.apple.dtdevicekit Code: -402620415 Failure Reason: An unknown error has occurred. The target deployment is set

NavigationView in iPad popover does not work properly in SwiftUI

你说的曾经没有我的故事 提交于 2021-01-27 02:34:59
问题 I have the following code that displays a popover when a button is tapped: struct ContentView: View { @State private var show = false var body: some View { Button("Open") { self.show.toggle() }.popover(isPresented: $show, content: { // NavigationView { ScrollView { ForEach(0...10, id: \.self) {_ in Text("Test popover ...") }.padding() } // } }) } } If I add a NavigationView in popover's content then I get this : Any idea why this happens? It works fine if I set a fixed frame for the content,

Changing TextEditor background color in SwiftUI for macOS

≯℡__Kan透↙ 提交于 2021-01-26 04:45:55
问题 I would like to change the background color of a SwiftUI text editor on macOS. Is there a variant for the code below (used for iOS) to work for NSTextField instead of UITextView? Thanks. struct ContentView: View { init() { UITextView.appearance().backgroundColor = .clear } var body: some View { TextEditor(text: .constant("Placeholder")) .background(Color.red) } } 回答1: I have just posted an answer for that issue on a similar question here With the help of extension, you can clear the default

Changing TextEditor background color in SwiftUI for macOS

假装没事ソ 提交于 2021-01-26 04:45:28
问题 I would like to change the background color of a SwiftUI text editor on macOS. Is there a variant for the code below (used for iOS) to work for NSTextField instead of UITextView? Thanks. struct ContentView: View { init() { UITextView.appearance().backgroundColor = .clear } var body: some View { TextEditor(text: .constant("Placeholder")) .background(Color.red) } } 回答1: I have just posted an answer for that issue on a similar question here With the help of extension, you can clear the default

SwiftUI - Indexset to index in array

﹥>﹥吖頭↗ 提交于 2021-01-26 04:02:12
问题 I am using ForEach within a NavigationView and list combined with a function called when the user deletes a row using .onDelete() as per below. struct PeriodListView: View { @ObservedObject var theperiodlist = ThePeriodList() @EnvironmentObject var theprofile: TheProfile @State private var showingAddPeriod = false var dateFormatter: DateFormatter { let formatter = DateFormatter() formatter.dateStyle = .long return formatter } var body: some View { NavigationView { List { ForEach(theperiodlist

SwiftUI - Indexset to index in array

淺唱寂寞╮ 提交于 2021-01-26 03:59:03
问题 I am using ForEach within a NavigationView and list combined with a function called when the user deletes a row using .onDelete() as per below. struct PeriodListView: View { @ObservedObject var theperiodlist = ThePeriodList() @EnvironmentObject var theprofile: TheProfile @State private var showingAddPeriod = false var dateFormatter: DateFormatter { let formatter = DateFormatter() formatter.dateStyle = .long return formatter } var body: some View { NavigationView { List { ForEach(theperiodlist

How can I get only unique record in coredata+cloudkit(NSPersistentCloudKitContainer) environment?

扶醉桌前 提交于 2021-01-24 20:27:11
问题 For example, I have a entity named User in public database of Cloukit. Every new user using the App will record his identity in it, and only one record. But in coredata+cloudkit environment, there is a user, two apple devices, two this Apps, one cloud. Firstly, the user use this App on the phone A, check existence of User in local coredata when startup, not exist, so create a User record. It's ok. Days later, the user do the same on the second Phone B, record not exist in local(not sync from

How can I get only unique record in coredata+cloudkit(NSPersistentCloudKitContainer) environment?

断了今生、忘了曾经 提交于 2021-01-24 20:25:10
问题 For example, I have a entity named User in public database of Cloukit. Every new user using the App will record his identity in it, and only one record. But in coredata+cloudkit environment, there is a user, two apple devices, two this Apps, one cloud. Firstly, the user use this App on the phone A, check existence of User in local coredata when startup, not exist, so create a User record. It's ok. Days later, the user do the same on the second Phone B, record not exist in local(not sync from