Post

Replies

Boosts

Views

Activity

Reply to Get data from view after it gets added on screen using ForEach
Thanks for showing the refactored code. It compiled fine. I needed to add enableButtonBool = true, but it was a great help to guess what you want to do. (I still do not understand some parts of the code, but it may be better to show what I guessed.) I may be mistaking something, but you may want to do something like this: import SwiftUI struct ChecklistModel: Codable, Hashable { var description, remarks, status: String? } struct CheckListCard: View { @Binding var checkListData : ChecklistModel @State var statusList: [String] = [] @Binding var enableButtonBool: Bool var body: some View { let currentStatus = Binding<String>( get: {checkListData.status ?? ""}, set: {checkListData.status = $0}) let currentRemark = Binding<String>( get: {checkListData.remarks ?? ""}, set: {checkListData.remarks = $0}) VStack{ Text("Description").padding() .onAppear(){ addData() } if let description = checkListData.description { Text(description) .padding() } Text("Status").padding() if checkListData.status != nil { Picker("Status", selection: currentStatus) { ForEach(statusList, id: \.self){ status in Text(status) } }.pickerStyle(SegmentedPickerStyle()) .padding() .disabled(!enableButtonBool) } Text("Remarks") if checkListData.remarks != nil { TextField("Remarks", text: currentRemark) .disabled(!enableButtonBool) .padding() .background(Color(.white)) .cornerRadius(8) .accentColor(.gray) } else { TextField("Remarks", text: currentRemark) .disabled(!enableButtonBool) .padding() .background(Color(.white)) .cornerRadius(8) } } .padding() .background(Color("light_gray")) .foregroundColor(.black) .cornerRadius(8) .shadow(radius: 10) .padding() } func addData() { statusList.append("Yes") statusList.append("No") statusList.append("NA") if let status = checkListData.status { statusList.append(status) //<- Why this is needed? } } } struct CheckListSheet: View { @State var taskId: Int @State var checklistResponse: [ChecklistModel] = [ChecklistModel()] @State var enableButtonBool: Bool = false @State var statusList: [String] = [] var body: some View { Text("Checklist Items") .padding() .font(.title) ScrollView { ForEach(checklistResponse.indices, id:\.self) { index in CheckListCard(checkListData: $checklistResponse[index], enableButtonBool: $enableButtonBool) } if enableButtonBool { Button("Update") { updateCheckList() } } } .onAppear(){ getChecklists() } } func updateCheckList() { print("this is the checklistresponse \(checklistResponse)") } func getChecklists() { checklistResponse = [ ChecklistModel(description: "ist item", remarks: nil, status: "Yes"), ChecklistModel(description: "2nd item", remarks: "Fine", status: "no") ] enableButtonBool = true } }
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Toolbar buttons become unusable after closing the sheet.
Can you try something like this? struct ContentView: View { @State private var showingSheet = false var body: some View { NavigationView { Text("1st View") .toolbar { ToolbarItemGroup(placement: .navigationBarTrailing) { Button("Button1") { showingSheet = true } Button("Button2") { showingSheet = true } } } .sheet(isPresented: $showingSheet) { Sheet() } } } } Or this: struct ContentView2: View { @State private var showingSheet = false var body: some View { NavigationView { Text("1st View") .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button("Button1") { showingSheet = true } } ToolbarItem(placement: .navigationBarTrailing) { Button("Button2") { showingSheet = true } } } .sheet(isPresented: $showingSheet) { Sheet() } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to How can I auto-populate a Text Field once a button is selected?
You declare a local constant within offlineListing(_:), but it is not used and the value is disposed at the end of the method. (You would have seen a waring Initialization of immutable value 'productURLField' was never used; consider replacing with assignment to '_' or removing it, which should not be ignored.) Even if the local constant and the IBOutlet have exactly the same identifier, they are two different things and have nothing to do with each other. You may want to do something like this: @IBAction func offlineListing(_ sender: Any) { productURLField.text = "N/A" }
Topic: UI Frameworks SubTopic: UIKit Tags:
May ’21
Reply to Need help converting JSON objects from double & floats to strings
As already noted, when you need to convert Float/Double to String for assignment, you need to do it in the right hand side. So, this would be the minimal code: func connectLabels(loc: String, temp: Double, lat: Float, long: Float) { locationLabel.text = loc tempInFLabel.text = String(temp) latLabel.text = String(lat) longLabel.text = String(long) } But if you want to make your app sort of practical in the future, you should better use NumberFormatter for user readable values. Also, some users want temperatures shown in the unit they accustomed to, we use Celsius usually. So, some practical code would be something like this: static let tempFormatter: MeasurementFormatter = { let mf = MeasurementFormatter() //You may want to modify these as you like... mf.unitStyle = .medium mf.numberFormatter.maximumFractionDigits = 1 return mf }() static let latLongFormatter: NumberFormatter = { let nf = NumberFormatter() //You may want to modify these as you like... nf.usesSignificantDigits = true nf.minimumSignificantDigits = 5 nf.maximumSignificantDigits = 5 return nf }() func connectLabels(loc: String, temp: Double, lat: Float, long: Float) { locationLabel.text = loc let tempMeasurement = Measurement(value: temp, unit: UnitTemperature.fahrenheit) tempLabel.text = MyWeatherTableViewCell.tempFormatter.string(from: tempMeasurement) latLabel.text = MyWeatherTableViewCell.latLongFormatter.string(from: lat as NSNumber) longLabel.text = MyWeatherTableViewCell.latLongFormatter.string(from: long as NSNumber) }
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to How to access viewController components in model (MVC)
Okay, and do you have any idea how I can do that? Or a resource, a link to help me?  You can make your Model to trigger some events, and your view controller will be able to show UIAlertController or update text view based on the evens. To achieve this, you can use NotificationCenter, property observer, delegate pattern or there may be many other ways. Combine would be your another option if you prefer some modern ways. But, as you say Compute class is empty, I cannot say what would be best for you and cannot show any examples.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jun ’21
Reply to iOS app development
Is Python usable to make iOS apps on Mac in 2021 or only Swift? Swift and Objective-C are the only supported languages for developing iOS apps. (C/C++ could be another option for some specific components of Apple's platforms.) And Xcode (more specifically, version 12+) is the only supported IDE to make apps for App Store. You can find some third party frameworks or tools which enable you to develop iOS apps in JavaScript, Dart, C#, Ruby or Python. (It is very hard to find articles about developing iOS apps in Python, which seems to be a very minor choice.) If you want to use any of such frameworks, you need to know the risks of using them. For example, there were several posts recently, reporting they could not build their apps made by one of the third party frameworks. Also the Apple's dev forums are meant for code-level questions, using Apple's framework or tools for Apple's platforms. You should not go deep into the third party libraries or frameworks here in the dev forums. My recommendation, get the latest Mac which is capable of running the latest Xcode. And learn developing apps in Swift.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to Xcode Cannot Run the Default "Hello World" C++ Program
Any idea why this is happening? I have tried what you described using Xcode 12.5 on macOS 11.4. It ran without any problems and I could see in the debug console: Hello, World! Program ended with exit code: 0 Thus, there may be some issues with your environment, or macOS 11.2 may have some problems to work with the version of Xcode you are using. Do you think of anything special with your environment?
Jun ’21
Reply to Swift migration failed Segmentation fault: 11
Unfortunately, there's no quick fix for Segmentation fault: 11. In some limited cases, Clean Build Folder or removing derived data might work, but not for all cases. The first thing you should do is finding out which Swift file is (or which Swift files are) causing the issue. How many Swift files do you have in your project?
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’21
Reply to 2021-6 Missing Info.plist value - A value for the Info.plist key 'CFBundleIconName' is missing in the bundle, even then I include CFBundleIconName.
Have you added app icons in an asset catalog as suggested in the Apple's message? Apps built with iOS 11 or later SDK must supply app icons in an asset catalog and must also provide a value for this Info.plist key. For more information see http://help.apple.com/xcode/mac/current/#/dev10510b1f7.
Jun ’21
Reply to Get data from view after it gets added on screen using ForEach
Thanks for showing the refactored code. It compiled fine. I needed to add enableButtonBool = true, but it was a great help to guess what you want to do. (I still do not understand some parts of the code, but it may be better to show what I guessed.) I may be mistaking something, but you may want to do something like this: import SwiftUI struct ChecklistModel: Codable, Hashable { var description, remarks, status: String? } struct CheckListCard: View { @Binding var checkListData : ChecklistModel @State var statusList: [String] = [] @Binding var enableButtonBool: Bool var body: some View { let currentStatus = Binding<String>( get: {checkListData.status ?? ""}, set: {checkListData.status = $0}) let currentRemark = Binding<String>( get: {checkListData.remarks ?? ""}, set: {checkListData.remarks = $0}) VStack{ Text("Description").padding() .onAppear(){ addData() } if let description = checkListData.description { Text(description) .padding() } Text("Status").padding() if checkListData.status != nil { Picker("Status", selection: currentStatus) { ForEach(statusList, id: \.self){ status in Text(status) } }.pickerStyle(SegmentedPickerStyle()) .padding() .disabled(!enableButtonBool) } Text("Remarks") if checkListData.remarks != nil { TextField("Remarks", text: currentRemark) .disabled(!enableButtonBool) .padding() .background(Color(.white)) .cornerRadius(8) .accentColor(.gray) } else { TextField("Remarks", text: currentRemark) .disabled(!enableButtonBool) .padding() .background(Color(.white)) .cornerRadius(8) } } .padding() .background(Color("light_gray")) .foregroundColor(.black) .cornerRadius(8) .shadow(radius: 10) .padding() } func addData() { statusList.append("Yes") statusList.append("No") statusList.append("NA") if let status = checkListData.status { statusList.append(status) //<- Why this is needed? } } } struct CheckListSheet: View { @State var taskId: Int @State var checklistResponse: [ChecklistModel] = [ChecklistModel()] @State var enableButtonBool: Bool = false @State var statusList: [String] = [] var body: some View { Text("Checklist Items") .padding() .font(.title) ScrollView { ForEach(checklistResponse.indices, id:\.self) { index in CheckListCard(checkListData: $checklistResponse[index], enableButtonBool: $enableButtonBool) } if enableButtonBool { Button("Update") { updateCheckList() } } } .onAppear(){ getChecklists() } } func updateCheckList() { print("this is the checklistresponse \(checklistResponse)") } func getChecklists() { checklistResponse = [ ChecklistModel(description: "ist item", remarks: nil, status: "Yes"), ChecklistModel(description: "2nd item", remarks: "Fine", status: "no") ] enableButtonBool = true } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Toolbar buttons become unusable after closing the sheet.
Can you try something like this? struct ContentView: View { @State private var showingSheet = false var body: some View { NavigationView { Text("1st View") .toolbar { ToolbarItemGroup(placement: .navigationBarTrailing) { Button("Button1") { showingSheet = true } Button("Button2") { showingSheet = true } } } .sheet(isPresented: $showingSheet) { Sheet() } } } } Or this: struct ContentView2: View { @State private var showingSheet = false var body: some View { NavigationView { Text("1st View") .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button("Button1") { showingSheet = true } } ToolbarItem(placement: .navigationBarTrailing) { Button("Button2") { showingSheet = true } } } .sheet(isPresented: $showingSheet) { Sheet() } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to How can I auto-populate a Text Field once a button is selected?
You declare a local constant within offlineListing(_:), but it is not used and the value is disposed at the end of the method. (You would have seen a waring Initialization of immutable value 'productURLField' was never used; consider replacing with assignment to '_' or removing it, which should not be ignored.) Even if the local constant and the IBOutlet have exactly the same identifier, they are two different things and have nothing to do with each other. You may want to do something like this: @IBAction func offlineListing(_ sender: Any) { productURLField.text = "N/A" }
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to Need help converting JSON objects from double & floats to strings
As already noted, when you need to convert Float/Double to String for assignment, you need to do it in the right hand side. So, this would be the minimal code: func connectLabels(loc: String, temp: Double, lat: Float, long: Float) { locationLabel.text = loc tempInFLabel.text = String(temp) latLabel.text = String(lat) longLabel.text = String(long) } But if you want to make your app sort of practical in the future, you should better use NumberFormatter for user readable values. Also, some users want temperatures shown in the unit they accustomed to, we use Celsius usually. So, some practical code would be something like this: static let tempFormatter: MeasurementFormatter = { let mf = MeasurementFormatter() //You may want to modify these as you like... mf.unitStyle = .medium mf.numberFormatter.maximumFractionDigits = 1 return mf }() static let latLongFormatter: NumberFormatter = { let nf = NumberFormatter() //You may want to modify these as you like... nf.usesSignificantDigits = true nf.minimumSignificantDigits = 5 nf.maximumSignificantDigits = 5 return nf }() func connectLabels(loc: String, temp: Double, lat: Float, long: Float) { locationLabel.text = loc let tempMeasurement = Measurement(value: temp, unit: UnitTemperature.fahrenheit) tempLabel.text = MyWeatherTableViewCell.tempFormatter.string(from: tempMeasurement) latLabel.text = MyWeatherTableViewCell.latLongFormatter.string(from: lat as NSNumber) longLabel.text = MyWeatherTableViewCell.latLongFormatter.string(from: long as NSNumber) }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’21
Reply to How to access viewController components in model (MVC)
the problem is that I need to use the UIAlertController and the textView in the Compute class That's against the MVC design pattern. You should not touch views directly from Model.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
What do you want? This is not a place to write a bug report.
Replies
Boosts
Views
Activity
Jun ’21
Reply to Recipes App | SwiftUI | Creating the pages
Unless you clarify what you have done till now, it is hard to say something sure.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to this class is not key value coding-compliant for the key result. - Error
How can I fix this? That may happen when an IBOutlet connection to result exists in the storyboard. Do you know how to see all the connection of the storyboard? You may need to remove the wrong connection and re-connect it.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to How to access viewController components in model (MVC)
Okay, and do you have any idea how I can do that? Or a resource, a link to help me?  You can make your Model to trigger some events, and your view controller will be able to show UIAlertController or update text view based on the evens. To achieve this, you can use NotificationCenter, property observer, delegate pattern or there may be many other ways. Combine would be your another option if you prefer some modern ways. But, as you say Compute class is empty, I cannot say what would be best for you and cannot show any examples.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Scene not showing full screen on iPhone
Have you added Launch Screen to your project?
Replies
Boosts
Views
Activity
Jun ’21
Reply to iOS app development
Is Python usable to make iOS apps on Mac in 2021 or only Swift? Swift and Objective-C are the only supported languages for developing iOS apps. (C/C++ could be another option for some specific components of Apple's platforms.) And Xcode (more specifically, version 12+) is the only supported IDE to make apps for App Store. You can find some third party frameworks or tools which enable you to develop iOS apps in JavaScript, Dart, C#, Ruby or Python. (It is very hard to find articles about developing iOS apps in Python, which seems to be a very minor choice.) If you want to use any of such frameworks, you need to know the risks of using them. For example, there were several posts recently, reporting they could not build their apps made by one of the third party frameworks. Also the Apple's dev forums are meant for code-level questions, using Apple's framework or tools for Apple's platforms. You should not go deep into the third party libraries or frameworks here in the dev forums. My recommendation, get the latest Mac which is capable of running the latest Xcode. And learn developing apps in Swift.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Xcode Cannot Run the Default "Hello World" C++ Program
Any idea why this is happening? I have tried what you described using Xcode 12.5 on macOS 11.4. It ran without any problems and I could see in the debug console: Hello, World! Program ended with exit code: 0 Thus, there may be some issues with your environment, or macOS 11.2 may have some problems to work with the version of Xcode you are using. Do you think of anything special with your environment?
Replies
Boosts
Views
Activity
Jun ’21
Reply to Swift migration failed Segmentation fault: 11
Unfortunately, there's no quick fix for Segmentation fault: 11. In some limited cases, Clean Build Folder or removing derived data might work, but not for all cases. The first thing you should do is finding out which Swift file is (or which Swift files are) causing the issue. How many Swift files do you have in your project?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Build a windowed C++ application for Mac in 2021
In the latest version of Xcode I don't see any options to create an Objective-C application.  In Xcode 12.5, which I believe is the latest, I see an option to choose Language as Objective-C. What version of Xcode are you using? Have you tried to change other options when creating a project?
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to 2021-6 Missing Info.plist value - A value for the Info.plist key 'CFBundleIconName' is missing in the bundle, even then I include CFBundleIconName.
Have you added app icons in an asset catalog as suggested in the Apple's message? Apps built with iOS 11 or later SDK must supply app icons in an asset catalog and must also provide a value for this Info.plist key. For more information see http://help.apple.com/xcode/mac/current/#/dev10510b1f7.
Replies
Boosts
Views
Activity
Jun ’21