Cocoapod中的可选协议方法

时间:2019-02-15 02:15:53

标签: swift cocoapods protocols

我有几种协议方法,开发人员在安装我的cocoapod时可以作为委托调用。但是,目前都需要实施它们。如何使它们成为可选的?这是一个片段:

在我的cocoapod的代码中:

public protocol ServiceDelegate: NSObjectProtocol {
    func didDetectDoubleTapGesture()
}

//To fire the protocol method...
delegate?.didDetectDoubleTapGesture()

从开发人员的角度来看:

extension ViewController: ServiceDelegate {

    func didDetectDoubleTapGesture() {
        print("didDetectDoubleTapGesture")
    }

}

它当前有效,但是我想使开发人员可以选择实现'didDetectDoubleTapGesture()'委托方法。到目前为止,我已经尝试了'@objc'和'@optional'。最干净的方法是什么?

1 个答案:

答案 0 :(得分:0)

with xml_data as (select xmltype('<?xml version="1.0" encoding="UTF-8"?>
<MSH>
   <MSH.1>|</MSH.1>
   <MSH.2>lal</MSH.2>
   <MSH.3>
      <HD.1>LAB</HD.1>
   </MSH.3>
   <MSH.4>
      <HD.1>767543</HD.1>
   </MSH.4>
   <MSH.5>
      <HD.1>ADT</HD.1>
   </MSH.5>
   <MSH.6>
      <HD.1>767543</HD.1>
   </MSH.6>
   <MSH.7>199003141304-0500</MSH.7>
   <MSH.9>
      <CM_MSG.1>ACK</CM_MSG.1>
      <CM_MSG.3>ACK_ACK</CM_MSG.3>
   </MSH.9>
   <MSH.10>XX3657</MSH.10>
   <MSH.11>
      <PT.1>P</PT.1>
   </MSH.11>
   <MSH.12>
      <VID.1>2.4</VID.1>
   </MSH.12>
</MSH>') xd from dual)
select x.* from xml_data
,xmltable('//*[not(*)]' passing xd 
 columns  
    n_level_1    varchar2(4000) path '(ancestor-or-self::*/name(.))[1]'
   ,n_level_2   varchar2(4000) path '(ancestor-or-self::*/name(.))[2]'
   ,n_level_3   varchar2(4000) path '(ancestor-or-self::*/name(.))[3]'
   ,n_level_4   varchar2(4000) path '(ancestor-or-self::*/name(.))[4]'
   ,n_level_5   varchar2(4000) path '(ancestor-or-self::*/name(.))[5]'
   ,n_level_6   varchar2(4000) path '(ancestor-or-self::*/name(.))[6]'
   ,n_level_7   varchar2(4000) path '(ancestor-or-self::*/name(.))[7]'
   ,n_level_8   varchar2(4000) path '(ancestor-or-self::*/name(.))[8]'
   ,n_level_9   varchar2(4000) path '(ancestor-or-self::*/name(.))[9]'
   ,n_level_10  varchar2(4000) path '(ancestor-or-self::*/name(.))[10]'    
   --...n times
   ,n_value    varchar2(4000)  path './text()'  
 ) x;