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

[SR-3748] Objective-C runtime API should receive a better Swift API similar to Dispatch #46333

Closed
DevAndArtist mannequin opened this issue Jan 26, 2017 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. SDKOverlay

Comments

@DevAndArtist
Copy link
Mannequin

DevAndArtist mannequin commented Jan 26, 2017

Previous ID SR-3748
Radar None
Original Reporter @DevAndArtist
Type Bug
Status Resolved
Resolution Invalid
Environment

Xcode 8.2.1 with it's build in Swift 3.0.2 toolchain.

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, SDKOverlay
Assignee None
Priority Medium

md5: 80c49a4eed96d0ec34fb6ffffa7814e8

Issue Description:

Here is a quick sketch of how the `Method` could look like in Swift (I believe it can be improved even further):

/// An opaque type that represents a method in a class definition.
public struct Method {
  
    public struct Description {
        /**< The name (selector) of the method */
        public var selector: Selector
        
        /**< The types of the method arguments */
        public var types: UnsafeMutablePointer<Int8>
        
        public init()
        
        public init(name: Selector, types: UnsafeMutablePointer<Int8>)
    }
  
    /**
     * Returns the name (selector) of a method.
     *
     * @return A pointer of type SEL.
     *
     * @note To get the method name as a C string, call \c sel_getName(method.selector).
     */
    @available(iOS 2.0, *)
    public var selector: Selector { get }
    
    /**
     * Returns or sets the implementation of a method.
     *
     * @return A function pointer of type IMP.
     */
    @available(iOS 2.0, *)
    public var implementation: IMP { get set }
    
    /**
     * Returns a string describing a method's parameter and return types.
     *
     * @return A C string. The string may be \c NULL.
     */
    @available(iOS 2.0, *)
    public var typeEncoding: UnsafePointer<Int8> { get }
    
    /**
     * Returns the number of arguments accepted by a method.
     *
     * @return An integer containing the number of arguments accepted by the given method.
     */
    @available(iOS 2.0, *)
    public var numberOfArguments: UInt32 { get }
    
    /**
     * Returns a string describing a method's return type.
     *
     * @return A C string describing the return type. You must free the string with \c free().
     */
    @available(iOS 2.0, *)
    public var copyReturnType: UnsafeMutablePointer<Int8> { get }
    
    /**
     * Returns a string describing a single parameter type of a method.
     *
     * @param index The index of the parameter to inspect.
     *
     * @return A C string describing the type of the parameter at index \e index, or \c NULL
     *  if method has no parameter index \e index. You must free the string with \c free().
     */
    @available(iOS 2.0, *)
    public func copyArgumentType(at index: UInt32) -> UnsafeMutablePointer<Int8>
    
    /**
     * Returns a string describing a method's return type.
     */
    @available(iOS 2.0, *)
    public var returnType: String { get }
    
    /**
     * Returns a string describing a single parameter type of a method.
     *
     * @param index The index of the parameter you want to inquire about.
     */
    @available(iOS 2.0, *)
    public func argumentType(at index: UInt32) -> String?
    
    @available(iOS 2.0, *)
    public var description: UnsafeMutablePointer<Description> { get }
    
    /**
     * Exchanges the implementations of two methods.
     *
     * @param other Method to exchange with the current method.
     */
    @available(iOS 2.0, *)
    public func exchangeImplementation(with other: Method)
}

There are more types like this, that could receive some better wrapper types.

@belkadan
Copy link
Contributor

As I said, the Objective-C runtime API is an Apple product, not part of the Swift open source project. Any requests about it should go through bugreport.apple.com.

@DevAndArtist
Copy link
Mannequin Author

DevAndArtist mannequin commented Jan 26, 2017

@belkadan Okay, my bad. I'll file a bug there. Thanks again.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. SDKOverlay
Projects
None yet
Development

No branches or pull requests

1 participant