Skip to content
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

Swift 6 & Complete concurrency checking #29

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Build for Apple Platforms

on:
push:
branches:
- main
pull_request:
branches:
- '*'

env:
PROJECT_SCHEME: MarkdownView # Set your project's scheme here

jobs:
build-ios:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest

- name: Build for iOS
run: |
xcodebuild clean build \
-scheme ${{ env.PROJECT_SCHEME }} \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro'

build-macos:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest

- name: Build for macOS
run: |
xcodebuild clean build \
-scheme ${{ env.PROJECT_SCHEME }} \
-sdk macosx \
-destination 'platform=OS X'

build-tvos:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest

- name: Build for tvOS
run: |
xcodebuild clean build \
-scheme ${{ env.PROJECT_SCHEME }} \
-sdk appletvsimulator \
-destination 'platform=tvOS Simulator,name=Apple TV'

build-watchos:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest

- name: Build for watchOS
run: |
xcodebuild clean build \
-scheme ${{ env.PROJECT_SCHEME }} \
-sdk watchsimulator \
-destination 'platform=watchOS Simulator,name=Apple Watch Ultra 2 (49mm)'

build-visionos:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest

- name: Build for visionOS
run: |
xcodebuild clean build \
-scheme ${{ env.PROJECT_SCHEME }} \
-sdk xros \
-destination 'platform=visionOS Simulator,name=Apple Vision Pro'
13 changes: 7 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "4fcc1aeb59dcf0a651cfc2aba3a5253976afe1c80e8d88dd48080568e80ec3fc",
"pins" : [
{
"identity" : "highlightr",
Expand All @@ -14,19 +15,19 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-cmark.git",
"state" : {
"revision" : "29d9c97e6310b87c4799268eaa2fc76164b2dbd8",
"version" : "0.2.0"
"revision" : "3ccff77b2dc5b96b77db3da0d68d28068593fa53",
"version" : "0.5.0"
}
},
{
"identity" : "swift-markdown",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-markdown.git",
"location" : "https://github.com/swiftlang/swift-markdown.git",
"state" : {
"revision" : "68b2fed9fb12fb71ac81e537f08bed430b189e35",
"version" : "0.2.0"
"revision" : "8f79cb175981458a0a27e76cb42fee8e17b1a993",
"version" : "0.5.0"
}
}
],
"version" : 2
"version" : 3
}
7 changes: 4 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.7
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -15,7 +15,7 @@ let package = Package(
.library(name: "MarkdownView", targets: ["MarkdownView"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-markdown.git", from: "0.2.0"),
.package(url: "https://github.com/swiftlang/swift-markdown.git", from: "0.5.0"),
.package(url: "https://github.com/raspu/Highlightr.git", from: "2.1.2"),
],
targets: [
Expand All @@ -28,7 +28,8 @@ let package = Package(
package: "Highlightr",
condition: .when(platforms: [.iOS, .macOS])
),
]
],
swiftSettings: [.swiftLanguageMode(.v6)]
),
]
)
34 changes: 34 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "MarkdownView",
platforms: [
.macOS(.v12),
.iOS(.v15),
.tvOS(.v15),
.watchOS(.v8),
],
products: [
.library(name: "MarkdownView", targets: ["MarkdownView"]),
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-markdown.git", from: "0.5.0"),
.package(url: "https://github.com/raspu/Highlightr.git", from: "2.1.2"),
],
targets: [
.target(
name: "MarkdownView",
dependencies: [
.product(name: "Markdown", package: "swift-markdown"),
.product(
name: "Highlightr",
package: "Highlightr",
condition: .when(platforms: [.iOS, .macOS])
),
]
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ extension View {
}

// MARK: - Environment Values

struct MarkdownBlockDirectiveKey: EnvironmentKey {
static var defaultValue = BlockDirectiveRenderer()
@MainActor
struct MarkdownBlockDirectiveKey: @preconcurrency EnvironmentKey {
static let defaultValue = BlockDirectiveRenderer()
}

extension EnvironmentValues {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import SwiftUI
import Markdown

class BlockDirectiveRenderer {
class BlockDirectiveRenderer: @unchecked Sendable {
/// All providers which have been added.
var providers: [String : any BlockDirectiveDisplayable] = [:]

/// Add custom provider for block directive .
/// - Parameters:
/// - provider: Represention of the block directive.
Expand All @@ -19,7 +19,9 @@ class BlockDirectiveRenderer {
text: String
) -> AnyView? {
if let provider {
return AnyView(provider.makeView(arguments: args, text: text))
return provider.makeView(
arguments: args, text: text
).eraseToAnyView()
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/MarkdownView/Customization/CodeHighlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI
/// The theme of code highlighter.
///
/// - note: For more information, Check out [raspu/Highlightr](https://github.com/raspu/Highlightr) .
public struct CodeHighlighterTheme: Equatable {
public struct CodeHighlighterTheme: Equatable, Sendable {
/// The theme name in Light Mode.
var lightModeThemeName: String

Expand Down Expand Up @@ -35,7 +35,7 @@ public struct CodeHighlighterTheme: Equatable {
}

struct CodeHighlighterThemeKey: EnvironmentKey {
static var defaultValue: CodeHighlighterTheme = CodeHighlighterTheme(
static let defaultValue: CodeHighlighterTheme = CodeHighlighterTheme(
lightModeThemeName: "xcode", darkModeThemeName: "dark"
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

/// A type-erased MarkdownFontGroup value.
public struct AnyMarkdownFontGroup {
public struct AnyMarkdownFontGroup: Sendable {
var _h1: Font
var _h2: Font
var _h3: Font
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI
/// The font group that describes a set of platform’s dynamic types for each component.
///
/// Use ``MarkdownView/MarkdownFontGroup/automatic`` to construct this type.
public struct DefaultFontGroup: MarkdownFontGroup { }
public struct DefaultFontGroup: MarkdownFontGroup, Sendable { }

extension MarkdownFontGroup where Self == DefaultFontGroup {
/// The font group that describes a set of platform’s dynamic types for each component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public extension View {
// MARK: - Environment Values

struct MarkdownFontGroupKey: EnvironmentKey {
static var defaultValue = AnyMarkdownFontGroup(.automatic)
static let defaultValue = AnyMarkdownFontGroup(.automatic)
}

extension EnvironmentValues {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

/// A type-erased MarkdownForegroundStyleGroup value.
public struct AnyMarkdownForegroundStyleGroup {
public struct AnyMarkdownForegroundStyleGroup: Sendable {
var _h1: AnyShapeStyle
var _h2: AnyShapeStyle
var _h3: AnyShapeStyle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public extension View {
// MARK: - Environment Values

struct MarkdownForegroundStyleGroupKey: EnvironmentKey {
static var defaultValue = AnyMarkdownForegroundStyleGroup(.automatic)
static let defaultValue = AnyMarkdownForegroundStyleGroup(.automatic)
}

extension EnvironmentValues {
Expand Down
4 changes: 2 additions & 2 deletions Sources/MarkdownView/Customization/LayoutRole.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

/// The role of MarkdownView, which affects how MarkdownView is rendered.
public enum MarkdownViewRole {
public enum MarkdownViewRole: Sendable {
/// The normal role.
///
/// A role that makes the view take the space it needs and center contents, like a normal SwiftUI View.
Expand All @@ -18,7 +18,7 @@ public enum MarkdownViewRole {
}

struct MarkdownViewRoleKey: EnvironmentKey {
static var defaultValue = MarkdownViewRole.normal
static let defaultValue = MarkdownViewRole.normal
}

extension EnvironmentValues {
Expand Down
6 changes: 3 additions & 3 deletions Sources/MarkdownView/Customization/List.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

struct ListIndentEnvironmentKey: EnvironmentKey {
static var defaultValue: CGFloat = 12
static let defaultValue: CGFloat = 12
}

extension EnvironmentValues {
Expand All @@ -19,7 +19,7 @@ public extension View {


struct UnorderedListBulletEnvironmentKey: EnvironmentKey {
static var defaultValue: String = "•"
static let defaultValue: String = "•"
}

extension EnvironmentValues {
Expand All @@ -37,7 +37,7 @@ public extension View {


struct UnorderedListBulletFontEnvironmentKey: EnvironmentKey {
static var defaultValue: Font = .title2.weight(.black)
static let defaultValue: Font = .title2.weight(.black)
}

extension EnvironmentValues {
Expand Down
2 changes: 1 addition & 1 deletion Sources/MarkdownView/Customization/Spacing.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

struct ComponentSpacingEnvironmentKey: EnvironmentKey {
static var defaultValue: CGFloat = 8
static let defaultValue: CGFloat = 8
}

extension EnvironmentValues {
Expand Down
4 changes: 2 additions & 2 deletions Sources/MarkdownView/Customization/TintColor.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import SwiftUI

struct BlockQuoteTint: EnvironmentKey {
static var defaultValue: Color = Color.accentColor
static let defaultValue: Color = Color.accentColor
}

struct InlineCodeBlockTint: EnvironmentKey {
static var defaultValue = Color.accentColor
static let defaultValue = Color.accentColor
}

extension EnvironmentValues {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

extension AnyShapeStyle: Equatable {
extension AnyShapeStyle: @retroactive Equatable {
public static func == (lhs: AnyShapeStyle, rhs: AnyShapeStyle) -> Bool {
let oldBuffer = withUnsafeBytes(of: lhs) { $0 }
let newBuffer = withUnsafeBytes(of: rhs) { $0 }
Expand Down
9 changes: 9 additions & 0 deletions Sources/MarkdownView/Helper/ActorIsolated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

actor ActorIsolated<Value> {
public var value: Value

init(_ value: Value) {
self.value = value
}
}
2 changes: 1 addition & 1 deletion Sources/MarkdownView/Helper/ContainerSize.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

struct ContainerSize: EnvironmentKey {
static var defaultValue: CGSize = .zero
static let defaultValue: CGSize = .zero
}

extension EnvironmentValues {
Expand Down
Loading
Loading