Search code examples
iosobjective-ccocoa-touchrubymotion

readonly property in RubyMotion


if this in obj-c

@interface SomeClass : NSObject

@property (nonatomic,strong) NSString* name;

@end

@implementation SomeClass

@synthesize name;

//If we want to implement our own setter to do something
- (void)setName(NSString*)aString {
    name = aString;
}

@end

is this in rubymotion

class SomeClass < NSObject
  attr_accessor :name

  #If we want to implement our own setter to do something
  def name=(aString)
    @name = aString
  end
end

How (and is it even possible) to create a @property (nonatomic,strong, readonly)?

And where can I read about this?


Solution

  • You can just use

    attr_reader :name
    

    This will only generate the getter method. You can read about this in the ruby docs