In a SwiftUI project, I get the following runtime error:
2022-12-15 11:31:37.453318+0100 MyApp[7039:3585656] [SceneConfiguration] Info.plist contained no UIScene configuration dictionary (looking for configuration named "(no name)")
There are no scene in the project:
I have tried to change the settings,
To no avail.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
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:
I need to implement a remote control for a SwiftUI app running on iPad.
I would need to handle 2 different events like Start / Stop.
On software side, I plan to use .onReceive to listen to BLE device.
So my questions:
I need realtime reaction (a few 1/100 s max)
can any BLE remote control do the job ?
If anyone has tested some low cost remote, I am interested to know.
Or should I look for Homekit solutions ?
Or use an iPhone as remote controller ?
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 ?
I have encountered the following problem with a List.
The setup is as follows
@State private var allItems : [SomeItem]
@State private var selected : SomeItem?
// in the body
List(allItems, $selection) { theItem in …
}
where SomeItem is a struct.
When some properties of an item in allItems changes, the values that I read in theItem are not updated.
Just as if old content was cached.
I changed allItems to a computed var and everything works OK.
I read this SO thread https://stackoverflow.com/questions/74083515/swiftui-list-item-not-updated-if-model-is-wrapped-in-state
but that does not give a full explanation.
So my questions:
Is there effectively an issue here ?
when is it safe to use a State var as the Content of List ?
Is it OK (it seems) if the properties of items do not change ?
It seems also OK if the list of allItems is modified (appended, reduced) without problem changing the properties of its elements.
How to do if needed to change both allItems (append for instance) and change the properties of some items, as computed var cannot be modified.
Hope the question is clear.
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.
Last night we change hour for daylight saving time (at 2:00 it would be 3:00).
So I made a simple test to set an alarm at 2:10
At 1:59, clock jumped logically to 3:00
no alarm
At 3:10, alarm rang (in fact I had turned it off and back on, but that has no influence)
I set an alarm at 3:15, of course it rang
I set a new alarm at 2:20
It rang at 3:20
Conclusion: Clock app "replicates" the alarms between 2:00 and 2:59 into 3:00 - 3:59.
Which is great, not to miss any.
Question: Is this specific to Clock app or a more general system behaviour for all time events ?
If so, there may be a side effect:
I set an event A to turn On a light at 2:45
And set event B to turn it Off at 3:15
Then B will occur before A and the light will remain On
There is no perfect solution ("warping" 2:00 - 2:59 into a minute at 3:00 would creates other issues).
Extra question: What happens on winter time ? Will alarm ring twice at 2:10 ?
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.
I have declared an array as a State var
@State var proba : [Int] = [10, 40, 40, 10]
The array is updated in onAppear :
.onAppear {
proba = arrayOfTuples.map { (proba, _) in proba }
print("proba", proba)
}
The array is used for TextFields:
ForEach(0..<proba.count, id: \.self) { index in
TextField("N", value: $proba[index], format: .number)
.frame(width: 40)
.onChange(of: proba_kWh[index], perform: {[oldValue = proba_kWh[index]]
newValue in
print("proba onChange", index, oldValue, proba[index], newValue)
})
When View appears, I get some onChange (as initial values did change)
proba [10, 20, 60, 10] // onAppear changes 2 values: 1 and 2
proba onChange 2 40 60 60 // index 2 is changed before 1
proba onChange 1 40 20 20
I know that order of execution is not guaranteed, but in this specific case, I did thought it would be in the order of the array reading…
I have an app that runs eitheir as MacOS or iPadOS.
After a few changes to adapt to API differences (PasteBoard notably), app runs OK on both.
But the layout of views is messy when running on iPad.
Reason seems to be that Text are not using the same default font size, or that the same system font size does not use the same space. Same issue when using segmented picker for instance.
Configuration:
Xcode 14.2
MacOS 12.6.6
Simulator: iPad Pro (12.9") - iOS 16.2
Is it a correct analysis ?
Is there a simple workaround, to avoid the need to redesign all views for iPadOS ?