Module: KissShot::ObjC::Klass

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

Instance Method Summary collapse

Methods included from Base

#_objc_bracket_array, #_objc_diamond_array

Instance Method Details

#objc_class(name) ⇒ Object

Append @class forward declaration

Parameters:

  • name (String)

    class name

Returns:

  • self



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

def objc_class(name)
  line "@class #{name};"
  self
end

#objc_implementation(name) ⇒ Object

Append @implementation

Parameters:

  • name (String)

    class name

Returns:

  • self



31
32
33
34
35
# File 'lib/kiss_shot/objc/klass.rb', line 31

def objc_implementation(name)
  line "@implementation #{name}"
  yield if block_given?
  line "@end"
end

#objc_interface(name, superklass = "NSObject", protocols = nil) ⇒ Object

Append @interface

Parameters:

  • name (String)

    interface name

  • superklass (String, Symbol) (defaults to: "NSObject")

    superclass

  • protocols (String, Symbol, Array) (defaults to: nil)

    protocols this interface implemented

Returns:

  • self



20
21
22
23
24
25
# File 'lib/kiss_shot/objc/klass.rb', line 20

def objc_interface(name, superklass = "NSObject", protocols = nil)
  line "@interface #{name} : #{superklass}#{_objc_diamond_array(Array.wrap(protocols))}"
  yield if block_given?
  line "@end"
  self
end

#objc_interface_bracketObject

interface raw bracket for instance variable

Returns:

  • self



39
40
41
42
43
44
45
46
# File 'lib/kiss_shot/objc/klass.rb', line 39

def objc_interface_bracket
  line "{"
  indent_up
  yield if block_given?
  indent_down
  line "}"
  self
end

#objc_interface_variable(name, type = 'NSInteger') ⇒ Object

Interface instance variable

Parameters:

  • name (String)

    name of instance variable

  • type (String, Symbol, Array) (defaults to: 'NSInteger')

    type of instance variable

Returns:

  • self



52
53
54
# File 'lib/kiss_shot/objc/klass.rb', line 52

def objc_interface_variable(name, type = 'NSInteger')
  line "#{Array.wrap(type).join(" ")} #{name};"
end

#objc_method(*args) ⇒ Object

Append method

Parameters:

  • static (true, false)

    if is a static(class) method

  • return_type (String, Symbol, Array)

    return type

  • components

    remaining components



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/kiss_shot/objc/klass.rb', line 72

def objc_method(*args)
  sign = args.shift ? "+" : "-"
  type = args.shift
    raw "#{sign} (#{Array.wrap(type).join(" ")})", true
  if args.count == 1
    raw " "
    raw "#{args.shift}"
  else
    raise "Bad args for #objc_method" unless args.count % 3 == 0
    args.each_slice(3) do |slice|
      raw " "
      raw slice[0]
      raw ":"
      raw "(#{Array.wrap(slice[1]).join(" ")})"
      raw slice[2]
    end
  end
  if block_given?
    raw " {\n"
    indent_up
    yield
    indent_down
    line "}"
  else
    raw ";\n"
  end
  self
end

#objc_property(name, type, options = ['nonatomic', 'strong']) ⇒ Object

Append @property

Parameters:

  • name (String)

    property name

  • type (String, Array)

    property type, joined with ‘ `

  • options (String, Array) (defaults to: ['nonatomic', 'strong'])

    array of options, such as ‘nonatomic`, joined with ’,‘

Returns:

  • self



62
63
64
65
# File 'lib/kiss_shot/objc/klass.rb', line 62

def objc_property(name, type, options = ['nonatomic', 'strong'])
  line "@property #{_objc_bracket_array(Array.wrap(options))} #{Array.wrap(type).join(" ")} #{name};"
  self
end