-
Notifications
You must be signed in to change notification settings - Fork 1.2k
implementation for NSURLComponents.copy(with:) #461
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -929,9 +929,49 @@ open class NSURLComponents: NSObject, NSCopying { | |
open override func copy() -> Any { | ||
return copy(with: nil) | ||
} | ||
|
||
|
||
open override func isEqual(_ object: Any?) -> Bool { | ||
if let other = object as? NSURLComponents { | ||
if scheme != other.scheme { | ||
return false | ||
} | ||
if user != other.user { | ||
return false | ||
} | ||
if password != other.password { | ||
return false | ||
} | ||
if host != other.host { | ||
return false | ||
} | ||
if port != other.port { | ||
return false | ||
} | ||
if path != other.path { | ||
return false | ||
} | ||
if query != other.query { | ||
return false | ||
} | ||
if fragment != other.fragment { | ||
return false | ||
} | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
open func copy(with zone: NSZone? = nil) -> Any { | ||
NSUnimplemented() | ||
let copy = NSURLComponents() | ||
copy.scheme = self.scheme | ||
copy.user = self.user | ||
copy.password = self.password | ||
copy.host = self.host | ||
copy.port = self.port | ||
copy.path = self.path | ||
copy.query = self.query | ||
copy.fragment = self.fragment | ||
return copy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CFURLComponentsRef also has There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _components is set in init's. There is no variant of init that takes CFURLComponentsRef. So, I tried creating NSURLComponents using default init() and updated _components with _CFURLComponentsCreateCopy (after changing _components to var). But, this results in memory leak. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again the same issue above applies to subclassers; @mbvreddy's approach is correct for the abstract implementation. |
||
} | ||
|
||
// Initialize a NSURLComponents with the components of a URL. If resolvingAgainstBaseURL is YES and url is a relative URL, the components of [url absoluteURL] are used. If the url string from the NSURL is malformed, nil is returned. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CFURLComponentsRef implements an equality checking function. Can we just use CFEqual?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to use it. But, couldn't figure out how to cast CFURLComponentsRef to CFTypeRef thay CFEqual expect. NSURLComponent doesn't support toll-free bridge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NSURLComponents is a has-a not an is-a class so for subclasses this approach is by far safer imho