Class: Pod::Generator::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/generator/header.rb

Overview

Generates a header file.

According to the platform the header imports `UIKit/UIKit.h` or `Cocoa/Cocoa.h`.

Direct Known Subclasses

PrefixHeader, UmbrellaHeader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform) ⇒ Header

Initialize a new instance


27
28
29
30
31
# File 'lib/cocoapods/generator/header.rb', line 27

def initialize(platform)
  @platform = platform
  @imports = []
  @module_imports = []
end

Instance Attribute Details

#importsArray<String>


16
17
18
# File 'lib/cocoapods/generator/header.rb', line 16

def imports
  @imports
end

#module_importsArray<String> (readonly)


20
21
22
# File 'lib/cocoapods/generator/header.rb', line 20

def module_imports
  @module_imports
end

#platformSymbol (readonly)


12
13
14
# File 'lib/cocoapods/generator/header.rb', line 12

def platform
  @platform
end

Instance Method Details

#generateString

Note:

If the platform is iOS an import call to `UIKit/UIKit.h` is added to the top of the prefix header. For OS X `Cocoa/Cocoa.h` is imported.

Generates the contents of the header according to the platform.


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cocoapods/generator/header.rb', line 41

def generate
  result = ''
  result << "#ifdef __OBJC__\n"
  result << generate_platform_import_header
  result << "#else\n"
  result << "#ifndef FOUNDATION_EXPORT\n"
  result << "#if defined(__cplusplus)\n"
  result << "#define FOUNDATION_EXPORT extern \"C\"\n"
  result << "#else\n"
  result << "#define FOUNDATION_EXPORT extern\n"
  result << "#endif\n"
  result << "#endif\n"
  result << "#endif\n"
  result << "\n"

  imports.each do |import|
    result << %(#import "#{import}"\n)
  end

  unless module_imports.empty?
    module_imports.each do |import|
      result << %(\[email protected] #{import})
    end
    result << "\n"
  end

  result
end

#save_as(path) ⇒ void

This method returns an undefined value.

Generates and saves the header to the given path.


77
78
79
# File 'lib/cocoapods/generator/header.rb', line 77

def save_as(path)
  path.open('w') { |header| header.write(generate) }
end