简体   繁体   中英

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?

You can just use

attr_reader :name

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM