Post

Replies

Boosts

Views

Activity

ViewBuilder does not force View update
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 ?
2
0
929
Jan ’23
Design pattern for scheduling simulation steps
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 ?
4
0
1.2k
May ’23
Dark mode switching modifies ObservedObject
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.
2
0
705
Apr ’23
Several tags are inaccessible on the forum
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 ?
4
0
1k
Nov ’23
Swiping Watch faces always display 10:09 before exact time
I know it is not a developer question, but getting the answer may help understand what we can get or not get on Apple Watch after Watch10. Since WatchOS10.2 when swiping face, time is always displayed first as 10:09:31 before setting the correct time one second later. Just in the same way as a long press. But the interest of swipe is to have immediately a different face displaying the correct time. Why is it so ? Is it due to (probably) now using SwiftUI ? Or is it a quick fix, reusing most of code for Lon,g press case ? It did not behave so with WatchOS 9 or before. Is there a setting to change ? It is really inconvenient (and ugly). I filed a bug report: FB13466486
1
0
1.3k
Jan ’24
AppstoreConnect does not show units and sales of last days
Today, on Dec 14, when I look for units or sales, all that occurred after December 3rd is ignored. Tens were downloaded since dec 3rd, and I could see them when connecting earlier today. When I want to set the time period, I see that any date beyond Dec 3rd is greyed (see attached screenshot). It used to work a few hours ago. This occurred immediately after updating MacOS to 14.2, but I tested on a Mac running 12.6 with the same result. Is it only me or does anyone see the same issue ? I filed a bug report: FB13468285
10
0
2k
Mar ’24
Why does the superview of a UITableViewController turns nil after unwindSegue ?
Here is the set up. I have a UITableViewController (controller 1), to which I get from a controller (0) As I need to add a searchView atop the tableView, I addSubview to the superview. This is done in viewWillAppear self.view.superview?.addSubview(searchView) // AboveTableView searchView.isHidden = true print("willAppear", self.view.superview, self.tableView.superview) It works perfectly well, I get: willAppear Optional(<UIViewControllerWrapperView: 0x103d2eef0; frame = (0 0; 393 852); autoresize = W+H; layer = <CALayer: From this VC, I segue to another VC (2) with a show segue and comes back with an unwindSegue to return to (1). Problem is that no, superviews are nil. @IBAction func unwindToTableViewController(_ sender: UIStoryboardSegue) { print("unwind", self.view.superview, self.tableView.superview) } gives unwind nil nil If I step back from this controller (1) to the controller (0) from which I segued and segue again to the TableViewController (1), everything works as expected. In addition, if I go from 1 -> 2 by instantiating (2), everything works OK when I unwind to (1). I know a solution is to refactor code replacing UITableViewController with a UIViewController and embed a TableView inside. But I would like to understand why my present design does not work.
3
0
1.2k
Dec ’23
View appears transparent over tableView, whatever alpha channel
I have a view in storyboard, with a tableView and a coloured UIView. The UIView is declared after tableView, so it appears on top of tableView. However, it appears semi transparent over the tableView. In addition, I cannot set its alpha channel to values other than 1 or 0 (e.g., 0.9) But if I create the view programmatically, the view if fully opaque as expected. What am I missing ?
1
0
1.1k
Jun ’24
Forcing screen orientation for a VC
This is an often asked question, but I just have a partial answer so far. There are some views (not all) that I need to present in Portrait only when running on iPhone. If I come from a TabBar, I just add the following code in the TabBar controller override open var supportedInterfaceOrientations : UIInterfaceOrientationMask { if UIDevice.current.userInterfaceIdiom == .phone { return [.portrait, .portraitUpsideDown] } } But I need to do the same when I get to the destination VC by a segue fired from a plain UIViewController or a Cell in a TableView. If I put the code in the destination controller, it has no effect. If I put in the originating VC, it works when segue is triggered from code (case 2 below). But I cannot make it work when segue is triggered in storyboard from the accessory action in the cell of the TableView. Where should I declare the supportedInterfaceOrientations ? Should I do it in the navigation root ? If so, how ? I tried in an extension UINavigationController, to no avail. or should I trigger the segue from accessory, not directly in storyboard but through an IBAction in code ? If that may help, an overview of storyboard setup: Also tried solution described here to no avail either: https://www.appsdeveloperblog.com/disable-rotation-of-uiviewcontroller-embedded-into-uinavigationcontroller/
1
0
895
Jan ’24
Using Color() in background modifier in SwiftUI does not work with Xcode 15.3
I had this code working properly in Xcode 17.0.1, with macOS target as 12.4 struct SyntheseView: View { @AppStorage("isDarkMode") var isDarkMode = false // more declarations ……… var body: some View { VStack { ZStack { // code ………………… } .frame(width: 500, height: 300) .background(isDarkMode ? Color(red: 0, green: 0, blue: 120/255) : Color(red: 1, green: 1, blue: 186/255)) } // VStack In Xcode 15.3, I get the error The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions If I comment out the background modifier, no issue. I converted all parameters in Color to Double without success If I replace by a fixed color as .background(.blue) No error. Even the simple .background(Color(red: 0.0, green: 0.0, blue: 0.5)) causes the error. But: .background(isDarkMode ? .blue : .red) does work. I tried to define the Colors as static color extensions to no avail. Another bizarre point is that a similar pattern works OK for another View. Did something change in Xcode 17.3 ?
1
0
1.1k
Mar ’24
ViewBuilder does not force View update
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 ?
Replies
2
Boosts
0
Views
929
Activity
Jan ’23
Show / Hide navigation links at top of window
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.
Replies
1
Boosts
0
Views
768
Activity
Feb ’23
Question of curiosity: why different fonts in different forum sections ?
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
Replies
8
Boosts
0
Views
1.5k
Activity
Feb ’23
Forum editor bug since last maintenance
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.
Replies
12
Boosts
0
Views
2.2k
Activity
Oct ’23
Impossible to reply to some thread even not marked locked
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 ?
Replies
8
Boosts
0
Views
1.5k
Activity
Apr ’23
Design pattern for scheduling simulation steps
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 ?
Replies
4
Boosts
0
Views
1.2k
Activity
May ’23
Dark mode switching modifies ObservedObject
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.
Replies
2
Boosts
0
Views
705
Activity
Apr ’23
No email notifications since a few days
Since a few days, I do not receive any mail notification on answers to mail. Is it only me ?
Replies
6
Boosts
0
Views
1.1k
Activity
Oct ’23
Several tags are inaccessible on the forum
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 ?
Replies
4
Boosts
0
Views
1k
Activity
Nov ’23
Swiping Watch faces always display 10:09 before exact time
I know it is not a developer question, but getting the answer may help understand what we can get or not get on Apple Watch after Watch10. Since WatchOS10.2 when swiping face, time is always displayed first as 10:09:31 before setting the correct time one second later. Just in the same way as a long press. But the interest of swipe is to have immediately a different face displaying the correct time. Why is it so ? Is it due to (probably) now using SwiftUI ? Or is it a quick fix, reusing most of code for Lon,g press case ? It did not behave so with WatchOS 9 or before. Is there a setting to change ? It is really inconvenient (and ugly). I filed a bug report: FB13466486
Replies
1
Boosts
0
Views
1.3k
Activity
Jan ’24
AppstoreConnect does not show units and sales of last days
Today, on Dec 14, when I look for units or sales, all that occurred after December 3rd is ignored. Tens were downloaded since dec 3rd, and I could see them when connecting earlier today. When I want to set the time period, I see that any date beyond Dec 3rd is greyed (see attached screenshot). It used to work a few hours ago. This occurred immediately after updating MacOS to 14.2, but I tested on a Mac running 12.6 with the same result. Is it only me or does anyone see the same issue ? I filed a bug report: FB13468285
Replies
10
Boosts
0
Views
2k
Activity
Mar ’24
Why does the superview of a UITableViewController turns nil after unwindSegue ?
Here is the set up. I have a UITableViewController (controller 1), to which I get from a controller (0) As I need to add a searchView atop the tableView, I addSubview to the superview. This is done in viewWillAppear self.view.superview?.addSubview(searchView) // AboveTableView searchView.isHidden = true print("willAppear", self.view.superview, self.tableView.superview) It works perfectly well, I get: willAppear Optional(<UIViewControllerWrapperView: 0x103d2eef0; frame = (0 0; 393 852); autoresize = W+H; layer = <CALayer: From this VC, I segue to another VC (2) with a show segue and comes back with an unwindSegue to return to (1). Problem is that no, superviews are nil. @IBAction func unwindToTableViewController(_ sender: UIStoryboardSegue) { print("unwind", self.view.superview, self.tableView.superview) } gives unwind nil nil If I step back from this controller (1) to the controller (0) from which I segued and segue again to the TableViewController (1), everything works as expected. In addition, if I go from 1 -> 2 by instantiating (2), everything works OK when I unwind to (1). I know a solution is to refactor code replacing UITableViewController with a UIViewController and embed a TableView inside. But I would like to understand why my present design does not work.
Replies
3
Boosts
0
Views
1.2k
Activity
Dec ’23
View appears transparent over tableView, whatever alpha channel
I have a view in storyboard, with a tableView and a coloured UIView. The UIView is declared after tableView, so it appears on top of tableView. However, it appears semi transparent over the tableView. In addition, I cannot set its alpha channel to values other than 1 or 0 (e.g., 0.9) But if I create the view programmatically, the view if fully opaque as expected. What am I missing ?
Replies
1
Boosts
0
Views
1.1k
Activity
Jun ’24
Forcing screen orientation for a VC
This is an often asked question, but I just have a partial answer so far. There are some views (not all) that I need to present in Portrait only when running on iPhone. If I come from a TabBar, I just add the following code in the TabBar controller override open var supportedInterfaceOrientations : UIInterfaceOrientationMask { if UIDevice.current.userInterfaceIdiom == .phone { return [.portrait, .portraitUpsideDown] } } But I need to do the same when I get to the destination VC by a segue fired from a plain UIViewController or a Cell in a TableView. If I put the code in the destination controller, it has no effect. If I put in the originating VC, it works when segue is triggered from code (case 2 below). But I cannot make it work when segue is triggered in storyboard from the accessory action in the cell of the TableView. Where should I declare the supportedInterfaceOrientations ? Should I do it in the navigation root ? If so, how ? I tried in an extension UINavigationController, to no avail. or should I trigger the segue from accessory, not directly in storyboard but through an IBAction in code ? If that may help, an overview of storyboard setup: Also tried solution described here to no avail either: https://www.appsdeveloperblog.com/disable-rotation-of-uiviewcontroller-embedded-into-uinavigationcontroller/
Replies
1
Boosts
0
Views
895
Activity
Jan ’24
Using Color() in background modifier in SwiftUI does not work with Xcode 15.3
I had this code working properly in Xcode 17.0.1, with macOS target as 12.4 struct SyntheseView: View { @AppStorage("isDarkMode") var isDarkMode = false // more declarations ……… var body: some View { VStack { ZStack { // code ………………… } .frame(width: 500, height: 300) .background(isDarkMode ? Color(red: 0, green: 0, blue: 120/255) : Color(red: 1, green: 1, blue: 186/255)) } // VStack In Xcode 15.3, I get the error The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions If I comment out the background modifier, no issue. I converted all parameters in Color to Double without success If I replace by a fixed color as .background(.blue) No error. Even the simple .background(Color(red: 0.0, green: 0.0, blue: 0.5)) causes the error. But: .background(isDarkMode ? .blue : .red) does work. I tried to define the Colors as static color extensions to no avail. Another bizarre point is that a similar pattern works OK for another View. Did something change in Xcode 17.3 ?
Replies
1
Boosts
0
Views
1.1k
Activity
Mar ’24