美文网首页2021 swfit 重拾之路
swift - 按钮事件 遵循协议 只读属性 单例写法

swift - 按钮事件 遵循协议 只读属性 单例写法

作者: 大也 | 来源:发表于2021-07-06 08:58 被阅读0次

1.不同的部分用 Protocol 和 extension 然文件可读性高

按钮点击事件
          self.panGestureRecognizer = UIPanGestureRecognizer(target: self, action:#selector(panGestureRecognized(gestureRecognizer:)))
遵循协议
1.           if let fromVC = fromViewController as? ADAlertViewAlertStyleTransitionProtocol {}
2.            if fromViewController.conforms(to: ADAlertViewAlertStyleTransitionProtocol.self){}

  open var shouldPresentInFullscreen: Bool { get }

//只读 也是 可以直接写get的
override var shouldPresentInFullscreen: Bool{
      get{
          return false
      }
  }

4.swift 单例

//    #warning("这个地方不明白怎么写 先不管直接加到window上")
//      解决方式看其他优秀第三方库源码 跟着写 后面就是确认方案通用性 和原理
  
//    @objc public class var shared: IQKeyboardManager {
//        struct Static {
//            //Singleton instance. Initializing keyboard manger.
//            static let kbManager = IQKeyboardManager()
//        }
//
//        /** @return Returns the default singleton instance. */
//        return Static.kbManager
//    }

  static func windowAlertViewControllerMapTable() -> NSMapTable<AnyObject, AnyObject>  {
      struct Static {
          //Singleton instance. Initializing keyboard manger.
          static let windowAlertViewControllerMapTables :NSMapTable = NSMapTable<AnyObject, AnyObject>(keyOptions: NSPointerFunctions.Options.strongMemory, valueOptions: NSPointerFunctions.Options.strongMemory)
      }

      return Static.windowAlertViewControllerMapTables
  }

相关文章

网友评论

    本文标题:swift - 按钮事件 遵循协议 只读属性 单例写法

    本文链接:https://www.haomeiwen.com/subject/kjsiultx.html