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
}
Post
Replies
Boosts
Views
Activity
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.
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.
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?
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.
@satcol, could you please share the exact details of how you linked the XcodeKit lib?
I've added XcodeKit as a linked binary under Build Phases but when I link, it gives a linker error: "framework not found XcodeKit".
I've raised a TSI for this and the conclusion was that it is not possible. NSTextView and NSTextField would have to be changed to allow this. The issue is that they do not pass the copy: selector up the responder chain when it is not handled so it stops there.
I've raised a TSI for this and the conclusion was that this is not possible.
My work-around was to add a specific menu item with its own shortcut. It is not as elegant as I would have liked, but it works.
Thanks Eskimo. I would have replied long ago but I did not get notified about your reply :)
It is now finally fixed and one can now click on the alarm bell at the top of the post to get notified again. Yea!
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")
}
}
}
}
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.
No, I have not.
I found a workaround by wrapping a NSTextField in a NSViewRepresentable but this broke again in Big Sur. So, I am again trying to resolve this.
ps. Sorry for only replying now. For some reason I missed the notification.
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 }
}
I've also asked this question (slightly differently) months ago and managed to solve it.
See the response to my question here. - https://developer.apple.com/forums/thread/124617
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()
	}
}