From ee60aa424f2d4e1bc7905f2ce818a2a16fe46f17 Mon Sep 17 00:00:00 2001 From: yonilevy Date: Wed, 28 Jan 2026 00:16:13 +0200 Subject: [PATCH] Modernize Swift code generation to silence compiler warnings - Replace deprecated 'class' constraint with 'AnyObject' in protocols - Suppress unused variable warning for fbeStructSize - Add @retroactive attribute for external protocol conformance - Remove unnecessary '_ =' on void function calls --- .../Fbe/Source/ChronoxorFbe/ClientProtocol.swift | 3 ++- .../Fbe/Source/ChronoxorFbe/FieldModel.swift | 2 +- .../Fbe/Source/ChronoxorFbe/FinalModel.swift | 2 +- .../Source/ChronoxorFbe/ReceiverProtocol.swift | 3 ++- .../Fbe/Source/ChronoxorFbe/SenderProtocol.swift | 4 ++-- .../Fbe/Source/ChronoxorFbe/UUIDGenerator.swift | 2 +- source/generator_swift.cpp | 16 +++++++++------- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/ClientProtocol.swift b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/ClientProtocol.swift index 56c9062ea..5f7d86e13 100644 --- a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/ClientProtocol.swift +++ b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/ClientProtocol.swift @@ -8,7 +8,7 @@ import Foundation // Fast Binary Encoding base client -public protocol ClientProtocol: class { +public protocol ClientProtocol: AnyObject { // Get the send bytes buffer var sendBuffer: Buffer { get set } @@ -269,6 +269,7 @@ public extension ClientProtocol { fbeStructSize = Int(Buffer.readUInt32(buffer: messageBuffer, offset: messageOffset + fbeStructOffset)) fbeStructType = Int(Buffer.readUInt32(buffer: messageBuffer, offset: messageOffset + fbeStructOffset + 4)) } + _ = fbeStructSize // part of wire format; kept for readability // Handle the message _ = onReceive(type: fbeStructType, buffer: messageBuffer.data, offset: messageOffset, size: messageSize) diff --git a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/FieldModel.swift b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/FieldModel.swift index 37ed9c084..f6152c790 100644 --- a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/FieldModel.swift +++ b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/FieldModel.swift @@ -8,7 +8,7 @@ import Foundation // Fast Binary Encoding base field model -public protocol FieldModel: class { +public protocol FieldModel: AnyObject { var _buffer: Buffer { get set } var _offset: Int { get set } diff --git a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/FinalModel.swift b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/FinalModel.swift index d79fb4402..f52765672 100644 --- a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/FinalModel.swift +++ b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/FinalModel.swift @@ -8,7 +8,7 @@ import Foundation // Fast Binary Encoding base final model -public protocol FinalModel: class { +public protocol FinalModel: AnyObject { var _buffer: Buffer { get set } var _offset: Int { get set } diff --git a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/ReceiverProtocol.swift b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/ReceiverProtocol.swift index 4e6b000f0..ba8443fad 100644 --- a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/ReceiverProtocol.swift +++ b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/ReceiverProtocol.swift @@ -8,7 +8,7 @@ import Foundation // Fast Binary Encoding base receiver -public protocol ReceiverProtocol: class { +public protocol ReceiverProtocol: AnyObject { // Get the bytes buffer var buffer: Buffer { get set } @@ -244,6 +244,7 @@ public extension ReceiverProtocol { fbeStructSize = Int(Buffer.readUInt32(buffer: messageBuffer, offset: messageOffset + fbeStructOffset)) fbeStructType = Int(Buffer.readUInt32(buffer: messageBuffer, offset: messageOffset + fbeStructOffset + 4)) } + _ = fbeStructSize // part of wire format; kept for readability // Handle the message _ = onReceive(type: fbeStructType, buffer: messageBuffer.data, offset: messageOffset, size: messageSize) diff --git a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/SenderProtocol.swift b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/SenderProtocol.swift index 6d52c979b..d64638b0c 100644 --- a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/SenderProtocol.swift +++ b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/SenderProtocol.swift @@ -8,7 +8,7 @@ import Foundation // Fast Binary Encoding base sender -public protocol SenderProtocol: class { +public protocol SenderProtocol: AnyObject { // Get the bytes buffer var buffer: Buffer { get set } @@ -45,7 +45,7 @@ public extension SenderProtocol { // Send the value let sent = try listener.onSend(buffer: buffer.data, offset: 0, size: buffer.size) - try _ = buffer.remove(offset: 0, size: sent) + try buffer.remove(offset: 0, size: sent) return sent } } diff --git a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/UUIDGenerator.swift b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/UUIDGenerator.swift index 99b3d1559..32abb6642 100644 --- a/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/UUIDGenerator.swift +++ b/projects/Swift/Proto/Fbe/Source/ChronoxorFbe/UUIDGenerator.swift @@ -40,7 +40,7 @@ public struct UUIDGenerator { } } -extension UUID: Comparable { +extension UUID: @retroactive Comparable { public static func < (lhs: UUID, rhs: UUID) -> Bool { return lhs.hashValue < rhs.hashValue } diff --git a/source/generator_swift.cpp b/source/generator_swift.cpp index 73fad5a85..9a9e5a7d9 100644 --- a/source/generator_swift.cpp +++ b/source/generator_swift.cpp @@ -216,7 +216,7 @@ public struct UUIDGenerator { } } -extension UUID: Comparable { +extension UUID: @retroactive Comparable { public static func < (lhs: UUID, rhs: UUID) -> Bool { return lhs.hashValue < rhs.hashValue } @@ -795,7 +795,7 @@ void GeneratorSwift::GenerateFBEFieldModel(const std::string& domain, const std: std::string code = R"CODE( // Fast Binary Encoding base field model -public protocol FieldModel: class { +public protocol FieldModel: AnyObject { var _buffer: Buffer { get set } var _offset: Int { get set } @@ -2268,7 +2268,7 @@ void GeneratorSwift::GenerateFBEFinalModel(const std::string& domain, const std: std::string code = R"CODE( // Fast Binary Encoding base final model -public protocol FinalModel: class { +public protocol FinalModel: AnyObject { var _buffer: Buffer { get set } var _offset: Int { get set } @@ -3496,7 +3496,7 @@ void GeneratorSwift::GenerateFBESender(const std::string& domain, const std::str std::string code = R"CODE( // Fast Binary Encoding base sender -public protocol SenderProtocol: class { +public protocol SenderProtocol: AnyObject { // Get the bytes buffer var buffer: Buffer { get set } @@ -3533,7 +3533,7 @@ public extension SenderProtocol { // Send the value let sent = try listener.onSend(buffer: buffer.data, offset: 0, size: buffer.size) - try _ = buffer.remove(offset: 0, size: sent) + try buffer.remove(offset: 0, size: sent) return sent } } @@ -3566,7 +3566,7 @@ void GeneratorSwift::GenerateFBEReceiver(const std::string& domain, const std::s std::string code = R"CODE( // Fast Binary Encoding base receiver -public protocol ReceiverProtocol: class { +public protocol ReceiverProtocol: AnyObject { // Get the bytes buffer var buffer: Buffer { get set } @@ -3802,6 +3802,7 @@ public extension ReceiverProtocol { fbeStructSize = Int(Buffer.readUInt32(buffer: messageBuffer, offset: messageOffset + fbeStructOffset)) fbeStructType = Int(Buffer.readUInt32(buffer: messageBuffer, offset: messageOffset + fbeStructOffset + 4)) } + _ = fbeStructSize // part of wire format; kept for readability // Handle the message _ = onReceive(type: fbeStructType, buffer: messageBuffer.data, offset: messageOffset, size: messageSize) @@ -3902,7 +3903,7 @@ void GeneratorSwift::GenerateFBEClient(const std::string& domain, const std::str std::string code = R"CODE( // Fast Binary Encoding base client -public protocol ClientProtocol: class { +public protocol ClientProtocol: AnyObject { // Get the send bytes buffer var sendBuffer: Buffer { get set } @@ -4163,6 +4164,7 @@ public extension ClientProtocol { fbeStructSize = Int(Buffer.readUInt32(buffer: messageBuffer, offset: messageOffset + fbeStructOffset)) fbeStructType = Int(Buffer.readUInt32(buffer: messageBuffer, offset: messageOffset + fbeStructOffset + 4)) } + _ = fbeStructSize // part of wire format; kept for readability // Handle the message _ = onReceive(type: fbeStructType, buffer: messageBuffer.data, offset: messageOffset, size: messageSize)