From 4e591c9597df24db320589d5fb0712236aa35d73 Mon Sep 17 00:00:00 2001 From: Benjamin Erhart Date: Tue, 14 Apr 2026 17:52:06 +0200 Subject: [PATCH 1/2] Added .suitable gitignore. --- .gitignore | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e69a10 --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +# Created by https://www.toptal.com/developers/gitignore/api/xcode,macos +# Edit at https://www.toptal.com/developers/gitignore?templates=xcode,macos + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Xcode ### +## User settings +xcuserdata/ + +## Xcode 8 and earlier +*.xcscmblueprint +*.xccheckout + +### Xcode Patch ### +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcodeproj/project.xcworkspace/ +!*.xcworkspace/contents.xcworkspacedata +/*.gcno +**/xcshareddata/WorkspaceSettings.xcsettings + +# End of https://www.toptal.com/developers/gitignore/api/xcode,macos From 9f30f9f68690a2e5bfa4c9eb24db2c307a96831a Mon Sep 17 00:00:00 2001 From: Benjamin Erhart Date: Tue, 14 Apr 2026 17:53:22 +0200 Subject: [PATCH 2/2] Issue #1: format the `BlockedCount` number output to locale. --- dns/BlockedCount.swift | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/dns/BlockedCount.swift b/dns/BlockedCount.swift index 8a0faab..69d7686 100644 --- a/dns/BlockedCount.swift +++ b/dns/BlockedCount.swift @@ -3,8 +3,18 @@ import SwiftUI import Foundation struct BlockedCount: View { + @State private var txtRecord: String = "..." + private static let startIndex = 44 + + private static let formatter: NumberFormatter = { + let formatter = NumberFormatter() + formatter.numberStyle = .decimal + + return formatter + }() + var body: some View { Text(txtRecord) .onAppear { @@ -16,26 +26,21 @@ struct BlockedCount: View { // This is a DNS wire format response and we make a lot of assumptions // It is not critical functionality so just let it fail if it fails - guard data.count > 44 else { return nil } - - let startIndex = 44 - let subData = data.suffix(from: startIndex) - - // Find the first space character (ASCII 32) - var endIndex: Int? - for (offset, byte) in subData.enumerated() { - if byte == 32 { // Space character - endIndex = offset - break - } + guard data.count > Self.startIndex else { + return nil } - guard let foundEndIndex = endIndex else { return nil } + // Find the first space character (ASCII 32). + guard let endIndex = data.suffix(from: Self.startIndex).firstIndex(of: 32) else { + return nil + } - // Extract bytes between start and space - let numberData = subData.prefix(foundEndIndex) + guard let numberString = String(data: data[Self.startIndex ..< endIndex], encoding: .utf8) + else { + return nil + } - return String(decoding: numberData, as: UTF8.self) + return Self.formatter.string(for: Int(numberString)) } func fetchTXTRecord() {