microsoft / FluentDarkModeKit

A library for backporting Dark Mode in iOS
MIT License
1.63k stars 125 forks source link

Namespace style #90

Closed VineFiner closed 2 years ago

VineFiner commented 4 years ago

Sorry, this may not be a wrong.

r.swift uses .rx to distinguish namespaces

Why didn’t you use the same method, for compatibility with Objective-C?

levinli303 commented 4 years ago

Hello, I'm not familiar with rx, can you elaborate on what you mean by distinguishing namespaces? Thanks!

VineFiner commented 4 years ago
import Foundation

struct MyNameSpace<Base> {
 private let base: Base
 init(base: Base) {
    self.base = base
 }
}

extension MyNameSpace {
    func hello() {
        print("hello")
    }
}
protocol NameSpcaceWrappable {
    associatedtype T
    // 
    var rx: T { get }
    // 
    static var rx: T.Type { get }
}

// 
extension NameSpcaceWrappable {
    var rx: MyNameSpace<Self> {
         return MyNameSpace<Self>(base: self)
     }

     static var rx: MyNameSpace<Self>.Type {
         return MyNameSpace<Self>.self
     }
}

extension String: NameSpcaceWrappable {

}
let space = String()
space.rx.hello()
levinli303 commented 4 years ago

hmm, maybe an example related to this project would be better, I'm still trying to know what you are proposing here. Wrap a UIColor/UIImage?

VineFiner commented 4 years ago

hmm, maybe an example related to this project would be better, I'm still trying to know what you are proposing here. Wrap a UIColor/UIImage?

Yes, I found a binary library.

https://github.com/Elenionl/EasyDarkMode

Is it better for swift?


import EasyDarkMode

imageView.image = UIImage.dm.image(name: "check_light", dark: "check_dark")
levinli303 commented 2 years ago

Closing, we do not intend to make interface changes in the future. Objective-C compatibility has been added a few commits ago.