Post

Replies

Boosts

Views

Activity

Reply to Does UITextField in UIViewRepresentable have a solution?
I found something that fixed my problem but I'm not sure it is the right way of doing things. Setting the horizontal content compression resistance priority to defaultLow made it scroll correctly. The makeUIView function below shows the full solution. func makeUIView(context: Context) -> UIViewType { // Setup text view: // ---------------- let textView = UITextField() textView.delegate = context.coordinator textView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) // Creae a dummy view for the inputView (keyboard) so that the default // keyboard is not shown: let dummyView = UIView(frame: CGRect.zero) textView.inputView = dummyView return textView }
Apr ’22
Reply to Cannot bind to local UDP socket - address already in use
Thanks. I am not sure what to do with this tread since the problem was not a code problem but a port being reserved by XQuartz. Thanks for the advice on netstat. I will use it in the future but it seems it would not have picked up the problem either since the port was not open, it was just being reserved. I cannot confirm since I've uninstalled XQuartz to resolve my issue (did not have the option to move other port). I am marking this as the answer purely to close the thread, and in case anyone ever gets to it. Let me know if you disagree.
Feb ’22
Reply to How do I get recommended iOS app preview resolution?
OK, I knew I was missing something stupid: I should not be using iPhone 13 Pro for the video, but an iPhone 13 Pro Max. That gives the correct resolution. Bonus tip: Make use of iMovie's built-in support for generating app previews (yes, I know this should be obvious, but just in case). This did allow me to record my video on my iPhone 13 Pro and still save it in the correct resolution.
Jan ’22
Reply to Xcode 12.2 & Big Sur: Source editor extensions have vanished
The strangest thing now happened. The extensions that worked a day ago no longer work. They are not even there when I open System Preferences Extensions. It is as if it never existed. There was no reboot through the night, my macBook was closed. How can this be? Nothing that I tried (even reboot) is helping. I can even create a new project and follow the steps to create an extension but not even debugging works (it starts debugging but the extension is not under the Editor menu in xcode. Any suggestions?
Feb ’21
Reply to Xcode 12.2 & Big Sur: Source editor extensions have vanished
I can answer my own question about embedding and signing XcodeKit. I had my project selected instead of the target extension. Steps to link XcodeKit (just in case someone else needs exact steps): Select your top-level project in the Project Navigator. Under TARGETS, select your extension to see its settings. In the General tab, scroll down to Frameworks and Libraries. For a new extension, it will show two libs: 1) Cocoa.framework; 2) XcodeKit.framework. Both have the option Do Not Embed selected. Change XcodeKit.framework to Embed & Sign. Rebuild. I can also confirm this resolved the issue.
Feb ’21
Reply to How do I add MenuItem to menubar in macos using SwiftUI?
Thanks, that did help. For completeness, I wrote this small sample app that adds a new menu item to the menu and overrides the copy menu. @main struct MenuTestApp: App {   var body: some Scene {     WindowGroup {       ContentView()     }     .commands {       CommandMenu("My Top Menu") {         Button("Sub Menu Item") { print("You pressed sub menu.") }           .keyboardShortcut("S")       }       CommandGroup(replacing: .pasteboard) {         Button("Cut") { print("Cutting something...") }           .keyboardShortcut("X")         Button("Copy") { print("Copying something...") }           .keyboardShortcut("C")         Button("Paste") { print("Pasting something...") }           .keyboardShortcut("V")         Button("Paste and Match Style") { print("Pasting and Matching something...") }           .keyboardShortcut("V", modifiers: [.command, .option, .shift])         Button("Delete") { print("Deleting something...") }           .keyboardShortcut(.delete)         Button("Select All") { print("Selecting something...") }           .keyboardShortcut("A")       }     }   } }
Feb ’21
Reply to How to override Edit>Copy when first responder cannot copy
My app is displaying a default value as the user enters data in the TextField. It is clear that this data that is being displayed will be copied. The problem does not seem to be related to Enabled since it is set in IB. I got it to work by removing the view that had focus (in my case a TextField). When I did this, Copy was enabled and my copy function in code above was called. My problem still seems to be related to providing and telling the system that copy is available when the current first responder cannot handle it. I've tried various things like creating my own NSTextField and trying to override copy but without success. I've also created a new SwiftUI app and posted this thread - https://developer.apple.com/forums/thread/667633 since it more clearly shows my issue. ps. Sorry for the late reply. It seems my notifications are not working.
Nov ’20
Reply to How do I get a Picker to show initial and selected value?
I found that changing my picker to use an Enum works: Picker("Pick Something: ", selection: $pickedValue) { 	ForEach(TestState.allCases) { state in 		Text(state.rawValue).tag(state) 	} } Why would this work differently from the initial code? TestState is declared: enum TestState: String, CaseIterable, Identifiable {   case one   case two   var id: String { self.rawValue } }
Nov ’20
Reply to Can I bind to Int but edit with TextField
I found a much better solution. Not only does it solve the original problem, but it also solves the problem when editing doubles (see previous comments) and it allows a single value to be edited by multiple TextFields (or sliders, or any other visual element). The key is in not binding the TextField to a string, but creating a new Binding with a getter and setter. A local private string is used to keep the string being edited by the TextField in synch with the value (or partial value in this case). The example below shows a struct with two members. A value of this type can be passed to the custom view that is used to edit it. The value is shown at the top of the view (for information only). The view has two TextFields that is used to edit the two members of the value. This is just a proof of concept and can be improved further by using Formatters. This example also scales nicely in that a custom view can be created to edit a custom type and the complexity can be hidden inside the custom view. struct MyStruct { 	var a: Int 	var b: Double } struct MyStructView: View { 	@Binding var myStruct: MyStruct 	 	@State private var lastValidValue = MyStruct(a: 10, b: 20) 	@State private var isEditingA = false 	@State private var isEditingB = false 	@State private var aStrValue = "" 	@State private var bStrValue = "" 	 	var body: some View { 		 		VStack { 			Text("myStruct.a = \(myStruct.a)	.b = \(myStruct.b)") 			Divider() 			 			HStack { 				Text("a = ") 				TextField("Value a", text: Binding( 				get: { 					if self.isEditingA { 						return self.aStrValue 					} else { 						return "\(self.myStruct.a)" 					} 				}, set: { str in 					self.aStrValue = str 					 					if let tmp = Int(str) { 						self.myStruct.a = tmp 						self.lastValidValue = self.myStruct 					} else { 						self.myStruct.a = self.lastValidValue.a 					} 				}), onEditingChanged: { editing in 					self.isEditingA = editing 				}) 			} 			 			HStack { 				Text("b = ") 				TextField("Value b", text: Binding( 					get: { 						if self.isEditingB { 							return self.bStrValue 						} else { 							return "\(self.myStruct.b)" 						} 				}, set: { str in 					self.bStrValue = str 					 					if let tmp = Double(str) { 						self.myStruct.b = tmp 						self.lastValidValue = self.myStruct 					} else { 						self.myStruct.b = self.lastValidValue.b 					} 				}), onEditingChanged: { editing in 					self.isEditingB = editing 				}) 			} 		} 		.frame(width: 300, height: 100) 		.padding() 		.onAppear { 			self.lastValidValue = self.myStruct 		} 	} } struct ContentView: View { 	@State private var myStruct = MyStruct(a: 1, b: 2.0) 	 	var body: some View { 		MyStructView(myStruct: $myStruct) 	} } struct ContentView2_Previews: PreviewProvider { 	static var previews: some View { 		ContentView() 	} }
Jun ’20