Skip to content

Fix visionOS availability error for split(by:) method#45

Merged
Recouse merged 1 commit intoRecouse:mainfrom
danielseidl:main
Feb 19, 2026
Merged

Fix visionOS availability error for split(by:) method#45
Recouse merged 1 commit intoRecouse:mainfrom
danielseidl:main

Conversation

@danielseidl
Copy link
Contributor

Summary

  • Fixes compiler error where split(by:) was unavailable on visionOS
  • Extracts split logic into a helper method using compile-time platform conditional

Environment

  • Xcode 26.4 beta (17E5159k)

Problem

The existing code used a runtime #available check to choose between split(separator:) (new API) and split(by:) (legacy fallback):

let rawMessages: [Data] = if #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, visionOS 1.0, *) {
    data[bufferRange].split(separator: separator)
} else {
    data[bufferRange].split(by: separator)
}

While visionOS 1.0+ would always take the if branch at runtime, Swift still type-checks the else branch at compile time, causing an error because split(by:) is marked unavailable for visionOS.

Solution

Replaced the inline conditional with a new splitData(_:separator:) helper that uses #if os(visionOS) compile-time conditional to completely exclude the legacy code path on visionOS builds:

private func splitData(_ data: Data, separator: [UInt8]) -> [Data] {
    #if os(visionOS)
    return data.split(separator: separator)
    #else
    if #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) {
        return data.split(separator: separator)
    } else {
        return data.split(by: separator)
    }
    #endif
}

Test Plan

  • Project builds successfully
  • Verify builds on visionOS target
  • Run existing EventParserTests to ensure parsing behavior unchanged

Use compile-time #if os(visionOS) conditional to exclude the legacy
split(by:) fallback on visionOS, since visionOS 1.0+ always has the
modern split(separator:) API available.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@danielseidl danielseidl requested a review from Recouse as a code owner February 19, 2026 08:56
@Recouse
Copy link
Owner

Recouse commented Feb 19, 2026

That's a good catch, thank you!

@Recouse Recouse merged commit 4913820 into Recouse:main Feb 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants