Post

Replies

Boosts

Views

Activity

Reply to How to get the position of dominant colors in CGImage?
An idea for a more basic solution: split each color axis (0 to 255) in segments with width of 4: 0-3; 4-7; 8-11 … You will have 64 segments. Then you create an array to count how many pixels in each of the 64 * 64 * 64 = 262144 items (if you split by 8, you can reduce to 323232 = 32768 var theCube : [Int] = Array(repeating: 0, count: 646464) a function to compute the position of a color in the array: func colorIndex(for color: UIColor) -> Int { // we return 64*64*r/4 + 64*g/4 + b/4, with r, g, b between 0 and 255 var index = 0 if let components = color.cgColor.components { if components.count < 3 { // We are grayscale, r, g, b will be equal let grayValue = Int(255*components[0] / 4) // We bring grayValue between 0 and 63 index = (64*64 + 64 + 1) * grayValue } else { // components are between 0 and 1, convert to 0...255 first index = 64*64*Int(255*components[0] / 4) index = index + 64 * Int(255*components[1] / 4) index = index + Int(255*components[2] / 4) } } return index } test: print(colorIndex(for: UIColor.red)) // 258048 print(colorIndex(for: UIColor.green)) // 4032 print(colorIndex(for: UIColor.blue)) // 63 print(colorIndex(for: UIColor.white)) // 262143 last item in cube print(colorIndex(for: UIColor.black)) // 0 first item in cube you then test for each pixel, computing the colorIndex and increment the cube[index] accordingly max value in the array is the dominant color: its index is dominantColorIndex. Once you have defined this dominant color search for points which color fall in this max, by computing its colorIndex and find if equal to dominantColorIndex Hope that helps.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’24
Reply to Broken Xcode
Your version of Xcode is so old (we are now 15.4) and MacOS 14, that it is not surprising that you get problems. Even rdar is no more accessible. Can't you really update MacOS to a more recent version and Xcode to a version supported by this OS version ?
Apr ’24
Reply to How to I move the sectorMark annotation to the outside perimeter of the pie chart?
The way I achieved it is by computing a position for the annotation. Here is the sample code for you to improve… struct ContentView: View { struct PieData: Identifiable { let id = UUID() let category: String let categoryPercentage: Int var angle = 0.0 // Will be computed onAppear var color: Color } @State private var pieData: [PieData] = [ .init(category: "A", categoryPercentage: 10, color: .blue), .init(category: "B", categoryPercentage: 68, color: .green), .init(category: "C", categoryPercentage: 20, color: .orange), .init(category: "D", categoryPercentage: 38, color: .brown), .init(category: "E", categoryPercentage: 98, color: .red), .init(category: "F", categoryPercentage: 58, color: .cyan), .init(category: "G", categoryPercentage: 77, color: .yellow) ] var angles: [Double] { var computedAngles = [Double]() var midSectorAngle = 0.0 let total = pieData.reduce(0, { $0 + $1.categoryPercentage }) // needed to compute angles var partialTotal = 0 for data in pieData { midSectorAngle = Double(partialTotal) + Double(data.categoryPercentage) / 2 midSectorAngle *= 2 * Double.pi / Double(total) computedAngles.append(midSectorAngle) partialTotal += data.categoryPercentage } return computedAngles } var body: some View { GeometryReader { geometry in Chart(pieData) { data in SectorMark(angle: .value("Pie Chart", data.categoryPercentage), angularInset: 1.7) .foregroundStyle(by: .value("Category", data.category)) .cornerRadius (5) .annotation (position: .overlay) { Text("\(data.categoryPercentage)%") .bold() .position(x: 145+75*sin(data.angle), y: 140-75*cos(data.angle)) } // .offset(x: 200, y: 20) // If here it would rotate sectors ! } .frame(width: 300, height: 300) .position(x: 200, y: 400) .onAppear { for index in 0..<pieData.count { pieData[index].angle = angles[index] } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’24
Reply to The content regarding app forced termination in the Apple guidelines
There is only one reference to termination in the guidelines: 2.3.1 (a)ASR & NR Don’t include any hidden, dormant, or undocumented features in your app; your app’s functionality should be clear to end users and App Review. All new features, functionality, and product changes must be described with specificity in the Notes for Review section of App Store Connect (generic descriptions will be rejected) and accessible for review. Similarly, marketing your app in a misleading way, such as by promoting content or services that it does not actually offer (e.g. iOS-based virus and malware scanners) or promoting a false price, whether within or outside of the App Store, is grounds for removal of your app from the App Store or a block from installing via alternative distribution and termination of your developer account.
Apr ’24
Reply to Developing for just myself
Welcome to the forum. You can use full fledged Xcode for free and load the app you develop on your devices and of course test on simulators. That's the free account. Really great to get started. Limits: no publishing on AppStore (I understand you don't care) you will have to rebuild and reload the app on devices frequently (I think once a week). But's that not a big issue. Good start and enjoy.
Apr ’24
Reply to TextField with Double clear button / currency format for string value
I may have a solution to propose. It is a bit circumvolved, but seems to do the job. Idea is to have 2 TextFields that overlap, and select which one is tab the front in a ZStack (with zIndex), and change focus as needed. I have set coloured background so that you can track what's happening and also hide the overlapped field. struct ContentView: View { @State private var checkAmount : Double = 0.0 @State private var valueToEnter = true @FocusState private var checkAmountIsFocused: Bool @FocusState private var checkAmount2IsFocused: Bool var totalPerPerson: Double { // calculations including (Double(checkAmount) ?? 0) return 0.0 } private let quantityFormatter: NumberFormatter = { let formatter = NumberFormatter() formatter.locale = Locale.current formatter.numberStyle = .decimal formatter.minimumFractionDigits = 2 formatter.maximumFractionDigits = 2 formatter.zeroSymbol = "" return formatter }() var body: some View { NavigationStack { Form { Section("Check amount") { ZStack { TextField("Enter check amount", value: $checkAmount, format: .currency(code: Locale.current.currency?.identifier ?? "USD")) .keyboardType(.decimalPad) .focused($checkAmountIsFocused) .onTapGesture { // onTap, we shall change focus valueToEnter = false // That puts this field behind and the "yellow" at the front checkAmount = 0 // quantityFormatter will not display any content in the yellow field checkAmountIsFocused = false checkAmount2IsFocused = true } .background(.green) // replace by Color(UIColor.systemBackground) .zIndex(valueToEnter ? 1 : 0) TextField("", value: $checkAmount, formatter: quantityFormatter) .keyboardType(.decimalPad) .focused($checkAmount2IsFocused) .onSubmit { valueToEnter = true // That puts this field behind and the "green" at the front checkAmountIsFocused = true checkAmount2IsFocused = false } .background(.yellow) // replace by Color(UIColor.systemBackground) .zIndex(valueToEnter ? 0 : 1) } } }.navigationTitle("We split") .toolbar { ToolbarItemGroup(placement: .keyboard) { Spacer() if checkAmountIsFocused { Button("Done") { checkAmountIsFocused = false } } } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’24
Reply to How can I link to multiple views using Foreach. When I have five options with icons. Each option goes to a different link View
You should use code formatter tool to present your code properly in the post. It is really a pain to read it unformatted. And remove extra blank lines. What is the problem and the error you get ? You should handle a default case with EmptyView a good way to do it is to use ViewBuilder. Create a ViewBuilder (I use item.name and not item): @ViewBuilder func selectedView(name: String) -> some View { switch name { case "Medical": MedicalView() case "Illnes": IllnesView() case "Vaccune": VaccuneView() case "Dewor": DeworView() case "Allergie": AllergieView() default: EmptyView() } } And call with: Button(action: { }) { NavigationLink(destination: selectedView(name: item.name)) { } So you should change the definition of Item to get the name directly struct MockData { static var items = [Item(name: "Medical", color: .red, image: "heart"), Item(name: "Illnes", color: .blue, image:"pill"), Item(name: "Vaccune", color: .orange, image: "syringe"), Item(name: "Dewor", color: .green, image: "microbe"), Item(name: "Allergie", color:.purple, image: "allergens")] } Note that you'd now better use navigationDestination in a navigationStack. See how here: https://www.hackingwithswift.com/books/ios-swiftui/handling-navigation-the-smart-way-with-navigationdestination
Topic: App & System Services SubTopic: Core OS Tags:
Apr ’24
Reply to Unable to Enrol in Apple Developer Program
Is it the first time you try to unroll or did you unroll in the past ? If so, how was your account terminated ? today have been told by several people on the phone that I can't continue with the enrolment Who are this people ? Apple Support ? Did you call them or did they contact you ? In which country are you trying to enrol ?   I was told they'd reset my enrolment Told by whom ?
Apr ’24
Reply to Guideline 5.2.1 - Legal - Intellectual Property
A patent would not solve (and if there is a copyright issue, you would not logically get it). What I would do in such a case: either find information from Espressif Systems that the use of their product is free, and provide this information to reviewer or ask to Espressif Systems for a letter that authorises you to use in an app published on Appstore. Good luck.
Apr ’24
Reply to How to get the position of dominant colors in CGImage?
An idea for a more basic solution: split each color axis (0 to 255) in segments with width of 4: 0-3; 4-7; 8-11 … You will have 64 segments. Then you create an array to count how many pixels in each of the 64 * 64 * 64 = 262144 items (if you split by 8, you can reduce to 323232 = 32768 var theCube : [Int] = Array(repeating: 0, count: 646464) a function to compute the position of a color in the array: func colorIndex(for color: UIColor) -> Int { // we return 64*64*r/4 + 64*g/4 + b/4, with r, g, b between 0 and 255 var index = 0 if let components = color.cgColor.components { if components.count < 3 { // We are grayscale, r, g, b will be equal let grayValue = Int(255*components[0] / 4) // We bring grayValue between 0 and 63 index = (64*64 + 64 + 1) * grayValue } else { // components are between 0 and 1, convert to 0...255 first index = 64*64*Int(255*components[0] / 4) index = index + 64 * Int(255*components[1] / 4) index = index + Int(255*components[2] / 4) } } return index } test: print(colorIndex(for: UIColor.red)) // 258048 print(colorIndex(for: UIColor.green)) // 4032 print(colorIndex(for: UIColor.blue)) // 63 print(colorIndex(for: UIColor.white)) // 262143 last item in cube print(colorIndex(for: UIColor.black)) // 0 first item in cube you then test for each pixel, computing the colorIndex and increment the cube[index] accordingly max value in the array is the dominant color: its index is dominantColorIndex. Once you have defined this dominant color search for points which color fall in this max, by computing its colorIndex and find if equal to dominantColorIndex Hope that helps.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to How to get the position of dominant colors in CGImage?
How do you define precisely dominant color ? A single specific RGB value would not make a lot of sense. Once you have defined this dominant color (probably ranges of R, G, B values: an RGB Cube), you have to test for each pixel if it falls within this cube.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Question about Uploading my App to the Apple Store.
Never give your Apple Developer Account to anyone.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Broken Xcode
Your version of Xcode is so old (we are now 15.4) and MacOS 14, that it is not surprising that you get problems. Even rdar is no more accessible. Can't you really update MacOS to a more recent version and Xcode to a version supported by this OS version ?
Replies
Boosts
Views
Activity
Apr ’24
Reply to How to I move the sectorMark annotation to the outside perimeter of the pie chart?
The way I achieved it is by computing a position for the annotation. Here is the sample code for you to improve… struct ContentView: View { struct PieData: Identifiable { let id = UUID() let category: String let categoryPercentage: Int var angle = 0.0 // Will be computed onAppear var color: Color } @State private var pieData: [PieData] = [ .init(category: "A", categoryPercentage: 10, color: .blue), .init(category: "B", categoryPercentage: 68, color: .green), .init(category: "C", categoryPercentage: 20, color: .orange), .init(category: "D", categoryPercentage: 38, color: .brown), .init(category: "E", categoryPercentage: 98, color: .red), .init(category: "F", categoryPercentage: 58, color: .cyan), .init(category: "G", categoryPercentage: 77, color: .yellow) ] var angles: [Double] { var computedAngles = [Double]() var midSectorAngle = 0.0 let total = pieData.reduce(0, { $0 + $1.categoryPercentage }) // needed to compute angles var partialTotal = 0 for data in pieData { midSectorAngle = Double(partialTotal) + Double(data.categoryPercentage) / 2 midSectorAngle *= 2 * Double.pi / Double(total) computedAngles.append(midSectorAngle) partialTotal += data.categoryPercentage } return computedAngles } var body: some View { GeometryReader { geometry in Chart(pieData) { data in SectorMark(angle: .value("Pie Chart", data.categoryPercentage), angularInset: 1.7) .foregroundStyle(by: .value("Category", data.category)) .cornerRadius (5) .annotation (position: .overlay) { Text("\(data.categoryPercentage)%") .bold() .position(x: 145+75*sin(data.angle), y: 140-75*cos(data.angle)) } // .offset(x: 200, y: 20) // If here it would rotate sectors ! } .frame(width: 300, height: 300) .position(x: 200, y: 400) .onAppear { for index in 0..<pieData.count { pieData[index].angle = angles[index] } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to iPad - List View - background to foreground - moves up
I tested your code on iPad simulator and could not reproduce. Please explain in detail the different steps.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Cannot preview in this file, failed to launch
Welcome to the forum. Could you show: how you call preview the code for the View to preview
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to i want to crate a app that access all ios messages sms
An iOS app cannot access user's SMS (for privacy reasons)
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to The content regarding app forced termination in the Apple guidelines
There is only one reference to termination in the guidelines: 2.3.1 (a)ASR & NR Don’t include any hidden, dormant, or undocumented features in your app; your app’s functionality should be clear to end users and App Review. All new features, functionality, and product changes must be described with specificity in the Notes for Review section of App Store Connect (generic descriptions will be rejected) and accessible for review. Similarly, marketing your app in a misleading way, such as by promoting content or services that it does not actually offer (e.g. iOS-based virus and malware scanners) or promoting a false price, whether within or outside of the App Store, is grounds for removal of your app from the App Store or a block from installing via alternative distribution and termination of your developer account.
Replies
Boosts
Views
Activity
Apr ’24
Reply to Can't create new version
Most often you just have to reconnect later… When does the message shows ? When you click "create" ? Before ? Did you try with Safari instead of Chrome ?
Replies
Boosts
Views
Activity
Apr ’24
Reply to Developing for just myself
Welcome to the forum. You can use full fledged Xcode for free and load the app you develop on your devices and of course test on simulators. That's the free account. Really great to get started. Limits: no publishing on AppStore (I understand you don't care) you will have to rebuild and reload the app on devices frequently (I think once a week). But's that not a big issue. Good start and enjoy.
Replies
Boosts
Views
Activity
Apr ’24
Reply to TextField with Double clear button / currency format for string value
I may have a solution to propose. It is a bit circumvolved, but seems to do the job. Idea is to have 2 TextFields that overlap, and select which one is tab the front in a ZStack (with zIndex), and change focus as needed. I have set coloured background so that you can track what's happening and also hide the overlapped field. struct ContentView: View { @State private var checkAmount : Double = 0.0 @State private var valueToEnter = true @FocusState private var checkAmountIsFocused: Bool @FocusState private var checkAmount2IsFocused: Bool var totalPerPerson: Double { // calculations including (Double(checkAmount) ?? 0) return 0.0 } private let quantityFormatter: NumberFormatter = { let formatter = NumberFormatter() formatter.locale = Locale.current formatter.numberStyle = .decimal formatter.minimumFractionDigits = 2 formatter.maximumFractionDigits = 2 formatter.zeroSymbol = "" return formatter }() var body: some View { NavigationStack { Form { Section("Check amount") { ZStack { TextField("Enter check amount", value: $checkAmount, format: .currency(code: Locale.current.currency?.identifier ?? "USD")) .keyboardType(.decimalPad) .focused($checkAmountIsFocused) .onTapGesture { // onTap, we shall change focus valueToEnter = false // That puts this field behind and the "yellow" at the front checkAmount = 0 // quantityFormatter will not display any content in the yellow field checkAmountIsFocused = false checkAmount2IsFocused = true } .background(.green) // replace by Color(UIColor.systemBackground) .zIndex(valueToEnter ? 1 : 0) TextField("", value: $checkAmount, formatter: quantityFormatter) .keyboardType(.decimalPad) .focused($checkAmount2IsFocused) .onSubmit { valueToEnter = true // That puts this field behind and the "green" at the front checkAmountIsFocused = true checkAmount2IsFocused = false } .background(.yellow) // replace by Color(UIColor.systemBackground) .zIndex(valueToEnter ? 0 : 1) } } }.navigationTitle("We split") .toolbar { ToolbarItemGroup(placement: .keyboard) { Spacer() if checkAmountIsFocused { Button("Done") { checkAmountIsFocused = false } } } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to How can I link to multiple views using Foreach. When I have five options with icons. Each option goes to a different link View
You should use code formatter tool to present your code properly in the post. It is really a pain to read it unformatted. And remove extra blank lines. What is the problem and the error you get ? You should handle a default case with EmptyView a good way to do it is to use ViewBuilder. Create a ViewBuilder (I use item.name and not item): @ViewBuilder func selectedView(name: String) -> some View { switch name { case "Medical": MedicalView() case "Illnes": IllnesView() case "Vaccune": VaccuneView() case "Dewor": DeworView() case "Allergie": AllergieView() default: EmptyView() } } And call with: Button(action: { }) { NavigationLink(destination: selectedView(name: item.name)) { } So you should change the definition of Item to get the name directly struct MockData { static var items = [Item(name: "Medical", color: .red, image: "heart"), Item(name: "Illnes", color: .blue, image:"pill"), Item(name: "Vaccune", color: .orange, image: "syringe"), Item(name: "Dewor", color: .green, image: "microbe"), Item(name: "Allergie", color:.purple, image: "allergens")] } Note that you'd now better use navigationDestination in a navigationStack. See how here: https://www.hackingwithswift.com/books/ios-swiftui/handling-navigation-the-smart-way-with-navigationdestination
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Unable to Enrol in Apple Developer Program
Is it the first time you try to unroll or did you unroll in the past ? If so, how was your account terminated ? today have been told by several people on the phone that I can't continue with the enrolment Who are this people ? Apple Support ? Did you call them or did they contact you ? In which country are you trying to enrol ?   I was told they'd reset my enrolment Told by whom ?
Replies
Boosts
Views
Activity
Apr ’24
Reply to Guideline 5.2.1 - Legal - Intellectual Property
A patent would not solve (and if there is a copyright issue, you would not logically get it). What I would do in such a case: either find information from Espressif Systems that the use of their product is free, and provide this information to reviewer or ask to Espressif Systems for a letter that authorises you to use in an app published on Appstore. Good luck.
Replies
Boosts
Views
Activity
Apr ’24