【发布时间】:2014-08-11 09:38:40
【问题描述】:
我对objective-c 非常陌生,我在这个问题上苦苦挣扎了一段时间!这是我的类原型:
@interface YoCatchModel : NSObject
/**
Name of the Yo user. Currently this is local
*/
@property (nonatomic, strong) NSString* username;
/**
History of the messages sent with Yo
*/
@property (nonatomic, strong, readonly) NSMutableArray* historyArray;
/*
implement init method
*/
+ (instancetype) initmethod;
我应该在这个只读的方法中为我的历史可变数组分配内存。
我想创建另一个带有用户名字符串参数的 init 方法。这个新的 initWithUsername 方法应该在其定义中调用 init。
这是我正在尝试使用 instancetype 作为返回类型来实现 init 方法的实现。但我不太确定如何
- 为数组分配内存。
-
为用户名调用另一个 init 方法。
@implementation YoCatchModel + (instancetype)initmethod { return [[[self class] alloc] init]; }
如果有人能给我一些提示,我将不胜感激。到目前为止,我已经阅读了这些页面以到达这里:
【问题讨论】:
标签: objective-c arrays memory-management