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

Refactor EndpointInfo in Swift #3195

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bernardnormier
Copy link
Member

This PR converts the Swift EndpointInfo into classes like in C++ and C#.

@@ -15,10 +15,12 @@ class CommunicatorI: LocalObject<ICECommunicator>, Communicator {
self.initData = initData
do {
classGraphDepthMax = try initData.properties!.getIcePropertyAsInt("Ice.ClassGraphDepthMax")
precondition(classGraphDepthMax >= 1 && classGraphDepthMax <= 0x7FFF_FFFF, "Ice.ClassGraphDepthMax must be >= 0 and <= 0x7FFF_FFFF")
precondition(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to Swift format more often.

@@ -2,77 +2,155 @@

import Foundation

/// The user-level interface to an endpoint.
public protocol Endpoint: AnyObject, CustomStringConvertible {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved at the top of Endpoint.swift. Didn't change this protocol.

///
/// - returns: `String` - The string representation of the endpoint.
func toString() -> String
public init(underlying: EndpointInfo) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically "protected", but this is not available in Swift.

}

#if TARGET_OS_IPHONE
#if TARGET_OS_IPHONE // TODO: remove conditional
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IceIAP::EndpointInfo and ConnectionInfo classes are tiny classes that don't need be conditional.

rawBytes:rawBytes];
}

// TODO: we should never return null from this factory function.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning null will result in a crash.


@interface ICEEndpointInfo ()
@property(nonatomic, readonly) std::shared_ptr<Ice::EndpointInfo> info;
+ (id)createEndpointInfo:(std::shared_ptr<Ice::EndpointInfo>)infoPtr NS_RETURNS_RETAINED;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this signature, in particular the NS_RETURNS_RETAINED. Is this correct?

The object we return is a Swift object. It does not (but could) derive from NSObject.

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