Skip to content

Commit

Permalink
migrate to Swift 6
Browse files Browse the repository at this point in the history
  • Loading branch information
banjun committed Sep 24, 2024
1 parent e38e757 commit 6f1e500
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 91 deletions.
10 changes: 7 additions & 3 deletions BuildHelper/BuildHelper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
LastUpgradeCheck = 1600;
TargetAttributes = {
63A746952AFDD742003FA3AC = {
CreatedOnToolsVersion = 15.0.1;
Expand Down Expand Up @@ -219,6 +219,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -282,6 +283,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -312,6 +314,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Preview Content\"";
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -326,7 +329,7 @@
PRODUCT_BUNDLE_IDENTIFIER = jp.banjun.SwiftHotReload.BuildHelper;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
};
name = Debug;
};
Expand All @@ -339,6 +342,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Preview Content\"";
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -353,7 +357,7 @@
PRODUCT_BUNDLE_IDENTIFIER = jp.banjun.SwiftHotReload.BuildHelper;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
};
name = Release;
};
Expand Down
5 changes: 3 additions & 2 deletions BuildHelper/Sources/BuildHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
// Release build is not disabled as BuildHelper.app is to be buildable for generating a mac helper app.
// TODO: BuildHelper may be separated into sub- spec/package
import Foundation
import Combine
@preconcurrency import Combine

