Class: Objc2swiftAssistant::Objc2SwiftBlockSignature
- Inherits:
-
Object
- Object
- Objc2swiftAssistant::Objc2SwiftBlockSignature
- Defined in:
- lib/objc2swift_assistant/objc_2_swift_block_conversion.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#block_converter ⇒ Object
Returns the value of attribute block_converter.
-
#return_type ⇒ Object
Returns the value of attribute return_type.
Instance Method Summary collapse
- #arg_for_objc_str(arg_str) ⇒ Object
- #from_argument_type(arg_type) ⇒ Object
- #from_components(return_type_str, arg_strings) ⇒ Object
- #from_property_type(prop_type) ⇒ Object
-
#initialize(block_converter) ⇒ Objc2SwiftBlockSignature
constructor
A new instance of Objc2SwiftBlockSignature.
- #swift_declaration(full = true) ⇒ Object
Constructor Details
#initialize(block_converter) ⇒ Objc2SwiftBlockSignature
Returns a new instance of Objc2SwiftBlockSignature.
38 39 40 |
# File 'lib/objc2swift_assistant/objc_2_swift_block_conversion.rb', line 38 def initialize( block_converter ) @block_converter = block_converter end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
36 37 38 |
# File 'lib/objc2swift_assistant/objc_2_swift_block_conversion.rb', line 36 def arguments @arguments end |
#block_converter ⇒ Object
Returns the value of attribute block_converter.
34 35 36 |
# File 'lib/objc2swift_assistant/objc_2_swift_block_conversion.rb', line 34 def block_converter @block_converter end |
#return_type ⇒ Object
Returns the value of attribute return_type.
35 36 37 |
# File 'lib/objc2swift_assistant/objc_2_swift_block_conversion.rb', line 35 def return_type @return_type end |
Instance Method Details
#arg_for_objc_str(arg_str) ⇒ Object
100 101 102 103 104 |
# File 'lib/objc2swift_assistant/objc_2_swift_block_conversion.rb', line 100 def arg_for_objc_str( arg_str ) argument = ObjCBlockParameter.new() argument.from_declaration( arg_str ) argument end |
#from_argument_type(arg_type) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/objc2swift_assistant/objc_2_swift_block_conversion.rb', line 50 def from_argument_type( arg_type ) if arg_type.count('^') > 1 failure = "Cannot convert nested Block: #{arg_type}" return "String /*#{failure}*/", failure else m = arg_type.match( /(?<return_type>[^\(]*)\s*\(\s*\^\s*\)\s*\((?<arg_string>.*)\)/ ) if m.nil? failure = "Cannot match block: #{arg_type}" return "String /*#{failure}*/", failure else objc_return_type = m[ 'return_type' ].strip! @return_type = @block_converter.type_converter.swift_type_for_objc_type( objc_return_type ) arg_string = m[ 'arg_string' ] arg_strings = arg_string.nil? ? [] : arg_string.split( ',' ) @arguments = arg_strings.map do |arg_str| arg_for_objc_str( arg_str.strip ) end end end end |
#from_components(return_type_str, arg_strings) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/objc2swift_assistant/objc_2_swift_block_conversion.rb', line 42 def from_components( return_type_str, arg_strings ) @return_type = @block_converter.type_converter.swift_type_for_objc_type( return_type_str ) @arguments = arg_strings.map do |arg_str| arg_for_objc_str( arg_str.strip ) end end |
#from_property_type(prop_type) ⇒ Object
96 97 98 |
# File 'lib/objc2swift_assistant/objc_2_swift_block_conversion.rb', line 96 def from_property_type( prop_type ) end |
#swift_declaration(full = true) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/objc2swift_assistant/objc_2_swift_block_conversion.rb', line 73 def swift_declaration( full=true ) swift_args = @arguments.map do |arg| if arg.param_name.nil? str = "#{arg.param_type}" else str = "#{arg.param_name}: #{arg.param_type}" end str end sig = "(( #{swift_args.join( ', ' )} )" if full || !return_type.nil? if return_type.nil? sig += " -> ())" if return_type.nil? else sig += " -> #{return_type})" end else sig += " -> #{return_type})" unless return_type.nil? end sig end |