From fd5756db9fcc74d0dc186502ceef96f8a0af242e Mon Sep 17 00:00:00 2001 From: Kieran Klukas Date: Sat, 9 May 2026 20:21:04 -0400 Subject: [PATCH] chore: fix circular buffer due to swift bug --- ios/Tinkcil.xcodeproj/project.pbxproj | 4 +-- ios/Tinkcil/Localizable.xcstrings | 15 +++++------ ios/Tinkcil/Models.swift | 39 +++++++++------------------ 3 files changed, 21 insertions(+), 37 deletions(-) diff --git a/ios/Tinkcil.xcodeproj/project.pbxproj b/ios/Tinkcil.xcodeproj/project.pbxproj index 4161709..b50476e 100644 --- a/ios/Tinkcil.xcodeproj/project.pbxproj +++ b/ios/Tinkcil.xcodeproj/project.pbxproj @@ -255,7 +255,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 11; + CURRENT_PROJECT_VERSION = 12; DEVELOPMENT_TEAM = M67B42LX8D; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; @@ -294,7 +294,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 11; + CURRENT_PROJECT_VERSION = 12; DEVELOPMENT_TEAM = M67B42LX8D; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; diff --git a/ios/Tinkcil/Localizable.xcstrings b/ios/Tinkcil/Localizable.xcstrings index bb24f24..7861443 100644 --- a/ios/Tinkcil/Localizable.xcstrings +++ b/ios/Tinkcil/Localizable.xcstrings @@ -155,7 +155,7 @@ } }, "%lld" : { - "comment" : "A label displaying the target temperature in the slider panel. The value is shown in degrees Celsius.", + "comment" : "A label displaying the target temperature.", "isCommentAutoGenerated" : true }, "%lld degrees Celsius" : { @@ -255,7 +255,7 @@ } }, "%u" : { - "comment" : "A live temperature display with a temperature value and a degree symbol.", + "comment" : "A label displaying the current temperature in the format \"10°C\".", "isCommentAutoGenerated" : true }, "%u %@" : { @@ -361,7 +361,7 @@ } }, "%u°" : { - "comment" : "A label showing the target temperature in degrees. The argument is the target temperature.", + "comment" : "A label displaying the target temperature.", "isCommentAutoGenerated" : true }, "°" : { @@ -836,7 +836,7 @@ } }, "Close settings" : { - "comment" : "An accessibility label for the button that closes the settings panel.", + "comment" : "A label for a button that closes a settings panel.", "isCommentAutoGenerated" : true }, "Closes the Bluetooth connection to your soldering iron" : { @@ -3596,7 +3596,7 @@ } }, "No Data" : { - "comment" : "A label describing a view that shows when there is no data to display.", + "comment" : "A label that describes a view that is displayed when there is no data.", "isCommentAutoGenerated" : true }, "Off" : { @@ -6611,7 +6611,7 @@ } }, "Temperature data will appear here" : { - "comment" : "A description text that appears when there is no temperature data available.", + "comment" : "A description of what will be displayed when the user has not yet connected a Tink.", "isCommentAutoGenerated" : true }, "Temperature history graph" : { @@ -6758,8 +6758,7 @@ } }, "Try Demo" : { - "comment" : "A button that allows users to experience the app with simulated soldering iron data.", - "isCommentAutoGenerated" : true + }, "Value" : { "comment" : "Label for the y-axis in the temperature graph.", diff --git a/ios/Tinkcil/Models.swift b/ios/Tinkcil/Models.swift index 8e7e78f..33f9a2f 100644 --- a/ios/Tinkcil/Models.swift +++ b/ios/Tinkcil/Models.swift @@ -75,25 +75,14 @@ struct TemperaturePoint: Identifiable { // MARK: - Circular Buffer -@Observable -class CircularBuffer { +struct CircularBuffer { private var buffer: [T] private var writeIndex = 0 - private(set) var isFull = false - private var cachedElements: [T]? - private var cacheInvalidated = false + private(set) var elements: [T] = [] let capacity: Int - var elements: [T] { - if cacheInvalidated { - cachedElements = computeElements() - cacheInvalidated = false - } - return cachedElements ?? computeElements() - } - var count: Int { - isFull ? capacity : writeIndex + elements.count } init(capacity: Int) { @@ -102,36 +91,32 @@ class CircularBuffer { self.buffer.reserveCapacity(capacity) } - func append(_ element: T) { + mutating func append(_ element: T) { if buffer.count < capacity { buffer.append(element) writeIndex = buffer.count if writeIndex == capacity { - isFull = true writeIndex = 0 } } else { buffer[writeIndex] = element writeIndex = (writeIndex + 1) % capacity - isFull = true } - cacheInvalidated = true + elements = makeElements() } - func clear() { + mutating func clear() { buffer.removeAll(keepingCapacity: true) writeIndex = 0 - isFull = false - cachedElements = nil - cacheInvalidated = false + elements = [] } - private func computeElements() -> [T] { - if isFull { - return Array(buffer[writeIndex...]) + Array(buffer[.. [T] { + let count = buffer.count + if count > 0 { + return Array(buffer[writeIndex..