Post

Replies

Boosts

Views

Activity

Reply to Updating EditButton
This thread may provide some hints: https://www.hackingwithswift.com/forums/swiftui/list-view-stuck-in-edit-mode/7401 It tested this, which apparently does what you need: struct ContentView: View { @State private var selects: Set<Int> = [] @State var range = [1, 2, 3 ,4, 5] @Environment(\.editMode) var editMode var body: some View { VStack{ EditButton() List(selection: $selects){ ForEach(range, id: \.self) { ItemInList(num: $0) } .onDelete { range.remove(atOffsets: $0) editMode?.wrappedValue = .inactive } } .listStyle(PlainListStyle()) } } }
Dec ’24
Reply to On a brand new build, why would I get this error: "Error creating the CFMessagePort needed to communicate with PPT."
I get the same message in log when creating a project in Xcode 16.2 on MacMini with MacOS 14.7.2. Error creating the CFMessagePort needed to communicate with PPT. Failed to send CA Event for app launch measurements for ca_event_type: 0 event_name: com.apple.app_launch_measurement.FirstFramePresentationMetric Failed to send CA Event for app launch measurements for ca_event_type: 1 event_name: com.apple.app_launch_measurement.ExtendedLaunchMetrics I tested on Xcode 15.3 creating a new project does not show the log but another one: Logging Error: Failed to initialize logging system. Log messages may be missing. If this issue persists, try setting IDEPreferLogStreaming=YES in the active scheme actions environment variables. opening the project created with 16.2 crashed Xcode, even after changing project format to Xcode 15.3 from 16.0. As the Xcode 16,2 project works without problem, that seems to be just log noise. You could file a bug report however.
Topic: UI Frameworks SubTopic: SwiftUI
Dec ’24
Reply to textfield does not allow any user input
Why do you need to create a new UITextField in the IBAction ? You recreate a new UITextField which hides the existing one, hence you cannot enter anything). The logical way to do it: create the UITextField in the storyboard (I understand you did it) connect to an IBOutlet that you name nameTextField declare the placeholder in the storyboard (attributes inspector). It will be displayed automatically when the textField is empty. do not create the IBAction yet Then you should be able to type in nameTextField If you need an IBAction (but do NOT create nameTextField subview inside) declare in storyboard that the delegate of the textField is the UIViewController declare that the UIViewController conforms to UITextFieldDelegate change the IBAction (if you need to have some action once text entered) by: @IBAction func insertName(_ sender: UITextField) { let enteredName = sender.text print("Entered Name:", enteredName ?? "") } What is the error message on line 13 ?
Topic: UI Frameworks SubTopic: UIKit
Dec ’24
Reply to Stuck using variable in the tex statement
If I am honest this bit of code was generated, after a lot of trial and error by ChatBT. That's a problem when you don't understand the code you use. Did you ask CGT to solve the issue, as they proposed the code ? 😉 Returning to human answer, you didn't answer my question. Did you test the code I sent you? What is the result ?
Dec ’24
Reply to Stuck using variable in the tex statement
Could you test: case rule.hasSuffix("wins."): // "Player to reach X wins." let topScorers = scores.filter { $0.1 >= target } if !topScorers.isEmpty { print("topScorers not Empty") // <<-- ADD THIS let maxScore = scores.max(by: { $0.1 < $1.1 })?.1 ?? 0 let topScorers2 = scores.filter { $0.1 == maxScore } // <<-- CHANGE to topScorers2 gameIsDraw = topScorers2.count > 1 winner = topScorers2.count == 1 ? topScorers2.first?.0 : nil And tell what you get. A comment. Even if the syntax is correct, let maxScore = scores.max(by: { $0.1 < $1.1 })?.1 ?? 0 is hard to read. .1 is a property, it would be so easier to read by using the property name
Dec ’24
Reply to UIViewRepresentable is not working
I tested this part of code, with no error, as long as you include the updateUIView function, even empty. struct WebViewContainerRepresentable: UIViewRepresentable { typealias UIViewType = WKWebView func makeUIView(context: Context) -> WKWebView { let webView = WKWebView() if let url = Bundle.main.url(forResource: "index", withExtension: "html") { webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent()) } return webView } func updateUIView(_ uiView: WKWebView, context: Context) { // Updates not required for this use case } }
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’24
Reply to Stuck using variable in the tex statement
So that means winner is nil. There is likely an error here: gameIsDraw = topScorers.count > 1 winner = topScorers.count == 1 ? topScorers.first?.0 : nil gameIsDraw is true if count > 1 But winner is defined when count == 1 It should probably be winner = topScorers.count >= 1 ? topScorers.first?.0 : nil
Dec ’24
Reply to array
So, you will pass the array populated with the prices (in fact, you probably need to pass more information, to know to which pizza or customer a price refers to). Is it for SwiftUI or UIKit ? for SwiftUI, you would have a State var with the costs (or more info) and could use List to display @State var costs: [Double] = [] // You will have to append this array when you add a pizza In the body of the View, something like: struct ContentView: View { @State var costs: [Double] = [] // You will have to append this array when you add a pizza @State var newCost: Double = 0 var body: some View { VStack { List(costs, id: \.self) { cost in Text("cost: \(String(format: "%4.2f", cost) )") } HStack { Text("New pizza cost") TextField("", value: $newCost, format: .number) .border(.blue) } Button(action: { if newCost > 0 { self.costs.append(newCost) } newCost = 0 }) { Text("Append") } Spacer() } } }
Dec ’24
Reply to array
I'm not sure to understand. With the present code: func myfunc(costa: [Double]) { } myfunc(costa:[ ]) calling with [] parameter of course uses an empty array. If you call func myfunc(costa: [Double]) { print(costa.count) } myfunc(costa:[ 10.0, 20.0]) It will not be empty. You will see in log it has 2 items. But is it what you want ? What do you do in myfunc ? Just use the array (as in the example above) ? Or add items to the array ?
Dec ’24
Reply to Seeking advice on why Dog Translator Game for Dogs violates guideline 1.1.6 Safety: Objectionable Content
Including the "game" word and a notice that it is for entertainment only is not enough according to guideline 1.1.6 False information and features, including inaccurate device data or trick/joke functionality, such as fake location trackers. Stating that the app is “for entertainment purposes” won’t overcome this guideline. My understanding is that reviewer considers that some people will think they are able to speak to their dog. That's what your app name suggests with "Translator" and that could mislead users into thinking they will be able to "speak" dog. No one can give sure advice to pass review, but… At least, you could rename completely the app, eliminating the translator word. May be something like "Barking like a dog" or "Barking" ? would be more acceptable. And check that your app cannot be understood as a way to speak to a dog. Even the icon should take care of this, as well as all textes and images in the app. Good luck.
Dec ’24
Reply to Building Issue
Welcome to the forum. Is it a project (not a playground) ? Do you mean this right pointing black triangle on the right? Which version of Xcode ? Do you see a simulator selected in the top line ? What happens if you create a new project (iOS project, SwiftUI for instance) ? Do you get the triangle ? If not, you may have to reinstall Xcode
Topic: App & System Services SubTopic: General Tags:
Dec ’24