Hi Quinn, if I may add a point 10 to your (very meaningful) list:
when pasting images, think of reducing the size (can edit simply the image ref by dividing a dimension by 2) to avoid huge images that clutter the screen.
When you get an answer, please indicate if that solved the issue, if not explain what is not working. And don't forget to close the thread by marking the correct answer once you got it.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
That's an old question (this thread https://developer.apple.com/forums/thread/16375 dates back iOS9 or this other thread https://stackoverflow.com/questions/67249956/uisearchbar-warning-uitexteffectswindow-should-not-become-key-please-file-a-bu), but I've not found a comprehensive answer yet.
I need to add a Return key to a numeric keyboard (BTW, how is it it does not exist in standard ?)
I used to do it using
let keyBoardWindow = UIApplication.shared.windows.last
to get the keyboard window and then adding the subview (self.returnButton) to it
keyBoardWindow?.addSubview(self.returnButton)
Worked great and still works OK with iOS 15.
But we are told to use connectedScenes instead…
So I adapt code:
var keyBoardWindow: UIWindow? = nil
if #available(iOS 13.0, *) { // use connectedScenes
let scenes = UIApplication.shared.connectedScenes
let windowScene = scenes.first as? UIWindowScene
if let kbWindow = windowScene?.windows.last {
keyBoardWindow = kbWindow
}
} else {
keyBoardWindow = UIApplication.shared.windows.last
}
It runs, but subview does not show.
The problem is that keyboardWindow used to be a UIRemoteKeyboardWindow (the true keyboard window) and now is UITextEffectsWindow, which is not the real keyboardWindow. So adding subview to it adds improperly in the hierarchy.
Note: someone detailed the view hierarchy here: https://developer.apple.com/forums/thread/664547
UIWindow
UITextEffectsWindow
UIInputWindowController
UIInputSetContainerView
UIInputSetHostView
UIEditingOverlayViewController
UIEditingOverlayGestureView
I guess I have to add subview to something else than UITextEffectsWindow (keyBoardWindow), but to what ?
I tried
keyBoardWindow = kbWindow.superview as? UIWindow
to no avail.
I also tried to debug view hierarchy, but keyboard does not show in debugView.
That's a follow up of a previous thread.
https://developer.apple.com/forums/thread/707130
I did some test on iOS 16 simulator with Xcode 14ß.
Recognition is very poor. And recognition rate of some single letters (an L or an I for instance) is zero (literally). Same code worked better (success 50% for same single letters) with iOS 15.2.
Did something change on iOS 16 ? I filed a bug report: Jun 7, 2022 at 3:28 PM – FB10066541
Is there a difference in the distribution of results between those 2 forms ?
let x = (1...9).randomElement()!
let y = Int.random(in: 1...9)
In doc, I never see the first form used
I installed Xcode 14.2 (in parallel with other versions of Xcode with different names) on MBP MacOS 12.6.2.
Il works OK except when trying to use WatchOS simulator.
When I select a WatchOS target and then look for simulator, none is installed. I get an item in menu proposing to GET 9.1.
I downloaded.
But at the end of download, installation failed with the message that installation of watchOS 9.1 simulator runtime failed in CoreSimulator.
I tried the solution proposed here, to no avail.
https://stackoverflow.com/questions/74096242/unable-to-select-device-for-watchos-app-in-xcode
Note: installation on an iMac running 12.6.2 and Xcode 14.2 shows a long list of simulators:
With this code, button is at the center of the view and message is logged only when tapping in the button
1. struct ContentView: View {
2. var body: some View {
3.
4. ZStack {
5. Button(action: {
6. print("Touched")
7. }) {
8. Image(systemName: "square.split.diagonal.2x2")
9. .font(.system(size: 24))
10. .foregroundColor(.black)
11. // .position(x: 12, y: 12)
12. }
13.
14. }
15. .frame(width: 300, height: 300)
16. .background(Color.yellow)
17. }
18. }
But if I uncomment line 11, the message is logged on tap anywhere in the view.
How is it position() changes the behaviour ?
I use a ViewBuilder to generate the destination used in a NavigationSplitView (to select the detail View).
This viewBuilder depends on a parameter (in fact 2, but I try to simplify).
ViewBuilder is simple, just calls a View:
@ViewBuilder func destination(object: SomeObject, name: String) -> some View {
MyView(objToUse: object, nameToUse: name)
}
But this does not work. When I change the selection in the Master of the splitView, view is not updated (even though I've checked the content is updated.
This si so simple that I started using directly
MyView(objToUse: object, nameToUse: name)
in the detail View.
It did not work either.
Now, here is the surprise: if I use a switch statement in the ViewBuilder, it works:
Let's say we have:
struct SomeContent: Hashable, Identifiable, Codable {
var id = UUID()
var name: String
}
struct Object : Hashable, Identifiable, Equatable, Codable {
var id = UUID()
var content: [SomeContent] = []
}
So I define a func to get all the names
func allNames(of object: SomeObject) -> [String] {
var names : [String] = []
for o in object.content {
names.append(o.name)
}
return names
}
And modify ViewBuilder as follows: it works
@ViewBuilder func destination(object: SomeObject, name: String) -> some View {
let names : [String] = allNames(of: object)
switch name {
case names[0]: MyView(objToUse: object, nameToUse: name)
case names[1]: MyView(objToUse: object, nameToUse: name)
case names[2]: MyView(objToUse: object, nameToUse: name)
default: EmptyView()
}
It also works with nested if else if instead of a switch.
What is it I am missing ?
How do we switch on/off the display of lines at top of a window.
It should be in Preferences, but I cannot find it.
I noticed today that font has changed in some sections of this forum.
2 examples:
in forums tag: https://developer.apple.com/forums/
font is apparently Times-Roman
in Swift tag: https://developer.apple.com/forums/tags/swift
font is apparently SFProText-Medium
Since the maintenance 2 days ago, it seems editor has issues. Is it only me ?
Marking a text as quote does nothing. I mark this sentence as Quote to illustrate.
I tried to reply to a post : https://developer.apple.com/forums/thread/728329
But clicking on Reply button does nothing. ANd the Reply section does not show. No issue to answer to other threads.
Is it only me ?
I'm running a simulation (SwiftUI app), which has 100 steps.
I need each step to be executed in order.
A first try was to dispatch with delay to schedule each second:
for step in 0..<100 {
DispatchQueue.main.asyncAfter(deadline: .now() + Double(step) * 1.0) {
// simulation code
}
}
Very poor results as 100 running threads are too much load for the system.
So I split in 2 stages:
for bigStep in 0..<10 {
DispatchQueue.main.asyncAfter(deadline: .now() + Double(bigStep) * 10.0 ) {
for step in 0..<10 {
DispatchQueue.main.asyncAfter(deadline: .now() + Double(step) * 1.0) {
// simulation code
}
}
}
}
It works much better, as now there are a max of 20 threads active (in fact I create more levels to limit to a max of 8 concurrent threads).
It addition, it allows to interrupt the simulation before end.
My questions:
is it the appropriate pattern ?
Would a timer be better ?
Other options ?
This is a SwiftUI Mac App.
There is an observable object with a published array
class AllObjects : ObservableObject {
@Published var theItems = [Item]()
}
In the View, observed with:
@ObservedObject var allObjects : AllObjects
Item class is :
class Item: ObservableObject, Identifiable {
let id = UUID()
var placeNo = 1
// Other properties
}
When I switch dark / light mode within the app (with a toggle)
@Environment(\.colorScheme) var colorScheme
the ObservedObject allObjects is modified: array is emptied: allObjects.theItems is now an empty array.
What could cause the change to theItems ? I have checked that the only func un which theItems is reset to [] is not called.
Since a few days, I do not receive any mail notification on answers to mail. Is it only me ?
I notice that several (most) tags are not accessible now (Nov 2, 19:30 GMT). For instance
https://developer.apple.com/forums/tags/ios
https://developer.apple.com/forums/tags/uikit
https://developer.apple.com/forums/tags/macos
https://developer.apple.com/forums/tags/appkit
https://developer.apple.com/forums/tags/xcode
https://developer.apple.com/forums/tags/interface-builder
all with the same error: The page you’re looking for can’t be found
But others are:
https://developer.apple.com/forums/
https://developer.apple.com/forums/tags/swift
Is it only me ?