Post

Replies

Boosts

Views

Activity

Invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific
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())         }     } }
0
1
1.2k
Jan ’22
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.3k
Jun ’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.9k
Oct ’21
pencil kit issue--drawing can't stay on canvas
I want to use pencil kit in my swiftui app. I encapsulate PKCanvasView in UIViewRepresentable. I can draw on canvas with only one stroke. However, the image will disappear immediately when I release the finger. Am I missing anything? import SwiftUI import PencilKit struct ContentView: View { var body: some View { CanvasView() } } struct CanvasView: UIViewRepresentable { func makeUIView(context: Context) -> PKCanvasView { let canvas = PKCanvasView() canvas.tool = PKInkingTool(.pen, color: .green, width: 10) canvas.drawingPolicy = .anyInput return canvas } func updateUIView(_ uiView: PKCanvasView, context: Context) { } }
1
1
1.2k
Dec ’22
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.9k
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.9k
May ’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
783
Sep ’21
How to auto adjust the height of list row in edit mode?
I have a list. When I click the show button in any of rows, the long text appears and the height of row auto gets taller enough to show all of the long text. However, when the list is in "edit" mode, the height of row can't auto get taller enough to show all of the long text. The long text is truncated. I have to push the list to the top manually and release, then the height of row auto gets taller and the long text can be completely displayed again. Is there any way to achieve the "auto" adjustment effect just the same as the "non-edit" mode? struct ListEditTest: View { @State private var selects: Set<Int> = [] var body: some View { VStack{ EditButton() List(selection: $selects){ ForEach(1..<5){ ItemInList(num: $0) } } .listStyle(PlainListStyle()) } } } struct ItemInList: View{ let num: Int @State private var showDetail = false var body: some View{ HStack{ Text("NO.\(num)") Text("HelloWorld") if showDetail{ Text("TooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWords") Button { showDetail.toggle() } label: { Text("Hide") } }else{ Button { showDetail.toggle() } label: { Text("Show") } } } .buttonStyle(BorderlessButtonStyle()) } }
4
0
2.6k
Jun ’22
Reload images from PHPickerViewController
I'm writing an app which allow users to pick images from photo library by swiftUI. I wrap PHPickerViewController in representable to achieve the functionality. The benefit is that users don’t need to explicitly authorize my app to select photos. func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) Currently, I get images by picker(::) method above and save images in my app in order to reload images the next time users launch the app without needs to request authorization. Obviously, if the app stores references to the selected images, rather than images themselves, it can prevent from taking up large amounts of space. Is it meaning that I have to prompt to users for requesting authorization to access the library? Is there any approach only to use references and reload images which were selected by users previously from photo library using PHPickerViewController, supporting no need to request authorization.
1
0
1.6k
Nov ’22
how to make custom font to align in center of the frame
I need to use custom font in my app. While the built-in standard font will align in center automatically, the custom font seems to align "top"(seeing red border part) instead of "center"(blue border part). Is there any approach to fix it? struct ContentView: View { var body: some View { VStack(spacing: 20){ Text("SEPTEMBER") .font(.largeTitle) .border(.blue) Text("SEPTEMBER") .font(Font.custom("Arial Hebrew", size: 20)) .border(.red) } } }
2
0
1.3k
Mar ’23
legal font used in iOS app
[https://developer.apple.com/fonts/system-fonts/) shows dozens of system fonts. And it says "Apple platforms come with many preinstalled fonts that can be used by your app’s user interface. " on the top of the web page. Does it mean I can use any of them in my iOS app legally? Does it involve font license issue? What else should I pay attention to use system fonts legally?
1
0
861
Mar ’23
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
1k
Apr ’21
keyboard can't be popped up in live preview mode
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.
Replies
6
Boosts
0
Views
16k
Activity
Apr ’22
Invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific
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())         }     } }
Replies
0
Boosts
1
Views
1.2k
Activity
Jan ’22
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")         }     } }
Replies
2
Boosts
1
Views
6.3k
Activity
Jun ’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.
Replies
5
Boosts
1
Views
1.9k
Activity
Oct ’21
pencil kit issue--drawing can't stay on canvas
I want to use pencil kit in my swiftui app. I encapsulate PKCanvasView in UIViewRepresentable. I can draw on canvas with only one stroke. However, the image will disappear immediately when I release the finger. Am I missing anything? import SwiftUI import PencilKit struct ContentView: View { var body: some View { CanvasView() } } struct CanvasView: UIViewRepresentable { func makeUIView(context: Context) -> PKCanvasView { let canvas = PKCanvasView() canvas.tool = PKInkingTool(.pen, color: .green, width: 10) canvas.drawingPolicy = .anyInput return canvas } func updateUIView(_ uiView: PKCanvasView, context: Context) { } }
Replies
1
Boosts
1
Views
1.2k
Activity
Dec ’22
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.
Replies
5
Boosts
0
Views
9.9k
Activity
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?
Replies
8
Boosts
0
Views
1.9k
Activity
May ’21
some symbols in sf symbol 3 can't be displayed
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.
Replies
1
Boosts
0
Views
2.2k
Activity
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.
Replies
1
Boosts
0
Views
783
Activity
Sep ’21
How to auto adjust the height of list row in edit mode?
I have a list. When I click the show button in any of rows, the long text appears and the height of row auto gets taller enough to show all of the long text. However, when the list is in "edit" mode, the height of row can't auto get taller enough to show all of the long text. The long text is truncated. I have to push the list to the top manually and release, then the height of row auto gets taller and the long text can be completely displayed again. Is there any way to achieve the "auto" adjustment effect just the same as the "non-edit" mode? struct ListEditTest: View { @State private var selects: Set<Int> = [] var body: some View { VStack{ EditButton() List(selection: $selects){ ForEach(1..<5){ ItemInList(num: $0) } } .listStyle(PlainListStyle()) } } } struct ItemInList: View{ let num: Int @State private var showDetail = false var body: some View{ HStack{ Text("NO.\(num)") Text("HelloWorld") if showDetail{ Text("TooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWordsTooManyWords") Button { showDetail.toggle() } label: { Text("Hide") } }else{ Button { showDetail.toggle() } label: { Text("Show") } } } .buttonStyle(BorderlessButtonStyle()) } }
Replies
4
Boosts
0
Views
2.6k
Activity
Jun ’22
Reload images from PHPickerViewController
I'm writing an app which allow users to pick images from photo library by swiftUI. I wrap PHPickerViewController in representable to achieve the functionality. The benefit is that users don’t need to explicitly authorize my app to select photos. func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) Currently, I get images by picker(::) method above and save images in my app in order to reload images the next time users launch the app without needs to request authorization. Obviously, if the app stores references to the selected images, rather than images themselves, it can prevent from taking up large amounts of space. Is it meaning that I have to prompt to users for requesting authorization to access the library? Is there any approach only to use references and reload images which were selected by users previously from photo library using PHPickerViewController, supporting no need to request authorization.
Replies
1
Boosts
0
Views
1.6k
Activity
Nov ’22
how to detect major color in an image in iOS
I have a swiftui view that displays a picture which users select from Photo app and shows some texts below the picture. I want to dynamically tune the background color of the view depending on the picture major color. Say, if users select a grass or forest image, the background auto changes to green. Is there any best practice?
Replies
2
Boosts
0
Views
4.7k
Activity
Feb ’23
how to make custom font to align in center of the frame
I need to use custom font in my app. While the built-in standard font will align in center automatically, the custom font seems to align "top"(seeing red border part) instead of "center"(blue border part). Is there any approach to fix it? struct ContentView: View { var body: some View { VStack(spacing: 20){ Text("SEPTEMBER") .font(.largeTitle) .border(.blue) Text("SEPTEMBER") .font(Font.custom("Arial Hebrew", size: 20)) .border(.red) } } }
Replies
2
Boosts
0
Views
1.3k
Activity
Mar ’23
legal font used in iOS app
[https://developer.apple.com/fonts/system-fonts/) shows dozens of system fonts. And it says "Apple platforms come with many preinstalled fonts that can be used by your app’s user interface. " on the top of the web page. Does it mean I can use any of them in my iOS app legally? Does it involve font license issue? What else should I pay attention to use system fonts legally?
Replies
1
Boosts
0
Views
861
Activity
Mar ’23
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")             }             }         } } }
Replies
0
Boosts
0
Views
1k
Activity
Apr ’21