【问题标题】:readonly property in RubyMotionRubyMotion 中的只读属性
【发布时间】:2014-12-31 08:14:09
【问题描述】:

如果这是在 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

这是在 ruby​​motion 中吗

class SomeClass < NSObject
  attr_accessor :name

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

如何(甚至可能)创建@property (nonatomic,strong, readonly)

我在哪里可以读到这个?

【问题讨论】:

    标签: ios objective-c cocoa-touch rubymotion


    【解决方案1】:

    你可以使用

    attr_reader :name
    

    这只会生成 getter 方法。你可以在ruby docs

    【讨论】:

      猜你喜欢
      • 2010-11-22
      • 1970-01-01
      • 2014-11-20
      • 2023-01-25
      • 2014-08-22
      • 2015-02-01
      • 2011-01-28
      • 2011-06-02
      相关资源
      最近更新 更多