Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 目标是什么;建造商;?_Objective C_Cocoa_Constructor_Initialization - Fatal编程技术网

Objective c 目标是什么;建造商;?

Objective c 目标是什么;建造商;?,objective-c,cocoa,constructor,initialization,Objective C,Cocoa,Constructor,Initialization,我有这门课: @interface RSSEntry : NSObject{ NSString *blogTitle; NSString *articleTitle; NSString *articleUrl; NSDate *articleDate; } @property (copy) NSString *blogTitle; @property (copy) NSString *articleTitle; @property (copy) NSString

我有这门课:

@interface RSSEntry : NSObject{
    NSString *blogTitle;
    NSString *articleTitle;
    NSString *articleUrl;
    NSDate *articleDate;
}

@property (copy) NSString *blogTitle;
@property (copy) NSString *articleTitle;
@property (copy) NSString *articleUrl;
@property (copy) NSDate *articleDate;

@end

现在,我如何在创建对象时初始化这些成员变量,特别是在Xcode项目中启用ARC时?我不熟悉Objective-C;我正在从C基础语言中寻找类似构造函数的东西。

在Objective-C中没有构造函数。然而,通常的做法是创建
init
方法,并让用户立即调用
alloc
,然后再调用
init
。请参见示例。

您初始化了这样一个对象

RSSEntry *e = [[RSSEntry alloc] init];
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) 
{
    lesImagesViews = nil;
}
return self;
}
所以您覆盖了init方法

你的init看起来像这样

RSSEntry *e = [[RSSEntry alloc] init];
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) 
{
    lesImagesViews = nil;
}
return self;
}

这是UIViewController子类的init,其他类的默认init只是“init”,没有参数

RSSEntry*entry=[RSSEntry new]
RSSEntry*条目=[[RSSEntry alloc]init]只是提示链接已断开。可能值得在答案中添加代码??断开链接的替代内容: