-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into MacPaw.missing_enums
- Loading branch information
Showing
7 changed files
with
143 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// View.swift | ||
// | ||
// | ||
// Created by James J Kalafus on 2024-02-03. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension View { | ||
|
||
@inlinable public func navigationTitle(_ titleKey: LocalizedStringKey, selectedModel: Binding<String>) -> some View { | ||
self | ||
.navigationTitle(titleKey) | ||
.safeAreaInset(edge: .top) { | ||
HStack { | ||
Text( | ||
"Model: \(selectedModel.wrappedValue)" | ||
) | ||
.font(.caption) | ||
.foregroundColor(.secondary) | ||
Spacer() | ||
} | ||
.padding(.horizontal, 16) | ||
.padding(.vertical, 8) | ||
} | ||
} | ||
|
||
@inlinable public func modelSelect(selectedModel: Binding<String>, models: [String], showsModelSelectionSheet: Binding<Bool>, help: String) -> some View { | ||
self | ||
.toolbar { | ||
ToolbarItem(placement: .navigationBarTrailing) { | ||
Button(action: { | ||
showsModelSelectionSheet.wrappedValue.toggle() | ||
}) { | ||
Image(systemName: "cpu") | ||
} | ||
} | ||
} | ||
.confirmationDialog( | ||
"Select model", | ||
isPresented: showsModelSelectionSheet, | ||
titleVisibility: .visible, | ||
actions: { | ||
ForEach(models, id: \.self) { (model: String) in | ||
Button { | ||
selectedModel.wrappedValue = model | ||
} label: { | ||
Text(model) | ||
} | ||
} | ||
|
||
Button("Cancel", role: .cancel) { | ||
showsModelSelectionSheet.wrappedValue = false | ||
} | ||
}, | ||
message: { | ||
Text( | ||
"View \(help) for details" | ||
) | ||
.font(.caption) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Sources/OpenAI/Public/Utilities/ArrayWithThreadSafety.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// ArrayWithThreadSafety.swift | ||
// | ||
// | ||
// Created by James J Kalafus on 2024-02-01. | ||
// | ||
|
||
import Foundation | ||
|
||
internal class ArrayWithThreadSafety<Element> { | ||
private var array = [Element]() | ||
private let queue = DispatchQueue(label: "us.kalaf.OpenAI.threadSafeArray", attributes: .concurrent) | ||
|
||
@inlinable public func append(_ element: Element) { | ||
queue.async(flags: .barrier) { | ||
self.array.append(element) | ||
} | ||
} | ||
|
||
@inlinable public func removeAll(where shouldBeRemoved: @escaping (Element) throws -> Bool) rethrows { | ||
try queue.sync(flags: .barrier) { | ||
try self.array.removeAll(where: shouldBeRemoved) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters