Post

Replies

Boosts

Views

Activity

Import DocC to Xcode
I'm trying to figure out how to build DocC from other frameworks to Xcode's Developer Documentation. I tried using the build documentation command, and it generates the DocC for my project and displays it in the Developer Documentation, but not libraries in the SPM. The code documentation does appear in the Developer Documentation, but the contents of the DocC are not shown.
2
0
627
Apr ’24
Set value to @State in init function
I want to pass a value to a property marked with @State, and it doesn't work. struct AView: View { @State private var content: String? var body: some View { Text(content ? "") } init(content: String) { self.content = content } } #Preview { AView(content: "Test") } But if I change the content to non optional, it works well. struct AView: View { @State private var content: String var body: some View { Text(content) } init(content: String) { self.content = content } } #Preview { AView(content: "Test") } I googled for a while and found that I need to use a spacial way to initialize @State property in the first case. init(content: String) { _content = State(initialValue: content) } It works, but why? Is there any difficulty to unified API between optional and non optional @State property?
0
0
316
Dec ’23
Can not create a View with generic inside an other View
I tried to create a View with generic inside an other View, and it works fine with build and run. But when I tried to review it, Xcode 15.1 showed an error. CompileDylibError: Failed to build AView.swift Compiling failed: cannot find 'SubListView' in scope struct AView: View { struct BView<T: DisplayData>: View { } } I need to move the BView out of AView to fix the issues. I think it is a preview bug as it works well on build and run.
1
0
300
Dec ’23
SwiftUI: Change the button color in hover
I want to use the default button style, and I know we can set the tint to change the background color of a button. But how can I change the color when user hover the button, in macOS or tvOS? The hover button color is still a white with a transparency even it shows other color when not in hover.
1
0
1.1k
Dec ’23
Compare @FocusState will trigger change of it's value
I found a weird problem when I use @FocusState. I need to compare the value of @FocusState and display different View. But I found that compare @FocusState will trigger a change of it's value. The code **** will display two list of buttons. When you select the 2 button in the first list, the right button will display. When I try to move to the right button, the focus will jump to the 1 button in the first list. The reason is focused was changed to 1 when I try to jump to the right button(the value of focused will be nil and then 1). And if I remove the compare code(if focused == 2), it will work fine. I am currently using Xcode beta 6. Not sure if it is a bug in beta version. struct Demo: View { @FocusState var focused: Int? var body: some View { HStack { List { ForEach((1...10), id: \.self) { number in Button { } label: { Text("\(number)") } .focused($focused, equals: number) } } List { if focused == 2 { Button { } label: { Text("Button") } } } } } }
0
0
424
Aug ’23
scrollClipDisabled not support Form
Apple introduced a new API scrollClipDisabled to disable clip in List. But it dose not work in Form. What should I do if I want to disable the clip action and show the shadow? Or maybe scrollClipDisabled should support Form too? NavigationStack { Form { Section { Picker("播放速度", selection: $playSpeed) { ForEach(speeds, id: \.self) { speed in Text(String(speed)) } } Picker("最高画质", selection: $mediaQuality) { ForEach(MediaQualityEnum.allCases, id: \.self) { speed in Text(speed.desp) } } Toggle("Hevc优先", isOn: $preferHevc) Toggle("无损音频和杜比全景声", isOn: $losslessAudio) } header: { Text("播放器") } } .scrollClipDisabled() // not work }
1
0
397
Aug ’23