Post

Replies

Boosts

Views

Activity

Reply to dateFormater returns nil on Specific date
I could have found a few timezones where date(from:) returns nil for "1991-03-24T00:00:00". For example, Asia/Jerusalem. I'm not sure what would be the reason for this specific case, but historically, some ranges of local date & time may be missing from the calendar system of some regions. You may need to find a better way to represent a date using Date for such regions.
Dec ’21
Reply to Cannot use instance member 'model' within property initializer; property initializers run before 'self' is available
As the error message is clearly stating, you cannot use any instance members within property initializer (= Observer(model?.head)). One way to work around this restriction would be moving initialization into init(). class SampleViewModel { var model: SampleModel? let changeData: Observer<String> init() { let model = SampleModel() self.model = model self.changeData = Observer(model.head) } func changeLabel(_ tf: String) { self.changeData.value = tf } } You will not see the error with this change, but I'm not sure this would work as you expect.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’21
Reply to POD Compatibility
Whether or not they are using pods, apps and libraries may need fixes when new versions of iOS/iOS SDK are released. Unfortunately, many of the pods are very late about this sort of fixes. (Or old ones might be frozen.) If updating the versions of the pods to the latest does not solve your issue, you may need to contact to the author of the pods.
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’21
Reply to How do I fill in CXProviderDelegate in SwiftUI?
As you found, you cannot make a view type (which is a struct!) conform to CXProviderDelegate. You need to create a class inheriting NSObject and make it conform to CXProviderDelegate and use it in your view. By the way, in Swift, type names should start with Capital letters. You should not use videoTabView as a View name.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’21
Reply to How to use SF Symbols 3
Are you writing a code for iOS? SF Symbols are included in iOS, so you just need to check the availability of the symbol you want to use, and then specify the name of it in your app. No need to add something to Asset Catalog.
Topic: Design SubTopic: General Tags:
Dec ’21
Reply to Using protocol functions at unknown class
Maybe just make a function that will give the instance from name? I would use a Dictionary, if the number is 50 or so. let stringToNeededMethods: [String: NeededMethods] = [ "FirstImplementation": FirstImplementation(), //... ] if let theInstance = stringToNeededMethods["FirstImplementation"] { print(theInstance.doSmt(str: "0123")) }
Topic: App & System Services SubTopic: General Tags:
Dec ’21
Reply to Function Issue: Closure containing a declaration cannot be used with result builder 'ViewBuilder'
The declaration of function saveButtonPressed() resides in the body of body. You need to move it out of body. struct AddALandmarkForm: View { @Environment(\.presentationMode) var presentatoinMode @EnvironmentObject var listViewModel: ListViewModel @State var newLocationName: String = "" @State var texts: String = "Enter a Description" @State public var newPropertyType1 = false @State public var propertyPrice: String = "" @State var email: String = "" @State var ownerName: String = "" @State var alerTitle: String = "" @State var showAlert: Bool = false var body: some View { NavigationView { Form { //... } //<- End of `Form` .navigationBarTitle("Add a New Location") } //<- End of `NavigationView` } //<- End of `body` func saveButtonPressed() { listViewModel.addItem(title: newLocationName, descrip: texts, price: propertyPrice, mail: email, owner: ownerName) presentatoinMode.wrappedValue.dismiss() } } By the way, in Swift, type names should start with Capital letters. You should not use addALandmarkForm as a struct name in Swift.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’21
Reply to Run async tasks using Background Tasks
I'm misunderstanding something and/or doing something wrong As far as I see the documentation of setTaskCompleted(success:), it should be called when the task is completed. Have you tried something like this? private func configureBackgroundTasks() { Logger.log(.info, "Registering background tasks...") let bgTaskIdentifier = "com.example.task" BGTaskScheduler.shared.register(forTaskWithIdentifier: bgTaskIdentifier, using: DispatchQueue.main) { (task) in Logger.log(.info, "Performing background task \(bgTaskIdentifier)") Task { if let updatedData = await appManager.getUpdateAppData() { DispatchQueue.main.async { appManager.data = updatedData task.setTaskCompleted(success: true) } } else { task.setTaskCompleted(success: false) } backgroundTaskManager.scheduleAppRefresh() } } }
Topic: App & System Services SubTopic: Core OS Tags:
Dec ’21