Post

Replies

Boosts

Views

Activity

`import Collections` does make no sense errors.
I downloaded package, I can see it in Package Dependencies tab, [swift-collections | https://github.com/apple/swift-collections.git | Up to Next Major Version] — looks OK. But (quite strange): import Collections //🛑 No such module 'Collections' typealias Objects = OrderedSet<anyHashable> // No error I took Collection word from a list or typed — no difference. if I remove import Collections there is no OrderedSet anymore (of course) Can't compile. Cleaned build folder, restarted Xcode... What could be wrong with it? Any ideas?
1
0
16
5d
Need a progress bar during init a document
I have no idea how to do it: on MacOS, in Document.init(configuration: ReadConfiguration) I decode file, and restore objects from data, which in some cases could take a long time. Document isn't fully inited, so I have no access to it. But would like to have a progress bar on screen (easier to wait for done, for now). I know size, progress value, but no idea how to make view from object during init. I know, this question may be very stupid. init(configuration: ReadConfiguration) throws { guard let data = configuration.file.regularFileContents else { throw CocoaError(.fileReadCorruptFile) } let decoder = JSONDecoder() let flat = try decoder.decode(FlatDoc.self, from: data) print ("reverting \(flat.objects.count) objects...") ///This takes time, a lot of time, need progress bar ///Total is `flat.objects.count`, current is `objects.count` /// `Show me a way to the (next) progress bar!` revertObjects(from: flat.objects) print ("...done") } update: I defined var flatObjects in Document, and I can convert in .onAppear. struct TestApp: App { @State var isLoading = false ... ContentView(document: file.$document) .onAppear { isLoading = true Task {file.document.revertObjects()} isLoading = false } if isLoading { ProgressView() } ... } But progress bar never shows, only rainbow ball
Topic: UI Frameworks SubTopic: SwiftUI Tags:
0
0
111
2w
SwiftUI .fileImporter does not react to isPresented change.
I made a ImagePicker which worked pretty well. But when app get bigger it stops. Does not react to change isPresented value. As far I know I changed nothing around this part of an App. Also same thing happened in different place, another kind of picker. print ("HELL'o") never prints. Silence. struct ImagePicker: View { @Binding var imageSource: ImageSource @State var showFileImporter: Bool = false @EnvironmentObject var manager: Manager var body: some View { VStack { .... Button(action: { print("before", showFileImporter) showFileImporter = true print("after", showFileImporter) }, label: { Text("open Image") }) .buttonStyle(.borderless) .controlSize(.mini) }.fileImporter(isPresented: $showFileImporter, allowedContentTypes: [.png, .jpeg, .tiff], onCompletion: { result in print ("HELL'o") // Never prints switch result { case let .success(url): guard let _ = try? Data(contentsOf: url) else { return } .... case let .failure(error): print(error) } }) } } Does anybody have an idea what happened? I suspect some settings in completely different palce or bug or computer does not like me.
0
0
336
Dec ’24
Mixing a lot of shaders.
Project: I have some data wich could be transformed by shader, result may be kept in rgb channels of image. Great. But now to mix dozens of those results? Not one by one, image after image, but all at once. Something like „complicated average” color of particular pixel from all delivered images. Is it possible?
1
0
672
Dec ’24
Most idiotic problem with assign value to value?
Why assigning function.formula = formula does not change function.formula to formula in one go? It's always late one change behind. struct CustomFunction has defined .formula as @MainActor. I feel stupid. There is a part of code: struct CustomFormulaView: View { @Binding var function: CustomFunction @State var testFormula: String = "" @EnvironmentObject var manager: Manager .... .onChange(of: testFormula) { debugPrint("change of test formula: \(testFormula)") switch function.checkFormula(testFormula, on: manager.finalSize) { case .success(let formula): debugPrint("before Change: \(function.formula)") function.formula = formula // Nothing happens debugPrint("Test formula changed: \(testFormula)") debugPrint("set to success: \(formula)") debugPrint("what inside function? \(function.formula)") Task { //Generate Image testImage = await function.image( size: testImageSize), simulate: manager.finalSize) debugPrint("test image updated for: \(function.formula)") } .... and it produces this output when changed from 0.5 to 1.0 Debug: change of test formula: 1.0 Debug: before Change: 0.5 Debug: Test formula changed: 1.0 Debug: set to success: 1.0 Debug: what inside function? 0.5 Debug: test image updated for: 0.5 0.5 is an old value, function.formula should be 1.0 WT??
3
0
422
Nov ’24
How to break `while` loop and `deliver partial result to `View`?
I make some small program to make dots. Many of them. I have a Generator which generates dots in a loop: //reprat until all dots in frame while !newDots.isEmpty { virginDots = [] for newDot in newDots { autoreleasepool{ virginDots.append( contentsOf: newDot.addDots(in: size, allDots: &result, inSomeWay)) } newDots = virginDots } counter += 1 print ("\(result.count) dots in \(counter) grnerations") } Sometimes this loop needs hours/days to finish (depend of inSomeWay settings), so it would be very nice to send partial result to a View, and/or if result is not satisfying — break this loop and start over. My understanding of Tasks and Concurrency became worse each time I try to understand it, maybe it's my age, maybe language barier. For now, Button with {Task {...}} action doesn't removed Rainbow Wheel from my screen. Killing an app is wrong because killing is wrong. How to deal with it?
4
0
458
Nov ’24
Does some restriction exist in SwiftUI for binding computed values?
I have a view, and in this view I bind Axis class values — lowerBound which is a regular property and at – computed one which comes from protocol HasPositionProtocol associated with Axis. struct AxisPropertiesView<Axis>: View where Axis: StyledAxisProtocol, Axis: HasPositionProtocol, Axis: Observable { @Bindable var axis: Axis var body: some View { HStack { TextField("", text: $axis.shortName) .frame(width: 40) TextField("", value: $axis.lowerBound, format: .number) .frame(width: 45) //Problem is here: Slider(value: $axis.at, in: axis.bounds) ... Unfortunately I got en error Failed to produce diagnostic for expression; ... for whole View. But if I remove Slider from View, error disappeared. What could cause this strange behaviour? Value of .at comes from: public extension HasPositionProtocol { ///Absolut position on Axis var at: Double { get { switch position { case .max: return bounds.upperBound case .min: return bounds.lowerBound case .number(let number): return number } } set { switch newValue { case bounds.lowerBound: position = .min case bounds.upperBound: position = .max default: position = .number(newValue) } } } }
1
0
406
Nov ’24
Is it possible to generate nice PDF with gradient from SwiftUI view ?
I try to generate PDF from view. View is nice, there is a lot of transparency and many gradients (circular and linear). But if I use ImageRenderer in in a way that documentation suggest all transparency and gradients disappear. Is this bug or some feature? Is it way to generate vector graphic from view with transparency and gradients? PDF allows those features, so why not?
2
0
657
Nov ’24
How to align content of SwiftuUI ScrollView to top? (MacOS)
I have a ZStack view embedded in ScrollView. The height of ZStack often changes. var body: some View { ScrollView([.vertical, .horizontal], showsIndicators: true) {             VStack { // embedding in VStack doesn't change behaviour                 ZStack () {                     ForEach(mapElements.indices, id:\.self) { i in                         let element = mapElements[i]                         MapElementView (mapElement: element)                         .position(x: offset(x: element.x),                                   y: offset(y: element.y))                         .zIndex(5)                         MakeConnections(mapElement: element)                     }                 }.frame(width: calculateWidth(),                         height: calculateHeight())                 }                 Rectangle() // Just to make VStack filled             }         }.frame(alignment: .topLeading) } Some scroll views (ie. list) always align embedded objects to top even they are shorter than embedding scroll view. But in this case ZStack is always centred when view is refreshed. Is it possible to define behaviour, so each change of a content will align its top to scroll view top, even if height of ZStack is smaller than ScrollView?
3
0
5.0k
Jun ’23
Unable to get CGRect.null and CGPoint in Package after upgrading to Xcode 14.1
I have a MacOS package dependency which defines some class: FontPens import Foundation ... public class BoundsPen: Pen { var bounds = CGRect.null private var currentPoint = CGPoint.zero .... After upgrading Xcode to 14.1 both lines throws errors Type 'CGRect' has no member 'null' and Type 'CGPoint' has no member 'zero'. Calling CGPoint.zero and CGRect.null from an app is OK if Foundation is imported. Is it a way to solve this problem without changing package source?
1
1
1.2k
Nov ’22
How to move focus to view which is not TextField
I have a MacOS app which has a lot of TextFields in many views; and one editor view which has to receive pressed keyboard shortcut, when cursor is above. But as I try, I cannot focus on a view which is not text enabled. I made a small app to show a problem: @main struct TestFocusApp: App { var body: some Scene { DocumentGroup(newDocument: TestFocusDocument()) { file in ContentView(document: file.$document) } .commands { CommandGroup(replacing: CommandGroupPlacement.textEditing) { Button("Delete") { deleteSelectedObject.send() } .keyboardShortcut(.delete, modifiers: []) } } } } let deleteSelectedObject = PassthroughSubject<Void, Never>() struct MysticView: View { var body: some View { ZStack { Rectangle() .foregroundColor(.gray.opacity(0.3)) }.focusable() .onReceive(deleteSelectedObject) { _ in print ("received") } } } enum FocusableField { case wordTwo case view case editor case wordOne } struct ContentView: View { @Binding var document: TestFocusDocument @State var wordOne: String = "" @State var wordTwo: String = "" @FocusState var focus: FocusableField? var body: some View { VStack { TextField("one", text: $wordOne) .focused($focus, equals: .wordOne) TextEditor(text: $document.text) .focused($focus, equals: .editor) ///I want to receive DELETE in any way, in a MystickView or unfocus All another text views in App to not delete their contents MysticView() .focusable(true) .focused($focus, equals: .view) .onHover { inside in focus = inside ? .view : nil /// focus became ALWAYS nil, even set to `.view` here } .onTapGesture { focus = .view } TextField("two", text: $wordTwo) .focused($focus, equals: .wordTwo) } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView(document: .constant(TestFocusDocument())) } } Only first TextField became focused when I click or hover over MysticView I can assign nil to focus, but it will not unfocus fields from outside this one view. Is it a bug, or I missed something? How to make View focusable? To Unfocus all textFields?
0
0
840
Nov ’22
Is it possible to disable Core Animation in SwiftUI?
I build a graphic editor. Dragging points through my canvas is smooth and fast. But when I try to display data in outline view everything slows down to 2 FPS. First I suspected slow data access, but when I check app in Instruments I found Core Animation Commits are displayed as a red blocks and Time Profiler bit busy. Is a way to disable Core Animation for some views? Or this message is misleading?
1
0
2.1k
Jun ’22
Is it possible to set default height proportions of embedded views in VSplitView (MacOS)
I have a VSplitView with two views inside. But each time app starts proportions are set to 50/50, each one has the same height. I would like to set height of one of them to some number, (and save it in defaults... not most important thing). Of course I would like to change this height manually if I need to.     var body: some View {         return VSplitView { HigherView(with: someContent) // Let it be float height ShorterView(with: anotheContent) // let it height will be 300 when fired first time } } Is it very hard?
1
0
692
Jun ’22
SwiftUI App has disabled keyboard shortcuts on MacOS.
As in a title: even empty new app has menu with working menu items, but with disabled and not working keyboard shortcuts. Is it bug, feature or I should do something to enable them? Minimize, Zoom... works. My Edit Menu have the same problem: Commands Undo, Redo and Delete works when chosen from menu, but calling them via keyboard causes only cursor disappear.
1
0
1.2k
Jan ’22