Posts

Post not yet marked as solved
0 Replies
631 Views
We have been supporting a small company's iPad app for about a year now as an Ad Hoc distribution. This was a quick way for us to launch this internal app on a handful of devices. The issue is that ad hoc builds expire after 90 days, meaning someone always needs to generate a new build for folks to continue using the app. The app needs to be inside of the company network in order to access the backend web services, so it wouldn't be "review-able" from an App Store perspective. I know there are several ways to distribute internal apps - some of which were recently introduced. My question is, which method is the best way to go? Enterprise account? App Store (but only for internal folks)? What's the best way to clearly understand the best way amongst the options?
Posted
by bryonCat.
Last updated
.
Post marked as solved
9 Replies
7.5k Views
I am getting an error when trying to fetch objects in SwiftUi in a form sheet modal in iOS 13.Here's the error:[SwiftUI] Context in environment is not connected to a persistent store coordinator: <NSManagedObjectContext: 0x600003218620>I am able to run a fetchRequest from a list view, but not in the modal.Has anyone else seen this issue?I set the Environment context in the SceneDelegate:if let windowScene = scene as? UIWindowScene { let window = UIWindow(windowScene: windowScene) let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext //managedObjectContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy window.rootViewController = UIHostingController(rootView: ContentView().environmentObject(sampleViewModel).environmenbject(customerViewModel).environment(\.managedObjectContext, managedObjectContext)) self.window = window window.makeKeyAndVisible()In the ContentView:import SwiftUI struct ContentView: View { @State var isPresented = false var body: some View { NavigationView { VStack { // Search bar, filter, and divider SampleListView() } .sheet(isPresented: $isPresented) { NewSampleView() } .navigationBarTitle("Samples") AddSampleButton(isNewSamplePresented: $isPresented) } } }Able to see items in the SampleListView:struct SampleListView: View { @EnvironmentObject var viewModel: SampleListViewModel @FetchRequest(fetchRequest: Sample.allSamplesFetchRequest()) var samples: FetchedResults var body: some View { List(self.samples) { sample in VStack(alignment: HorizontalAlignment.leading) { NavigationLink(destination: SampleView(activeSampleModel: ActiveSampleViewModel(sample: sample))) { Spacer() Text(sample.trackingNumber ?? "") Spacer() Text(sample.sampleId ?? "") Spacer() } } } } }But I get the error when presenting the NewSampleView (I've tried using a fetchRequest defined in the view as well as one defined in the NSManagedObject subclass but the fetch is always failing with the above error) :import SwiftUI import CoreData struct NewSampleView : View { @State var customerId = "" @State var sampleDate = Date(timeIntervalSinceNow: 0) @State var receiptDate = Date(timeIntervalSinceNow: 0) @State var customerServiceSampleNumber = "" @State var notes = "" @Environment(\.managedObjectContext) var managedObjectContext @FetchRequest(fetchRequest: fetchRequest(), animation: nil) var customers: FetchedResults var body: some View { List(self.customers) { customer in VStack(alignment: HorizontalAlignment.leading) { Spacer() Text(customer.customerId ?? "") Spacer() } } } static func fetchRequest() -> NSFetchRequest { let request: NSFetchRequest = Customer.fetchRequest() as! NSFetchRequest request.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true)] return request }
Posted
by bryonCat.
Last updated
.
Post not yet marked as solved
0 Replies
1.1k Views
I am trying to integrate SwiftUI into a new app that uses CoreData model objects. I would like to show the properties of these objects in a custom SwiftUI component that has the text property of the TextField defaulted to the current value of that attribute.Would be so greatful for any insights on how best to implement this.Should the CoreData NSManagedObjects be passed in the View heirarchy as @ObservedObjects (in order to bind the value to the TextField)? I've been trying this and seem to run into issues where the compiler doesn't recognize the arguments as valid. The below code does not compile, I get an error 'Type '_' has no member 'testFieldId' on Line 8 of TestView.Here's a 'Test' NSManagedObject:import Foundation import CoreData @objc(Test) public class Test: NSManagedObject, Identifiable, Encodable { @NSManaged public var name: String? @NSManaged public var sampleTestId: String? @NSManaged public var tabNumber: Int16 @NSManaged public var sample: Sample? @NSManaged public var testFields: NSOrderedSet? enum CodingKeys: String, CodingKey { case name case sampleTestId case tabNumber case sample } // MARK: - Encodable public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(sampleTestId, forKey: .sampleTestId) try container.encode(name, forKey: .name) try container.encode(tabNumber, forKey: .tabNumber) } } extension Test { func testFieldsAsArray() -> ([TestField]) { return self.testFields?.array as! [TestField] } Tests have one or more TestFields:import Foundation import CoreData @objc(TestField) public class TestField: NSManagedObject, Identifiable, Encodable { @NSManaged public var allowEmptyResponse: Bool @NSManaged public var label: String? @NSManaged public var maxValue: Double @NSManaged public var minValue: Double @NSManaged public var numDecimalPlaces: Int16 @NSManaged public var testFieldId: String? @NSManaged public var testFieldResult: String? @NSManaged public var unitOfMeasurement: String? @NSManaged public var userUpdated: Bool @NSManaged public var test: Test? enum CodingKeys: String, CodingKey { case allowEmptyResponse case label case minValue case maxValue case numDecimalPlaces case testFieldId case testFieldResult case unitOfMeasurement case test }TestView has a list of TestFieldViews:import Foundation import SwiftUI struct TestView: View { @ObservedObject var test: Test var body: some View { ForEach(test.testFields, id: \.testFieldId) { field in TestFieldView(field: field) { newValue in } } } }Here's the TestFieldView:import Foundation import SwiftUI struct TestFieldView: View { @ObservedObject var field: TestField @State private var value = "" @Environment(\.managedObjectContext) var managedObjectContext var body: some View { HStack { Text(field.label ?? "") Spacer() TextField(fieldRange(), text: $value, onEditingChanged: { changed in print("Edit Changed!") self.field.testFieldResult = self.value do { try self.managedObjectContext.save() } catch { print("cannot save!") } }, onCommit: { print("Commit!") }) } .frame(width: 100) .keyboardType(UIKeyboardType.decimalPad) }Thanks for any help or words of wisdom that might get me un-stuck! 🙂
Posted
by bryonCat.
Last updated
.