Post

Replies

Boosts

Views

Activity

can't open documentation __update problem
I update my Xcode to the latest version today. After that, I can't access the developer documentation from the Xcode anymore. The error report says: Application Specific Information: Sending windowMenu_showDocumentation: to IDEDocCommandHandler from <NSMenuItem: 0x7f99fa73ee00 Developer Documentation> ProductBuildVersion: 12A7209 ASSERTION FAILURE in /Library/Caches/com.apple.xbs/Sources/IDEPlugins/IDEPlugins-17192/IDEDocViewer/DocumentationNavigator.swift:142 How can i solve the problem? Thanks in advance.
3
0
634
Sep ’20
live preview problem
I want to test the code below in live preview, but it seems not to work. In simulator, the button can change the text well, but not in live preview. How to fix it? Thanks in advance. import SwiftUI struct PreviewOnchangeTest: View {     @Binding var toggle: Bool     @State var text = "nice"     var body: some View {         VStack{         Text("\(text)")             .onChange(of: toggle, perform: { value in                 text = toggle.description             })         Button(action: {toggle.toggle()}, label: {             Text("change")         &#9;})         }     } } struct PreviewOnchangeTest_Previews: PreviewProvider {     @State static var toggle = true     static var previews: some View {         PreviewOnchangeTest(toggle: $toggle)     } }
1
0
1.2k
Jan ’21
How to explain the behavior of ".frame" when placed after ".offset"
According to the documentation of ".offset", The original dimensions of the view aren’t changed by offsetting the contents; in the example below the green border drawn by this view surrounds the original position of the text: Text("Hello, World!")             .border(Color.black)             .offset(x: 10.0, y: 50)             .border(Color.green) IMO, the modifer (ie,.border(Color.green))followed ".offset" should only affect the original view, but not the new view. When add a ".frame" right after the ".offset", I thought it also only affect the original view. However, the original and the new view are both affected. Text("Hello, World!")             .border(Color.black)             .offset(x: 10.0, y: 50)   &#9;&#9;.frame(width:50)             .border(Color.green) Further more, if I keep adding another ".frame" right after the first one, only the original view is affected again. Text("Hello, World!")             .border(Color.black)             .offset(x: 10.0, y: 50)             .frame(width:50)             .frame(width:100)             .border(Color.green) What happened under the hood? Thanks in advanced.
0
0
329
Feb ’21
large size image in swiftui
I want to demonstrate a large size image(5184*3456) in a modal sheet with swiftui. When I popup the sheet, memory usage increases from 20mb up to 100mb. However, when I dismiss the sheet, memory usage just decreases from 100mb to 92mb, wear and tear. I popup the sheet again, memory usage increases from 92mb back to 100mb. Back and forth, memory usage always changes between 92mb and 100mb, instead of between 20mb and 100mb that I expect to. Why doesn't memory usage decrease to 20mb when the sheet dismiss? Why doesn't image been purged from memory when the sheet dismisses? I just want memory usage stays in a low level. How could I do? Thanks in advance. struct IntroductionView: View {     @Environment(\EnvironmentValues.presentationMode) var presentation     var body: some View { GeometryReader{geo in            VStack(alignment:.leading){ Image("image") .resizable() .aspectRatio(contentMode: .fill) .frame(maxHeight:geo.size.height/4) .clipped()                 Spacer()                 Button(action: { presentation.wrappedValue.dismiss()                 }, label: {                     Text("Close")             }             }         } } }
0
0
987
Apr ’21
Read image from asset catalog
I drag a image.jpg into the assets.xcassets. And I want to read the jpg data in my code by "var imageData = NSDataAsset(name: "image")?.data" However, I get an error: "CoreUI: attempting to lookup a named data 'image' with a type that is not a data type in the AssetCatalog". And "imageData" is always nil. Do I make a mistake or miss sth? Thanks in advance.
5
0
9.8k
Apr ’21
Is there any way to set "ringer and alerts" sound in code?
I want to set "ringer and alerts" sound in code. MPVolumeView() seems like to control the system volume only. I have some sound effect(by invoking "AudioServicesPlaySystemSound(SystemSoundID:)") affected by "ringer and alerts" in my app. Even when the system volume is max, my app sound effect is still mute if "ringer and alerts" sound is mute. I have to tune "ringer and alerts" by "setting-sounds-ringer and alerts" manually. Is there any programable way to set it? Any help will be greatly appreciated.
0
0
634
Apr ’21
Protocol as return type
In swift language guide-"Opaque Types"-"Differences Between Opaque Types and Protocol Types", it said: "Another problem with this approach is that the shape transformations don’t nest. The result of flipping a triangle is a value of type Shape, and the protoFlip(:) function takes an argument of some type that conforms to the Shape protocol. However, a value of a protocol type doesn’t conform to that protocol; the value returned by protoFlip(:) doesn’t conform to Shape. This means code like protoFlip(protoFlip(smallTriange)) that applies multiple transformations is invalid because the flipped shape isn’t a valid argument to protoFlip(:)" I can't understand why it said"a value of a protocol type doesn’t conform to that protocol; the value returned by protoFlip(:) doesn’t conform to Shape". The return value must conform to Shape. It's a fundamental requirement by function signature, isn't it?
8
0
1.8k
May ’21
onTapGesture conflicts with button
I want to perform some code when the form is tapped. However the button in the form is affected by the onTapGesture either. I want the button tapped to execute the action block, not the onTapGesture block. How should I do? Thanks in advance. struct TextFieldPopupView: View {     @State private var text = ""     @State private var isON = false     var body: some View {         Form{             Text("Hello")             TextField("Hello", text: $text) .textFieldStyle(RoundedBorderTextFieldStyle())             Button(action: {                 print("Button")             }, label: {Text("Button")})             Toggle(isOn: $isON, label: {                 Text("Toggle")             })         }         .onTapGesture {             print("Form")         }     } }
2
1
6.2k
Jun ’21
A weird problem of LazyVGrid layout
I wrote some code using LazyVGrid. struct LazyVStackTestView: View {     let columnGridItem = Array(repeating: GridItem(), count: 3)     var body: some View {         GeometryReader{geo in             HStack{                 Rectangle().frame(maxWidth: 300,maxHeight: 100)                 LazyVGrid(columns: columnGridItem){                     ForEach(1..<13) { btn in                         Image(systemName: "plusminus.circle")                             .resizable()                             .scaledToFit()                             .clipShape(Circle())                     }                 }                 .padding()                 .frame(maxWidth: geo.size.height*0.6, maxHeight: geo.size.height)             }.border(Color.black)             .padding()         }.border(Color.blue)     } } When run it on simulator(iPhone 11) in horizontal orientation, I get a 4rows3columns button pad that is what I want. But when I turn the simulator to vertical orientation and back to horizontal orientation immediately, the button pad becomes 3rows3columns! What had happened? Any help will be appreciated.
2
0
2.8k
Jun ’21
What's the difference between InlinePickerStyle and WheelPickerStyle
struct PickerStyleView: View {     @State private var num  =  0     var body: some View {         Form{             Text("Number")             Picker(String(num), selection: $num, content: {                                  Text("5").tag(5)                 Text("10").tag(10)                 Text("15").tag(15)                 Text("20").tag(20)             })             .pickerStyle(InlinePickerStyle())         }     } } Using InlinePickerStyle() and WheelPickerStyle() seems to be no difference. What does "InlinePickerStyle()" refer to? And which case is "InlinePickerStyle()" suitable for in practice? Any help will be appreciated.
1
0
751
Sep ’21
"onTapGesture" interferes with segmented picker
struct ProblemSegmentTest: View {     @State private var select = 0     var body: some View {         VStack {             Picker("Test", selection: $select) {                 Text("A").tag(0)                 Text("B").tag(1)                 Text("C").tag(2)             }             .pickerStyle(SegmentedPickerStyle())         }         .onTapGesture {             print("test")         }     } } I want to do sth when the picker is taped. However, when I apply ".onTapGesture" to the vstack, the picker's options can't be selected any more. Any help will be appreciated.
5
1
1.8k
Sep ’21