Module: XDry::Boxing

Defined in:
lib/xdry/boxing.rb

Defined Under Namespace

Classes: ArrayConverter, Boxer, DateConverter, NSNumberConverter, NopConverter, StringConverter

Constant Summary collapse

SIMPLE_CONVERTIONS =
{
  'int' => NSNumberConverter.new('intValue', 'numberWithInt'),
  'NSInteger' => NSNumberConverter.new('integerValue', 'numberWithInteger'),
  'NSUInteger' => NSNumberConverter.new('unsignedIntegerValue', 'numberWithUnsignedInteger'),
  'BOOL' => NSNumberConverter.new('boolValue', 'numberWithBool'),
  'float' => NSNumberConverter.new('floatValue', 'numberWithFloat'),
  'CGFloat' => NSNumberConverter.new('floatValue', 'numberWithFloat'),
  'double' => NSNumberConverter.new('doubleValue', 'numberWithDouble'),
  'NSTimeInterval' => NSNumberConverter.new('doubleValue', 'numberWithDouble'),
}
POINTER_CONVERTIONS =
{
  'NSDate' => DateConverter.new,
  'NSString' => StringConverter.new,
}

Class Method Summary collapse

Class Method Details

.converter_for(type) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/xdry/boxing.rb', line 196

def self.converter_for type
  case type
  when SimpleVarType
    SIMPLE_CONVERTIONS[type.name]
  when PointerVarType
    case type.name
    when 'NSArray', 'NSMutableArray'
      return ArrayConverter.new(type.type_hint || 'NSObject', 'initWithDictionary', 'dictionaryRepresentation')
    end
    POINTER_CONVERTIONS[type.name]
  else
    nil
  end
end

.retain_policy_of(type) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/xdry/boxing.rb', line 211

def self.retain_policy_of type
  if conv = converter_for(type)
    conv.retain_policy
  else
    case type
      when PointerVarType then RetainPolicy::RETAIN
      when IdVarType      then RetainPolicy::ASSIGN_REF
      when SimpleVarType  then RetainPolicy::ASSIGN_VALUE
      when UnknownVarType then RetainPolicy::UNKNOWN
      when PointerPointerVarType then RetainPolicy::RETAIN
    end
  end
end