startIndex
TypeScriptget startIndex(): numberSwift declarationvar startIndex: Int { get }The position of the first element in a nonempty collection. If the collection is empty, `startIndex` is equal to `endIndex`.
struct · iOS 26.0+ · SDK 27.1
struct TranscriptA linear history of entries that reflect an interaction with a session. Use a `Transcript` to visualize previous instructions, prompts and model responses. If you use tool calling, a `Transcript` includes a history of tool calls and their results. ```swift struct HistoryView: View { let session: LanguageModelSession var body: some View { ScrollView { ForEach(session.transcript) { entry in switch entry { case let .instructions(instructions): MyInstructionsView(instructions) case let .prompt(prompt): MyPromptView(prompt) case let .reasoning(reasoning): MyReasoningView(reasoning) case let .toolCalls(toolCalls): MyToolCallsView(toolCalls) case let .toolOutput(toolOutput): MyToolOutputView(toolOutput) case let .response(response): MyResponseView(response) } } } } } ``` When you create a new ``LanguageModelSession`` it doesn't contain the state of a previous session. You can initialize a new session with a list of entries you get from a session ``LanguageModelSession/transcript``: ```swift // Create a new session with the first and last entries from a previous session. func newContextualSession(with originalSession: LanguageModelSession) -> LanguageModelSession { let allEntries = originalSession.transcript // Collect the entries to keep from the original session. let entries = [allEntries.first, allEntries.last].compactMap { $0 } let transcript = Transcript(entries: entries) // Create a new session with the result and preload the session resources. var session = LanguageModelSession(transcript: transcript) session.prewarm() return session } ```
get startIndex(): numberSwift declarationvar startIndex: Int { get }The position of the first element in a nonempty collection. If the collection is empty, `startIndex` is equal to `endIndex`.
replaceSubrange(subrange: SDKHandle, newElements: Array<Transcript_Entry>): voidSwift declarationmutating func replaceSubrange<C>(_ subrange: Range<Int>, with newElements: consuming C) where C : Collection, C.Element == Transcript.EntryReplaces the specified subrange of elements with the given collection. This method has the effect of removing the specified range of elements from the collection and inserting the new elements at the same location. The number of new elements need not match the number of elements being removed. In this example, three elements in the middle of an array of integers are replaced by the five elements of a `Repeated<Int>` instance. var nums = [10, 20, 30, 40, 50] nums.replaceSubrange(1...3, with: repeatElement(1, count: 5)) print(nums) // Prints "[10, 1, 1, 1, 1, 1, 50]" If you pass a zero-length range as the `subrange` parameter, this method inserts the elements of `newElements` at `subrange.startIndex`. Calling the `insert(contentsOf:at:)` method instead is preferred. Likewise, if you pass a zero-length collection as the `newElements` parameter, this method removes the elements in the given subrange without replacement. Calling the `removeSubrange(_:)` method instead is preferred. Calling this method may invalidate any existing indices for use with this collection. - Parameters: - subrange: The subrange of the collection to replace. The bounds of the range must be valid indices of the collection. - newElements: The new elements to add to the collection. - Complexity: O(*n* + *m*), where *n* is length of this collection and *m* is the length of `newElements`. If the call to this method simply appends the contents of `newElements` to the collection, this method is equivalent to `append(contentsOf:)`.
get history(): Transcript_HistoryViewSwift declarationvar history: Transcript.HistoryView { get set }The transcript entries excluding the leading instructions entry, if present. Use `history` to access just the conversational entries — prompts, responses, tool calls, and tool outputs — without the initial instructions that were used to configure the session. When reading, if the first entry in the transcript is an ``Entry/instructions(_:)`` entry, it is excluded from the returned view. All other entries, including any subsequent instructions entries, are included. When writing, the new value replaces all entries except the leading instructions entry, which is preserved.
set history(value: Transcript_HistoryView)Swift declarationvar history: Transcript.HistoryView { get set }The transcript entries excluding the leading instructions entry, if present. Use `history` to access just the conversational entries — prompts, responses, tool calls, and tool outputs — without the initial instructions that were used to configure the session. When reading, if the first entry in the transcript is an ``Entry/instructions(_:)`` entry, it is excluded from the returned view. All other entries, including any subsequent instructions entries, are included. When writing, the new value replaces all entries except the leading instructions entry, which is preserved.
get endIndex(): numberSwift declarationvar endIndex: Int { get }The collection's "past the end" position---that is, the position one greater than the last valid subscript argument. When you need a range that includes the last element of a collection, use the half-open range operator (`..<`) with `endIndex`. The `..<` operator creates a range that doesn't include the upper bound, so it's always safe to use with `endIndex`. For example: let numbers = [10, 20, 30, 40, 50] if let index = numbers.firstIndex(of: 30) { print(numbers[index ..< numbers.endIndex]) } // Prints "[30, 40, 50]" If the collection is empty, `endIndex` is equal to `startIndex`.
static init(): TranscriptSwift declarationinit()Creates a new, empty collection.
subscript(index: number): Transcript_EntrySwift declarationsubscript(index: Transcript.Index) -> Transcript.Entry { get set }Accesses the element at the specified position. The following example accesses an element of an array through its subscript to print its value: var streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"] print(streets[1]) // Prints "Bryant" You can subscript a collection with any valid index other than the collection's end index. The end index refers to the position one past the last element of a collection, so it doesn't correspond with an element. - Parameter position: The position of the element to access. `position` must be a valid index of the collection that is not equal to the `endIndex` property. - Complexity: O(1)
1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
Transcript.init(entries:)
This parameter hides a concrete Swift type.