Post

Replies

Boosts

Views

Activity

SwiftUI View creates huge gap at the top
display simple view with two text fields inside a vStack/HStack combination. It leaves huge gap at the top as shown on the attached image. I tried vStack, it has .leading and .trailing which justifies left or right. How can set specific spacing at the top? code: @Environment(\.managedObjectContext) private var viewContext @Environment(\.dismiss) var dismiss @Environment(\.presentationMode) var presentationMode @Binding var chosenPlan: ProviderApiCaller.ProviderData @State var state: String? @State var zip: String? func onAdd(plan: ProviderApiCaller.ProviderData ) { } var body: some View { NavigationView { VStack { HStack { Text(chosenPlan.name!) } HStack { Text(chosenPlan.plans.first!.planUrl) } } } .navigationTitle("Plan Details") .toolbar { // Back button ToolbarItem(placement: .navigationBarLeading) { Button(action: { presentationMode.wrappedValue.dismiss() }, label: { HStack(spacing: 2) { Image(systemName: "chevron.backward") .foregroundColor(.black) Button("Back", action: { self.presentationMode.wrappedValue.dismiss() } ) .foregroundColor(.black) } }) } ToolbarItem(placement: .confirmationAction) { // Button("Save", action: { Task { try? await rI?(nameInput, phoneInput) } }) Button("Save", action: { onAdd(plan: chosenPlan) } ) .foregroundColor(.blue) } } .navigationViewStyle(StackNavigationViewStyle()) .navigationBarBackButtonHidden(true) } ![]("https://developer.apple.com/forums/content/attachment/7510538e-c8b1-42d2-a68a-94d5aeaac186" "title=Screenshot 2023-05-26 at 4.11.30 PM.png;width=429;height=881")
4
0
2.4k
Jun ’23
SwiftUI how to dynamically append a view to an existing view
I have an existing ScrollView view with a Picker. Upon selection of a picker value, and user pressing the details button, I want to append a view to the bottom of the existing view. I call detailsView. But it does not seem to work. @Environment(\.managedObjectContext) private var viewContext @Environment(\.dismiss) var dismiss @Environment(\.presentationMode) var presentationMode @Binding var chosenProvider: Provider? @State var selectedLocation: Location? @State private var vendorNames: [String] = [] @State private var selectedVendor:String? = nil @State private var showingSheet = false @State var state: String? @State var zip: String? var body: some View { ScrollView { VStack { HStack { Text("Select Vendor") Picker("Provider", selection: $selectedVendor , content: { ForEach(vendorNames,id: \.self, content: { name in Text(name) }) }) .pickerStyle(MenuPickerStyle()) .onTapGesture { self.getVendorNames() { providers, status in if (status) { vendorNames = providers } } } } .onChange(of: selectedVendor, perform: { newValue in selectedVendor = newValue }) .tint(.orange) Button { DetailsView() } label: { Label("Details", systemImage: "list.bullet.rectangle") .foregroundColor(.blue) } Spacer() } } .onAppear{ self.getVendorNames() { providers, status in if (status) { vendorNames = providers } } } .navigationTitle("Add Vendor") .toolbar { // Back button ToolbarItem(placement: .navigationBarLeading) { Button(action: { presentationMode.wrappedValue.dismiss() }, label: { HStack(spacing: 2) { Image(systemName: "chevron.backward") .foregroundColor(.black) Button("Back", action: { self.presentationMode.wrappedValue.dismiss() } ) .foregroundColor(.black) } }) } } .navigationViewStyle(StackNavigationViewStyle()) .navigationBarBackButtonHidden(true) } struct DetailsView: View { var body: some View { VStack { Text("Some Details") } } } func getVendorNames (completionHandler: @escaping ([String], Bool) -> Void ) { var names = ["Acme", "Abc"] completionHandler(names, true) } }
2
0
1.9k
Jun ’23
Xcode 15.2 project dependencies are not recognized
Loaded both Swift-Collection package 1.1.0 from https://github.com/apple/swift-collections and Facebook 14.1.0 package from https://github.com/facebook/facebook-ios-sdk I open swift file and type import, the prompt shows the module FBSDKCorekit and as soon as select it, it immediately says module not found Does the same thing for OrderedCollection module. Did a clean and then also deleted DerivedData directory contents and rebuilt, same error occurs, does not recognize the modules, even though correct packages exist in Xcode I tied with Faebook 16.3.1 and tried. I deleted the project, created a new project, selected Add Package Dependencies and then deleted the recently sued packages, entered the facebook ios url and tried again. Same error, does not recognize the package contents How can I fix this? Please help.
1
0
679
Feb ’24
NSPersistentCloudKitContainer - Import failed with error: Error Domain=NSCocoaErrorDomain Code=4864
The NSPersistentCloudKitContainer synchronization between core data and iCloud was working fine with phone 15.1. Connected a new iPhone iOS 15.5, it gives error: CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate managedObjectContextSaved:](2504): <NSCloudKitMirroringDelegate: 0x28198c000>: Observed context save: <NSPersistentStoreCoordinator: 0x2809c9420> - <NSManagedObjectContext: 0x2819ad520> 2022-12-05 13:32:28.377000-0600 r2nr[340:6373] [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _importFinishedWithResult:importer:](1245): <PFCloudKitImporter: 0x2837dd740>: Import failed with error: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x65, 0x78, 0x61)" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x65, 0x78, 0x61)} CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _importFinishedWithResult:importer:](1245): <PFCloudKitImporter: 0x2837dd740>: Import failed with error: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x65, 0x78, 0x61)" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x53, 0x6f, 0x6d, 0x65, 0x20, 0x65, 0x78, 0x61)} I go back and try with my old iPhone iOS 15.1, gives same error.
2
1
1.1k
Aug ’25