-
Notifications
You must be signed in to change notification settings - Fork 0
Fix invalid @MainActor syntax and add macOS platform compatibility #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: qizh <[email protected]>
qizh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope it won't break anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes invalid Swift 6 syntax by removing @MainActor from protocol conformance declarations and marking protocol requirement implementations as nonisolated. The original syntax extension ValueView: @MainActor ProtocolName is invalid in Swift 6.
Key Changes
- Removed
@MainActorfrom 7 protocol conformance extension declarations (RawRepresentable, LosslessStringConvertible, CustomStringConvertible, ExpressibleByStringLiteral, ExpressibleByBooleanLiteral, ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral) - Added
nonisolatedkeyword to all protocol requirement implementations to satisfy nonisolated protocol requirements - Preserved
@inlinableandpublicmodifiers on affected members
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex apply your suggestions. Make sure CI can build the code you've changed with no errors. |
|
Summary
Testing
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
…lated Co-authored-by: qizh <[email protected]>
qizh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay, but should be tested
Replace or update the file parts as follows (showing the changed sections): At the top (imports): #if os(iOS) || targetEnvironment(macCatalyst)
import UIKit
#elseif os(macOS)
import AppKit
#endif
import SwiftUIWhere you apply contentShape / hoverEffect / fixedHeight, replace with platform-guarded modifiers: #if os(iOS) || targetEnvironment(macCatalyst)
.contentShape([.contextMenuPreview, .hoverEffect, .interaction, .dragPreview], shape)
.hoverEffect(.highlight)
#else
// contextMenuPreview & hoverEffect are iOS-only APIs
.contentShape([.interaction, .dragPreview], shape)
#endif
.fixedHeight()Where you set the background using .systemBackground, change to platform-aware Color: #if os(iOS) || targetEnvironment(macCatalyst)
.background(Color(.systemBackground), in: shape)
#elseif os(macOS)
.background(Color(NSColor.windowBackgroundColor), in: shape)
#endifWhere you set the pasteboard in the copy button action: #if os(iOS) || targetEnvironment(macCatalyst)
UIPasteboard.general.string = valueView.string
#elseif os(macOS)
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(valueView.string, forType: .string)
#endif
Replace the file content (or at least the header and extension) with modifications like: #if os(iOS) || targetEnvironment(macCatalyst)
import UIKit
public typealias PlatformColor = UIColor
#elseif os(macOS)
import AppKit
public typealias PlatformColor = NSColor
#endif
import SwiftUI
extension AttributedString {
@inlinable public func foregroundColor(_ color: PlatformColor) -> AttributedString {
transformingAttributes(\.foregroundColor) { foregroundColor in
// Convert platform color into SwiftUI Color
foregroundColor.value = Color(color)
}
}
@inlinable public func foregroundColor(_ color: Color) -> AttributedString {
transformingAttributes(\.foregroundColor) { foregroundColor in
foregroundColor.value = color
}
}
}Notes:
Replace instances like: String.comaspace.asAttributedString().foregroundColor(.secondaryLabel)with: String.comaspace.asAttributedString().foregroundColor(.secondary)Search and replace other UIKit-specific names:
Testing and notes
Example git workflow to apply these changes and open a PR:
|
Working on the macOS platform compatibility fixes now. Will add platform guards for iOS-only APIs and update color handling. |
…r handling Co-authored-by: qizh <[email protected]>
qizh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay, hopefully would work
|
The Swift build job is failing due to two main reasons: 1. Usage of APIs only available in macOS 26/iOS 26 or newerSeveral structs, methods, and subscripts in
Example Fix:@available(macOS 26.0, iOS 26.0, *)
public struct InlineArrayCollection<let N: Int, Element>: RandomAccessCollection {
// ... your code ...
@available(macOS 26.0, iOS 26.0, *)
public subscript(pos: Int) -> Element {
base[pos]
}
// ...
}If you cannot support earlier OS versions, it's sufficient to annotate everything involved with 2. 'NSColor' has no member errors in
|
Co-authored-by: qizh <[email protected]>
Co-authored-by: qizh <[email protected]>
Co-authored-by: qizh <[email protected]>
... Fixed in commits dcff037, 6294bd9, and eeaea5e. InlineArray+sugar.swift: Added Color+values.swift: Added proper availability guards and fixed NSColor property names:
All availability and NSColor member errors should now be resolved. |
Fix CI build failures caused by incorrect @mainactor annotations and macOS platform compatibility issues.
Changes Completed ✅
@MainActorfrom all protocol conformance extension declarationsnonisolatedto all protocol requirement implementationsstring,text,attributedString,multiplyString, andmultiplyTextproperties asnonisolatedSummary
Actor Isolation Fixes
Fixed actor isolation issues in ValueView.swift:
@MainActorannotations from protocol conformance extensions (RawRepresentable, LosslessStringConvertible, CustomStringConvertible, ExpressibleByStringLiteral, ExpressibleByBooleanLiteral, ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral)nonisolatedstring,text,attributedString,multiplyString,multiplyText) asnonisolatedto prevent "main actor-isolated property cannot be referenced from a nonisolated context" errorsThese properties are safe to mark as
nonisolatedbecauseValueViewis aSendableenum with only value-type associated values.macOS Platform Compatibility
Added cross-platform support to enable macOS builds:
LabeledValueView.swift:
hoverEffect,contextMenuPreview) with conditional compilationsystemBackgroundfor iOS,windowBackgroundColorfor macOS)AttributedString+String.swift:
PlatformColortypealias (UIColor/NSColor)foregroundColoroverloads: one forPlatformColorand one for SwiftUIColorValueView.swift:
.secondaryLabel) with SwiftUI cross-platform colors (.secondary)InlineArray+sugar.swift:
macOS 26.0to all@availableattributes alongsideiOS 26.0for InlineArray extensions and InlineArrayCollection structColor+values.swift:
@availableattributes for macOS versions to NSColor-based properties.link→.linkColor(macOS 10.10+).placeholderText→.placeholderTextColor(macOS 10.10+).separator→.separatorColor(macOS 10.14+).opaqueSeparator→.opaqueSeparatorColor(macOS 10.14+)systemFillvariants (macOS 10.15+)lightText→Color.white,darkText→Color.blackSecurity Summary
No security vulnerabilities were found or introduced by these changes.
Original prompt
This pull request was created as a result of the following prompt from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.