Post

Replies

Boosts

Views

Activity

Reply to Checking for NIL
You can filter what is typed, with TextField delegate. Don't forget to declare the ViewController as the delegate for the TextFields. Can be improved if you want to allow to move insertion cursor in an existing text.. let gcTabAscii = 9 let gcLineFeedAscii = 10 let gcReturnAscii = 13 func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { guard let charCode = string.first?.asciiValue else { if string == "" { // Accept backspace return true } return false } if charCode == gcLineFeedAscii || charCode == gcReturnAscii { // It is lineFeed even when typing return return true } if charCode == gcTabAscii { // Tab textField.text = textField.text! return false // You should fine tune here to allow for - sign or dot sign at start } let newString = textField.text! + string if Int(newString) != nil { // So we typed something in newString and it is a valid number ; if you do not expect an Int but any number, test for Float(newString) return true } else { return false // You could allow for - or starting dot with // return newString == "-" || newString == "." } }
Nov ’24
Reply to Guideline 2.1 - Information Needed
AFAIU, your app is not trading cryptocurrencies but advise about trading. So, in a sense, it facilitates transactions. That could be the reason for the constraints you get according to 3.1.5 (iii) Exchanges: Apps may facilitate transactions Note: this is a bit similar to medical app: even if they do not sell medicine or practice any medicine, if they advise on health they must meet some strict requirements. Did you try to contact support ?
Nov ’24
Reply to I get this Issue : ContentView.swift:3016:25 The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions. But I don´t know what I have to do. I am a noob. Can anybody help me.
Welcome to the forum. But your post is really badly written: When you post code, use code formatter to make your code readable. avoid duplicating the post provide all structure definitions, otherwise impossible to test and investigate. make sure the code you post does compile: What are: OrderItem MenuCategory etc Your code compile with those error. What di you post ? Real code ? An edited version (bad idea): @Environment(.dismiss) private var dismiss It should be @Environment(\.dismiss) private var dismiss This as well if MenuCategory is a type definition and not a var ForEach(MenuCategory) { category in struct OrderRow: View is declared twice
Nov ’24
Reply to Limiting the Number of Bool (True) Values
If I understand well, you want to allow a max of 2 checked on. And nothing should happen if trying to check a third (except maybe an error message). Here is how I did this: struct ContentView: View { @State private var viewModel = ContentViewModel() @State var allowMoreChecks = true // <<-- ADDED var body: some View { VStack(alignment: .leading) { List { ForEach(viewModel.models, id: \.id) { model in CheckButtonView(id: model.id, text: model.name, isOn: model.isOn, moreAllowed: allowMoreChecks) { id, bool in updateDate(id: id, bool: bool) // <<-- ADDED moreAllowed } } } } } func updateDate(id: String, bool: Bool) { for i in 0..<viewModel.models.count { let oldModel = viewModel.models[i] if oldModel.id == id { let newModel = Content(id: oldModel.id, name: oldModel.name, isOn: bool) viewModel.models.remove(at: i) viewModel.models.insert(newModel, at: i) break } } var count = 0 for i in 0..<viewModel.models.count { let model = viewModel.models[i] if model.isOn { count += 1 } } allowMoreChecks = count < 2 // <<-- ADDED } } struct CheckButtonView: View { let id: String let text: String @State var isOn: Bool var moreAllowed : Bool // <<-- ADDED var callBack: (String, Bool) -> Void var body: some View { HStack { Button { if !moreAllowed && !isOn {. // <<-- ADDED print("not authorized") } else { isOn.toggle() callBack(id, isOn) } } label: { Image(systemName: isOn ? "checkmark.square.fill" : "square") .resizable() .aspectRatio(contentMode: .fit) .frame(width: 18) .tint(!isOn ? .black : .blue) } Text(text) .font(.subheadline) Spacer() } .frame(maxWidth: .infinity) } } struct Content { let id: String let name: String let isOn: Bool } class ContentViewModel: ObservableObject { @Published var models = [Content]() @Published var canChange = true init() { models = [ Content(id: UUID().uuidString, name: "Jim", isOn: false), Content(id: UUID().uuidString, name: "Jenny", isOn: false), Content(id: UUID().uuidString, name: "Nancy", isOn: false), Content(id: UUID().uuidString, name: "Natalie", isOn: false) ] } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’24
Reply to Checking for NIL
You can filter what is typed, with TextField delegate. Don't forget to declare the ViewController as the delegate for the TextFields. Can be improved if you want to allow to move insertion cursor in an existing text.. let gcTabAscii = 9 let gcLineFeedAscii = 10 let gcReturnAscii = 13 func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { guard let charCode = string.first?.asciiValue else { if string == "" { // Accept backspace return true } return false } if charCode == gcLineFeedAscii || charCode == gcReturnAscii { // It is lineFeed even when typing return return true } if charCode == gcTabAscii { // Tab textField.text = textField.text! return false // You should fine tune here to allow for - sign or dot sign at start } let newString = textField.text! + string if Int(newString) != nil { // So we typed something in newString and it is a valid number ; if you do not expect an Int but any number, test for Float(newString) return true } else { return false // You could allow for - or starting dot with // return newString == "-" || newString == "." } }
Replies
Boosts
Views
Activity
Nov ’24
Reply to percentage
Use String with format: let percentString = String(format: "%4.2f", valueToPrint) + " %"
Replies
Boosts
Views
Activity
Nov ’24
Reply to Xcode crash report please help me to fix it I am suffering this issue from many days
Welcome to the forum. You don't give enough information. Xcode version is 16.1. Is it a beta or a release ? When does it occur ? When compiling your app ? If so, do you get error message ? At launch ? : if so you should reinstall Xcode.
Replies
Boosts
Views
Activity
Nov ’24
Reply to Guideline 2.1 - Information Needed
AFAIU, your app is not trading cryptocurrencies but advise about trading. So, in a sense, it facilitates transactions. That could be the reason for the constraints you get according to 3.1.5 (iii) Exchanges: Apps may facilitate transactions Note: this is a bit similar to medical app: even if they do not sell medicine or practice any medicine, if they advise on health they must meet some strict requirements. Did you try to contact support ?
Replies
Boosts
Views
Activity
Nov ’24
Reply to Help/App rejected
What is your question ? It seems the reviewer has explained in detail what you need to do (and not do). What else ?
Replies
Boosts
Views
Activity
Nov ’24
Reply to python in Xcode
Welcome to the forum. Hope that will give the complete answer: https://www.browserstack.com/guide/xcode-python-guide
Replies
Boosts
Views
Activity
Nov ’24
Reply to Unable to change TabView's background color
Did you try one of the many solutions proposed in this old thread ? https://forums.developer.apple.com/forums/thread/121799
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’24
Reply to I get this Issue : ContentView.swift:3016:25 The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions. But I don´t know what I have to do. I am a noob. Can anybody help me.
Welcome to the forum. But your post is really badly written: When you post code, use code formatter to make your code readable. avoid duplicating the post provide all structure definitions, otherwise impossible to test and investigate. make sure the code you post does compile: What are: OrderItem MenuCategory etc Your code compile with those error. What di you post ? Real code ? An edited version (bad idea): @Environment(.dismiss) private var dismiss It should be @Environment(\.dismiss) private var dismiss This as well if MenuCategory is a type definition and not a var ForEach(MenuCategory) { category in struct OrderRow: View is declared twice
Replies
Boosts
Views
Activity
Nov ’24
Reply to Worst update to photos app ever
You may have read what is the general feedback on new photo app. Mixed feelings to say the least: https://www.macrumors.com/2024/11/21/apples-photos-app-overhaul-controversial/
Replies
Boosts
Views
Activity
Nov ’24
Reply to Limiting the Number of Bool (True) Values
If I understand well, you want to allow a max of 2 checked on. And nothing should happen if trying to check a third (except maybe an error message). Here is how I did this: struct ContentView: View { @State private var viewModel = ContentViewModel() @State var allowMoreChecks = true // <<-- ADDED var body: some View { VStack(alignment: .leading) { List { ForEach(viewModel.models, id: \.id) { model in CheckButtonView(id: model.id, text: model.name, isOn: model.isOn, moreAllowed: allowMoreChecks) { id, bool in updateDate(id: id, bool: bool) // <<-- ADDED moreAllowed } } } } } func updateDate(id: String, bool: Bool) { for i in 0..<viewModel.models.count { let oldModel = viewModel.models[i] if oldModel.id == id { let newModel = Content(id: oldModel.id, name: oldModel.name, isOn: bool) viewModel.models.remove(at: i) viewModel.models.insert(newModel, at: i) break } } var count = 0 for i in 0..<viewModel.models.count { let model = viewModel.models[i] if model.isOn { count += 1 } } allowMoreChecks = count < 2 // <<-- ADDED } } struct CheckButtonView: View { let id: String let text: String @State var isOn: Bool var moreAllowed : Bool // <<-- ADDED var callBack: (String, Bool) -> Void var body: some View { HStack { Button { if !moreAllowed && !isOn {. // <<-- ADDED print("not authorized") } else { isOn.toggle() callBack(id, isOn) } } label: { Image(systemName: isOn ? "checkmark.square.fill" : "square") .resizable() .aspectRatio(contentMode: .fit) .frame(width: 18) .tint(!isOn ? .black : .blue) } Text(text) .font(.subheadline) Spacer() } .frame(maxWidth: .infinity) } } struct Content { let id: String let name: String let isOn: Bool } class ContentViewModel: ObservableObject { @Published var models = [Content]() @Published var canChange = true init() { models = [ Content(id: UUID().uuidString, name: "Jim", isOn: false), Content(id: UUID().uuidString, name: "Jenny", isOn: false), Content(id: UUID().uuidString, name: "Nancy", isOn: false), Content(id: UUID().uuidString, name: "Natalie", isOn: false) ] } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’24
Reply to SwiftUI App crashes while switching orientation
Welcome to the forum. Could you post minimal code so that we can try to reproduce and try to understand ? Maybe that's just an error in your code…
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’24
Reply to Issue with Empty Window Appearing on App Launch for macOS App - Help Needed
Could you show definition of LanguageSwitchPanel so that we can test and reproduce ?
Replies
Boosts
Views
Activity
Nov ’24
Reply to How to preview an `App` class in xcode?
If I understand your question, just use simulator. It is done to allow testing app on any type of device.
Replies
Boosts
Views
Activity
Nov ’24
Reply to Yahoo email screen
Did you try a long press on a box, to see if you get a context menu with a delete option ?
Replies
Boosts
Views
Activity
Nov ’24