Module: KissShot::ObjC::Protocol

Includes:
Base
Included in:
All
Defined in:
lib/kiss_shot/objc/protocol.rb

Instance Method Summary collapse

Methods included from Base

#_objc_bracket_array, #_objc_diamond_array

Instance Method Details

#objc_protocol(name, supers = ["NSObject"]) ⇒ Object

For @protocol

Parameters:

  • name (String)

    protocol name

  • supers (Array, String) (defaults to: ["NSObject"])

    super protocols, default to [‘NSObject’]

Returns:

  • self



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kiss_shot/objc/protocol.rb', line 26

def objc_protocol(name, supers = ["NSObject"])
  # Add new line
  line
  # Declare
  raw "@protocol #{name}"
  if block_given?
    # If block given, add supers, and yield
    if supers.count
      raw " #{_objc_diamond_array(Array.wrap(supers))}"
    end
    # new line, no indent
    raw "\n"
    # yield
    yield
    # add @end
    line "@end"
  else
    # if no block given, just close line with ;
    raw ";\n"
  end
  self
end

#objc_protocol_optionalObject

Add line for @optional

Returns:

  • self



16
17
18
19
20
# File 'lib/kiss_shot/objc/protocol.rb', line 16

def objc_protocol_optional
  line
  line "@optional"
  self
end

#objc_protocol_requiredObject

Add line for @required

Returns:

  • self



8
9
10
11
12
# File 'lib/kiss_shot/objc/protocol.rb', line 8

def objc_protocol_required
  line
  line "@required"
  self
end