Same class extension in two different modules
Asked Answered
S

1

8

I have a framework in my project that implements an extension on NSDate. The extension looks like this.

extension NSDate {
   func isGreaterThanDate(otherDate: NSDate) -> Bool {
      //function implementation here
   }
}

I've imported this framework into an app project. Now if I copy and paste that same extension into a swift file in the app, the new copy in my app's code appears to override the copy in the framework's code.

When I'm calling this function in my app, is there a way I can use namespacing to specify which implementation I want?

Sparrowgrass answered 4/11, 2015 at 23:57 Comment(3)
I don't understand why you want to override a function that you use in your framework in your app later?Vani
just change the name or the param label a little bit. You don't want to confuse your self with 2 different functions with the same name right? Even if you know that you might confuse others who read you code.Fanfaronade
yeah I realize I could change the name a bit... I'm kinda surprised there doesn't seem to be a way to solve this with namespacing. I can see it being a big gotcha on some dev teams...Sparrowgrass
S
2

The only answer I've found so far "No you can't use namespacing to protect against this." But I'm still keeping my eyes open for how to handle this situation if someone uses the same function signature like this accidentally.

Sparrowgrass answered 4/12, 2015 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.