Posts

Post not yet marked as solved
0 Replies
385 Views
If I run the exact same code on MacOS 12.7 (Xcode 14.2) and MacOS 15.0.1 (Xcode 15.0.1). In a scrollView, I display lines (lineDivider) and then a LazyVgrid, applying some offset: ScrollView(.vertical) { ForEach(1...50, id: \.self) { index in LabelledDivider(label: "\(index)", color: .gray.opacity(0.1)) .offset(y: CGFloat(65*index - 50) } LazyVGrid(columns: gridItemLayout, spacing: 33 ) { ForEach ($allItems.theItems) { $item in ItemView(item: item) } } .offset(y: 40) } In Xcode 14.2, I get the first layout and in Xcode 15.0 the second on right: The divider line is at the same position, but the view in grid is not. If I change .offset(y: 40) to .offset(y: 60) I get the same layout. So my questions: did anyone observe similar change ? is it due to Xcode, to MacOS ? Is it documented somewhere ?
Posted
by Claude31.
Last updated
.
Post marked as solved
12 Replies
1.5k Views
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.
Posted
by Claude31.
Last updated
.
Post not yet marked as solved
5 Replies
699 Views
Since a few hours, forum has an hectic behaviour: most often, returns "We'll be back." page or completely unformatted page or partially formatted even post page is a mess Is it a known problem or only on my side ?
Posted
by Claude31.
Last updated
.
Post marked as solved
1 Replies
501 Views
After more than 2 years of intense use of SwiftUI I appreciate many of its features, particularly the speed at which I can get some code running. But, there are some major buts … Screen Position, I keep struggling with try, test, error and retry to position views relative to each others, withy many iterations to tune the x and y parameters. And preview does not help when view is too complex: I find it more reliable to test in simulator. At the end, my code is messed with .position, .offset, … that I manually adjusted but may break if I change something elsewhere in the body. The fact that position is relative to center of view (different from UIKit) makes it even more mind boggling. For sure, UIKit constraints were not so easy, but you got a very stable code. That's not the case with SwiftUI z position In some cases, I want the View to appear on front of all others. It may be a very simple Rectangle() with overlay, e.g., to mimic an alert. And I struggle with the Rectangle drawn behind another view, even trying to adjust the zIndex to no avail… Should I create an explicit View instead of creating the Rectangle directly in the body ? So am I misusing SwiftUI, or are they points that SwiftUI should improve in the future ?
Posted
by Claude31.
Last updated
.
Post not yet marked as solved
0 Replies
558 Views
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 ?
Posted
by Claude31.
Last updated
.
Post marked as solved
9 Replies
2.6k Views
Here is the setup. I have an UIImageView in which I write some text, using UIGraphicsBeginImageContext. I pass this image to the OCR func: func ocrText(onImage: UIImage?) { let request = VNRecognizeTextRequest { request, error in guard let observations = request.results as? [VNRecognizedTextObservation] else { fatalError("Received invalid observations") } print("observations", observations.count) for observation in observations { if observation.topCandidates(1).isEmpty { continue } } } // end of request handler request.recognitionLanguages = ["fr"] let requests = [request] DispatchQueue.global(qos: .userInitiated).async { let ocrGroup = DispatchGroup() guard let img = onImage?.cgImage else { return } // Conversion to cgImage works OK                 print("img", img, img.width)                 let (_, _) = onImage!.logImageSizeInKB(scale: 1) ocrGroup.enter() let handler = VNImageRequestHandler(cgImage: img, options: [:]) try? handler.perform(requests) ocrGroup.leave() ocrGroup.wait() } } Problem is that observations is an empty array. I get the following logs: img <CGImage 0x7fa53b350b60> (DP) <<CGColorSpace 0x6000032f1e00> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)> width = 398, height = 164, bpc = 8, bpp = 32, row bytes = 1600 kCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little | kCGImagePixelFormatPacked is mask? No, has masking color? No, has soft mask? No, has matte? No, should interpolate? Yes 398 ImageSize(KB): 5 ko 2022-06-02 17:21:03.734258+0200 App[6949:2718734] Metal API Validation Enabled observations 0 Which shows image is loaded and converted correctly to cgImage. But no observations. Now, if I use the same func on a snapshot image of the text drawn on screen, it works correctly. Is there a difference between the image created by camera and image drawn in CGContext ? Here is how mainImageView!.image (used in ocr) is created in a subclass of UIImageView: override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { // Merge tempImageView into mainImageView UIGraphicsBeginImageContext(mainImageView!.frame.size) mainImageView!.image?.draw(in: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height), blendMode: .normal, alpha: 1.0) tempImageView!.image?.draw(in: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height), blendMode: .normal, alpha: opacity) mainImageView!.image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() tempImageView?.image = nil } I also draw the created image in a test UIImageView and get the correct image. Here are the logs for the drawn texte and from the capture: Drawing doesn't work img <CGImage 0x7fb96b81a030> (DP) <<CGColorSpace 0x600003322160> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)> width = 398, height = 164, bpc = 8, bpp = 32, row bytes = 1600 kCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little | kCGImagePixelFormatPacked is mask? No, has masking color? No, has soft mask? No, has matte? No, should interpolate? Yes 398 ImageSize(KB): 5 ko 2022-06-02 15:38:51.115476+0200 Numerare[5313:2653328] Metal API Validation Enabled observations 0 Screen shot : Works img <CGImage 0x7f97641720f0> (IP) <<CGColorSpace 0x60000394c960> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; iMac)> width = 570, height = 276, bpc = 8, bpp = 32, row bytes = 2280 kCGImageAlphaNoneSkipLast | 0 (default byte order) | kCGImagePixelFormatPacked is mask? No, has masking color? No, has soft mask? No, has matte? No, should interpolate? Yes 570 ImageSize(KB): 5 ko 2022-06-02 15:43:32.158701+0200 Numerare[5402:2657059] Metal API Validation Enabled 2022-06-02 15:43:33.122941+0200 Numerare[5402:2657057] [WARNING] Resource not found for 'fr_FR'. Character language model will be disabled during language correction. observations 1 Is there an issue with kCGColorSpaceModelRGB ?
Posted
by Claude31.
Last updated
.
Post not yet marked as solved
0 Replies
465 Views
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..&lt;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…
Posted
by Claude31.
Last updated
.
Post marked as solved
4 Replies
874 Views
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 ?
Posted
by Claude31.
Last updated
.
Post marked as solved
2 Replies
492 Views
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.
Posted
by Claude31.
Last updated
.
Post not yet marked as solved
0 Replies
966 Views
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 ?
Posted
by Claude31.
Last updated
.
Post not yet marked as solved
3 Replies
845 Views
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.
Posted
by Claude31.
Last updated
.
Post not yet marked as solved
13 Replies
2.9k Views
I propose that we collectively build a list of most wanted XCode features. Those pain points that do make our life more difficult with XCode or less fun.The goal would not be to have a scientifically correct ranking of all those, but simply:- make visible many ideas that have probably been reported in improvement requests- expose in short why that would be a great evolution, what pain point it would solve (functional improvements, not bugs correction)- if possible, discuss the feasibility of each idea.I would agree to update this original post to include new inputs.To avoid a thread where new posts get smaller and smaller in width, would be great to post each new idea as an answer to this original post. Of course discuss an idea as a reply to this idea post itself.Rule of the game would be tolerance, not trying to argue indefinitely on one idea. And be concise in wanted feature descriptionThe ultimate goal would be to influence positively XCode development team to consider the most wanted proposals.At least, have them explain us that one wanted feature in on the way (let's dream), why such idea is not so great, or why it would be too complex to implement…_________________________________Here is a first wanted feature, inspired from a thread in IB forum: https://forums.developer.apple.com/thread/72495Wanted Feature : Storyboard zoom when editing macOS appPain point: makes navigating in MacOS storyboard extremely painful if more than a few windows. Does limit the use of storyboards for MacOS App. The IB post was seen more than 7500 times, so that seems a largely shared concern.Feasibility: done for iOS, so should be possible for MacOS._________________________________Wanted Feature : Automatic/1-button icon, logo, screenshot, launch image generation for all project related devices/screens as mandated by ASC. Current with each new release.Pain point: The number of individually required image-based assets involved for meta data submittals became a burden long ago and continues to require significant labor to suss and satisfy.Feasibility: Xcode already does some of this w/launchStoryboards for new Swift projects, it just needs to be ubiquitous for all similar assets. It's just scripting/image resizing, which should not be a problem on macOS. Yes, I know there are 3rd party tools that help, but they seem to not keep up w/new devices/screen sizes - if they can do it, so can Xcode._________________________________Wanted Feature : More explicit help message when an action cannot be completed in IBPain point: When XCode cannot complete an action (e.g., create an IBOutlet for an IB object), option-cleaning the build folder solves the problem. Numerous issues reported on the forum were solved with this simple action. However, messages from IDE never mention this solution.Feasibility: Just adding (when appropriate) a suggestion in the message._________________________________Wanted Feature : When build fails, propose automatic correction action whenever possiblePain point: As an example, if some asset contains Finder information, a build error occurs, with message "resource fork, Finder information, or similar detritus not allowed Command /usr/bin/codesign failed with exit code 1". One has to go to Terminal, use xattr command and clean laboriously the offending files.Feasibility: As XCode has detected the files, it could propose to do the cleaning itself…- if it can be done with terminal command, so can Xcode._________________________________Wanted Feature : When an API is deprecated, get information on how to replace.Pain point: Most often, when an API is deprecated and we get a warning from compiler, we get no hint on how to replace. Thus, requiring to post on forum (a lot of posts relate to this search for information), search on web to find some hints… At the end losing time and not being sure to make the best decision.Feasibility: Those who deprecated API for sure know how to handle this. Should be (relatively) easy to provide information in doc, and in the deprecation message._________________________________Wanted Feature : When a string is missing for an infoPlist key, give a warning.Pain point: If the required key is missing, app will crash (or be rejected at Appstore verification stage which is a minor harm). I had the case where I called imagePicker, but intended to use only photo, not video. But if user taps on video, that caused a crash.Feasibility: When UIImagePickerControllerDelegate is used, compiler could check that infoPlist is defined for the required keys.._________________________________All comments welcomed.
Posted
by Claude31.
Last updated
.