xcode12
Get the current scroll position of a SwiftUI ScrollView
It was possible to read it and before. Here is a solution based on view preferences. struct DemoScrollViewOffsetView: View { @State private var offset = CGFloat.zero var body: some View { ScrollView { VStack { ForEach(0..<100) { i in Text(“Item \(i)”).padding() } }.background(GeometryReader { Color.clear.preference(key: ViewOffsetKey.self, value: -$0.frame(in: .named(“scroll”)).origin.y) }) .onPreferenceChange(ViewOffsetKey.self) { print(“offset >> \($0)”) … Read more
Initialize @StateObject with a parameter in SwiftUI
Here is a demo of solution. Tested with Xcode 12b. class MyObject: ObservableObject { @Published var id: Int init(id: Int) { self.id = id } } struct MyView: View { @StateObject private var object: MyObject init(id: Int = 1) { _object = StateObject(wrappedValue: MyObject(id: id)) } var body: some View { Text(“Test: \(object.id)”) } } … Read more
SwiftUI | Using onDrag and onDrop to reorder Items within one single LazyGrid?
SwiftUI 2.0 Here is completed simple demo of possible approach (did not tune it much, `cause code growing fast as for demo). Important points are: a) reordering does not suppose waiting for drop, so should be tracked on the fly; b) to avoid dances with coordinates it is more simple to handle drop by grid … Read more
Xcode building for iOS Simulator, but linking in an object file built for iOS, for architecture ‘arm64’
Xcode building for iOS Simulator, but linking in an object file built for iOS, for architecture ‘arm64’