Extensions


(Don Giovanni) #1

Hi I was wondering if i could get some suggestions on this:

extension CGPoint : Comparable

{

    static func <(l: CGPoint, r: CGPoint) ->

          Bool{

return true;

}

     static func ==(l: CGPoint, r: CGPoint) ->

           Bool{

       return true;

}

}

CGPoint is a Core graphics struct.

This code gives me an error "Declaration is only valid at file scope". However per swift documentation, I cannot add an access modifier to extensions that adopt protocols. I was wondering if there is an elegant workaround for this limitation or if there's something I'm missing here.

Thanks.


(Brent Royal-Gordon) #2

Is this the only thing in the file, or is the extension nested inside something else? That's what that error usually means.

···

On May 13, 2017, at 5:32 PM, Don Giovanni via swift-users <swift-users@swift.org> wrote:

Hi I was wondering if i could get some suggestions on this:

extension CGPoint : Comparable
{
    static func <(l: CGPoint, r: CGPoint) ->
          Bool{
return true;
}

     static func ==(l: CGPoint, r: CGPoint) ->
           Bool{
       return true;
}
}

CGPoint is a Core graphics struct.
This code gives me an error "Declaration is only valid at file scope". However per swift documentation, I cannot add an access modifier to extensions that adopt protocols. I was wondering if there is an elegant workaround for this limitation or if there's something I'm missing here.
Thanks.

--
Brent Royal-Gordon
Architechies