Posts

Post not yet marked as solved
0 Replies
416 Views
I have two lists side-by-side. I want to scroll any one of the lists, and the other one can scroll synchronously. Is there any way to achieve the effect? Any help will be appreciated. struct ScrollTwoListsSynchronously: View {     let dataSet = [1,2,3,4,5]     var body: some View {         HStack{             List{                 ForEach(dataSet,id:\.self){data in                     Text(String(data))                 }             }             .listStyle(PlainListStyle())             List{                 ForEach(dataSet,id:\.self){data in                     Text(String(data))                 }             }             .listStyle(PlainListStyle())         }     } }
Posted
by test1229.
Last updated
.
Post marked as solved
6 Replies
9.9k Views
In the simulator, everything is ok. However, in live preview mode of canvas, no keyboard pops up when I tap in the textfield. Did I miss anything? Or need more codes in preview?Thanks in advance.
Posted
by test1229.
Last updated
.
Post not yet marked as solved
0 Replies
995 Views
I make a toggle to control a textfield in a form. When I run it, I get a piece of warning: invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution What could I do to fix it? What's the harm if it's not fixed( App crashes, or...?). Any help will be appreciated. struct ContentView: View {     @State private var toggle1 = true     @State private var str1 = "..."     var body: some View {         Form{             Section{                 Toggle(isOn: $toggle1, label: {                     Text("Toggle 1")})             }             Section{                     if toggle1{                         HStack{                             Text("Toggle 1")                             TextField("...", text: $str1)                         }                     }             }             .textFieldStyle(RoundedBorderTextFieldStyle())         }     } }
Posted
by test1229.
Last updated
.
Post not yet marked as solved
0 Replies
1k Views
struct ContentView: View {     @State private var num = 0          var body: some View {         VStack{         Text(String(num))             .padding()         Button(action: {             num += 1         }, label: {Text("click+1")})         }     } } Question 1: If I run the code above on simulator, I could get the value of "num" on the console by using"po _num". However, if I run the code in previews(by "Debug-Attach to process"), I only get the error"error: :3:1: error: cannot find '_num' in scope" on the console by using"po _num" Xcode 13.2.1 Question 2: I could use "po num"/"po _num" to get the value of "num" with Xcode 12. BUT, only "po _num" works in Xcode13. "po num" will raise the error:" error: Couldn't lookup symbols: Preview2.ContentView.num.getter : Swift.Int" Any help will be appreciated.
Posted
by test1229.
Last updated
.
Post not yet marked as solved
1 Replies
1.2k Views
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.
Posted
by test1229.
Last updated
.
Post marked as solved
1 Replies
570 Views
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.
Posted
by test1229.
Last updated
.
Post marked as solved
1 Replies
1.9k Views
I downloaded sf symbol3 today. My Xcode is 12.5. When I write a simple code like: Image(systemName: "gearshape") everything is ok. However when the code turns to : Image(systemName: "gearshape.circle") nothing will be displayed. Do I miss anything? Thanks in advance.
Posted
by test1229.
Last updated
.
Post not yet marked as solved
0 Replies
569 Views
I have an app released in the iOS store which is set to be price tier 1. I want to set it to be free for just next week. After that, the price should be back to price tier1 again. If I tune it in App Store connect. Will it make my app to be in review again, or just take effect immediately? Thanks in advance.
Posted
by test1229.
Last updated
.
Post not yet marked as solved
0 Replies
2.2k Views
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.
Posted
by test1229.
Last updated
.
Post marked as solved
2 Replies
4.3k Views
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")         }     } }
Posted
by test1229.
Last updated
.
Post not yet marked as solved
0 Replies
352 Views
I know I can use .redacted(reason: .placeholder) to make displayed data appear as generic placeholders. But how can I declare a custom RedactionReasons instance and use it? The examples of initializer in documentation seem not to be helpful. Thanks in advance.
Posted
by test1229.
Last updated
.
Post marked as solved
8 Replies
1.3k Views
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?
Posted
by test1229.
Last updated
.
Post not yet marked as solved
0 Replies
554 Views
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.
Posted
by test1229.
Last updated
.
Post marked as solved
5 Replies
7k Views
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.
Posted
by test1229.
Last updated
.
Post not yet marked as solved
0 Replies
817 Views
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")             }             }         } } }
Posted
by test1229.
Last updated
.