Apprendre d'Apple est le meilleur moyen.
Par exemple, la notification du clavier d'Apple:
extension UIResponder {
public class let keyboardWillShowNotification: NSNotification.Name
public class let keyboardDidShowNotification: NSNotification.Name
public class let keyboardWillHideNotification: NSNotification.Name
public class let keyboardDidHideNotification: NSNotification.Name
}
Maintenant, j'apprends d'Apple:
extension User {
/// user did login notification
static let userDidLogInNotification = Notification.Name(rawValue: "User.userDidLogInNotification")
}
Quoi de plus, NSAttributedString.Key.foregroundColor
,:
extension NSAttributedString {
public struct Key : Hashable, Equatable, RawRepresentable {
public init(_ rawValue: String)
public init(rawValue: String)
}
}
extension NSAttributedString.Key {
/************************ Attributes ************************/
@available(iOS 6.0, *)
public static let foregroundColor: NSAttributedString.Key // UIColor, default blackColor
}
Maintenant, j'apprends d'Apple:
extension UIFont {
struct Name {
}
}
extension UIFont.Name {
static let SFProText_Heavy = "SFProText-Heavy"
static let SFProText_LightItalic = "SFProText-LightItalic"
static let SFProText_HeavyItalic = "SFProText-HeavyItalic"
}
usage:
let font = UIFont.init(name: UIFont.Name.SFProText_Heavy, size: 20)
Apprendre d'Apple est la façon dont tout le monde peut le faire et peut facilement promouvoir la qualité de votre code.