@MainActor
public final class BuildHelper: ObservableObject {
let proxyBrowser = ProxyBrowser()

Expand All @@ -17,7 +18,7 @@ public final class BuildHelper: ObservableObject {
private var fileMonitor: FileMonitor? {
didSet {
Task {
fileMonitorCancellable = await fileMonitor?.$fileChanges.compactMap {$0}.sink { [weak self] _ in
fileMonitorCancellable = await fileMonitor?.fileChanges.compactMap {$0}.sink { [weak self] _ in
self?.reload()
}
}
Expand Down
5 changes: 4 additions & 1 deletion BuildHelper/Sources/BuildHelperApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct BuildHelperApp: SwiftUI.App {

struct ContentView: View {
@EnvironmentObject var buildHelper: BuildHelper
@State private var browserView: MCBrowserViewControllerView?

var body: some View {
VStack(spacing: 20) {
Expand All @@ -38,7 +39,9 @@ struct BuildHelperApp: SwiftUI.App {
Text("Date Reloaded" + "\n" + (buildHelper.dateReloaded?.formatted(date: .numeric, time: .complete) ?? "Never"))
.multilineTextAlignment(.center)

buildHelper.proxyBrowser.browserView
if let browserView { browserView } else { ProgressView().task {
browserView = await buildHelper.proxyBrowser.browserView()
}}
}
.padding()
}
Expand Down
23 changes: 13 additions & 10 deletions BuildHelper/Sources/ProxyBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
// Release build is not disabled as BuildHelper.app is to be buildable for generating a mac helper app.
// TODO: BuildHelper may be separated into sub- spec/package
import Foundation
import MultipeerConnectivity
@preconcurrency import MultipeerConnectivity
@testable import SwiftHotReload // NOTE: use internal methods. SPM does not allow overlapping sources for a single Package.swift
import SwiftUI

final actor ProxyBrowser {
@Published private(set) var runtimePeers: [RuntimePeer] = []
private let peerID: MCPeerID
private let session: MCSession
private let browser: MCNearbyServiceBrowser
private let sessionDelegate: SessionDelegate = .init()
let browserView: MCBrowserViewControllerView
private(set) var browserView: @Sendable () async -> MCBrowserViewControllerView

init(hostName: String = ProcessInfo().hostName, bundleID: String? = Env.shared.CFBundleIdentifier, processID: Int32 = ProcessInfo().processIdentifier) {
init(hostName: String = ProcessInfo().hostName, bundleID: String? = Env.host.CFBundleIdentifier, processID: Int32 = ProcessInfo().processIdentifier) {
let displayName = String("Client[\(hostName)] \(bundleID ?? "cli")(\(processID))".utf8.prefix(63))!
self.peerID = MCPeerID(displayName: displayName)
self.session = MCSession(peer: peerID, securityIdentity: nil, encryptionPreference: .required)
self.browser = MCNearbyServiceBrowser(peer: peerID, serviceType: MultipeerConnectivityConstants.serviceType)
self.browserView = MCBrowserViewControllerView(browser: browser, session: session)
let session = MCSession(peer: peerID, securityIdentity: nil, encryptionPreference: .required)
self.session = session
let browser = MCNearbyServiceBrowser(peer: peerID, serviceType: MultipeerConnectivityConstants.serviceType)
self.browser = browser
self.browserView = { await MCBrowserViewControllerView(browser: browser, session: session) }

// Task {
session.delegate = sessionDelegate
Expand Down Expand Up @@ -69,16 +72,16 @@ final actor ProxyBrowser {
}

private extension ProxyBrowser {
private final class SessionDelegate: NSObject, MCSessionDelegate {
unowned var owner: ProxyBrowser?
private final class SessionDelegate: NSObject, MCSessionDelegate, Sendable {
unowned nonisolated(unsafe) var owner: ProxyBrowser?
override init() { super.init() }

func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) {
Task { await owner?.session(session, peer: peerID, didChange: state) }
Task { @Sendable in await self.owner?.session(session, peer: peerID, didChange: state) }
}

func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {
Task { await owner?.session(session, didReceive: data, fromPeer: peerID) }
Task { @Sendable in await self.owner?.session(session, didReceive: data, fromPeer: peerID) }
}

func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) {
Expand Down
10 changes: 7 additions & 3 deletions Example/SwiftHotReloadExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
LastUpgradeCheck = 1600;
TargetAttributes = {
63980F422AEA8DA50099B122 = {
CreatedOnToolsVersion = 15.0.1;
Expand Down Expand Up @@ -209,6 +209,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -270,6 +271,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -297,6 +299,7 @@
CODE_SIGN_ENTITLEMENTS = SwiftHotReloadExample.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Preview Content\"";
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -325,7 +328,7 @@
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Debug;
Expand All @@ -338,6 +341,7 @@
CODE_SIGN_ENTITLEMENTS = SwiftHotReloadExample.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Preview Content\"";
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -366,7 +370,7 @@
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
10 changes: 7 additions & 3 deletions FrameworkTarget/SwiftHotReload.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
LastUpgradeCheck = 1600;
TargetAttributes = {
63980F702AEA93310099B122 = {
CreatedOnToolsVersion = 15.0.1;
Expand Down Expand Up @@ -254,6 +254,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -318,6 +319,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -345,6 +347,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down Expand Up @@ -375,7 +378,7 @@
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Debug;
Expand All @@ -386,6 +389,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down Expand Up @@ -414,7 +418,7 @@
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Release;
Expand Down
52 changes: 32 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.6)
CFPropertyList (3.0.7)
base64
nkf
rexml
activesupport (6.1.7.6)
activesupport (7.1.4)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
base64 (0.2.0)
bigdecimal (3.1.8)
claide (1.1.0)
cocoapods (1.13.0)
cocoapods (1.15.2)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.13.0)
cocoapods-core (= 1.15.2)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.6.0, < 2.0)
cocoapods-downloader (>= 2.1, < 3.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.6.0, < 2.0)
Expand All @@ -34,7 +42,7 @@ GEM
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.23.0, < 2.0)
cocoapods-core (1.13.0)
cocoapods-core (1.15.2)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
Expand All @@ -45,7 +53,7 @@ GEM
public_suffix (~> 4.0)
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (1.6.3)
cocoapods-downloader (2.1)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.1)
Expand All @@ -54,40 +62,44 @@ GEM
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.2.2)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
drb (2.2.1)
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.16.3)
ffi (1.17.0-arm64-darwin)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.14.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.6.3)
minitest (5.20.0)
json (2.7.2)
minitest (5.25.1)
molinillo (0.8.0)
mutex_m (0.2.0)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
nkf (0.2.0)
public_suffix (4.0.7)
rexml (3.2.6)
rexml (3.3.7)
ruby-macho (2.5.1)
typhoeus (1.4.0)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcodeproj (1.23.0)
xcodeproj (1.25.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
zeitwerk (2.6.12)
rexml (>= 3.3.2, < 4.0)

PLATFORMS
arm64-darwin-21
arm64-darwin-22

DEPENDENCIES
Expand Down
Loading

0 comments on commit 6f1e500

Please sign in to comment.