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

Add kf namespacing #435

Merged
merged 5 commits into from
Sep 17, 2016
Merged

Add kf namespacing #435

merged 5 commits into from
Sep 17, 2016

Conversation

onevcat
Copy link
Owner

@onevcat onevcat commented Sep 15, 2016

This p-r adopts to a new namespacing system. It could avoid possible naming conflicting by introducing an extra struct layer. So we could get rid of the kf_ prefix. Instead, we could use an easier kf. to limit Kingfisher related APIs in its own namespace.

@webfrogs
Copy link
Contributor

Looks great. But I have some different ideas about the implement of namespace.It's about adding namespace extension with Struct type in swift.

  1. Using the generic struct Kingfisher<Base> as the default implement for Class Type
  2. When extension the Struct type like Swift 3's Data type. Define a new struct named like XXXProxy to implement the KingfisherCompatible type which is defined before. Then writing all extension of the Proxy struct to do the extension jobs. By doing this, We can avoid using type cast to get the right type, because I believe type casting is the bad code smell of swift.

First, making some small change of KingfisherCompatible protocol, There is no need to give the set property.

protocol KingfisherCompatible {
    associatedtype CompatibleType
    var kf: CompatibleType { get }
}

Then, extension Data type can be something like this:

struct DataProxy {
    fileprivate let value: String
    init(_ value: String) {
        self.value = value
    }
}

extension Data: KingfisherCompatible {
    typealias CompatibleType = DataProxy
    var kf: CompatibleType {
        return DataProxy(self)
    }
}

extension DataProxy {
   // Do whatever you want, and you can use value to get the exactly type: Data
}

@webfrogs
Copy link
Contributor

#441 , I create a pr ,just change the way of implemention

@onevcat onevcat merged commit 27d4acf into master Sep 17, 2016
@onevcat onevcat deleted the fix/kf-namespacing branch January 19, 2017 02:12
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