iOS:初始化对象的正确方法?
以Parse的iOS:初始化对象的正确方法?,ios,objective-c,initialization,class-method,instance-methods,Ios,Objective C,Initialization,Class Method,Instance Methods,以Parse的PFQuery类为模型,我正在为自己的项目(不是PFQuery的子类)构建自己的EMQuery类。我的问题是,如果我想以Parse的方式对类方法执行类似的调用(PFQuery*query=[pfqueryquerywhith…]),这是正确的方法吗 + (instancetype)queryWithType:(EMObjectType)objectType { EMQuery *query = [[self alloc] init]; return [query i
PFQuery
类为模型,我正在为自己的项目(不是PFQuery的子类)构建自己的EMQuery
类。我的问题是,如果我想以Parse的方式对类方法执行类似的调用(PFQuery*query=[pfqueryquerywhith…]
),这是正确的方法吗
+ (instancetype)queryWithType:(EMObjectType)objectType {
EMQuery *query = [[self alloc] init];
return [query initWithQueryType:objectType];
}
- (id)initWithQueryType:(EMObjectType)objectType {
self = [super init];
if (self) {
}
return self;
}
否-因为您两次调用超类的init 您的initWithQueryType应该替换对init的调用
+ (instancetype)queryWithType:(EMObjectType)objectType {
EMQuery *query = [self alloc];
return [query initWithQueryType:objectType];
}
例外情况是,如果类中的init执行某些操作。在这种情况下,两个initinit
和initWithQueryType:
应该设置为一个调用另一个,被调用的一个是唯一调用super init
的一个。这一个是指定的初始化器
所有初始化的主要解释是关于对象初始化的部分否-因为您两次调用了超类的init 您的initWithQueryType应该替换对init的调用
+ (instancetype)queryWithType:(EMObjectType)objectType {
EMQuery *query = [self alloc];
return [query initWithQueryType:objectType];
}
例外情况是,如果类中的init执行某些操作。在这种情况下,两个initinit
和initWithQueryType:
应该设置为一个调用另一个,被调用的一个是唯一调用super init
的一个。这一个是指定的初始化器
所有初始化的主要解释是关于对象初始化的部分否-因为您两次调用了超类的init 您的initWithQueryType应该替换对init的调用
+ (instancetype)queryWithType:(EMObjectType)objectType {
EMQuery *query = [self alloc];
return [query initWithQueryType:objectType];
}
例外情况是,如果类中的init执行某些操作。在这种情况下,两个initinit
和initWithQueryType:
应该设置为一个调用另一个,被调用的一个是唯一调用super init
的一个。这一个是指定的初始化器
所有初始化的主要解释是关于对象初始化的部分否-因为您两次调用了超类的init 您的initWithQueryType应该替换对init的调用
+ (instancetype)queryWithType:(EMObjectType)objectType {
EMQuery *query = [self alloc];
return [query initWithQueryType:objectType];
}
例外情况是,如果类中的init执行某些操作。在这种情况下,两个initinit
和initWithQueryType:
应该设置为一个调用另一个,被调用的一个是唯一调用super init
的一个。这一个是指定的初始化器
所有初始化的主要解释是关于对象初始化的部分不要调用两个init方法;打一次电话。像这样:
+ (instancetype)queryWithType:(EMObjectType)objectType {
EMQuery *query = [[self alloc] initWithQueryType:objectType];
return query;
}
不要调用两个init方法;打一次电话。像这样:
+ (instancetype)queryWithType:(EMObjectType)objectType {
EMQuery *query = [[self alloc] initWithQueryType:objectType];
return query;
}
不要调用两个init方法;打一次电话。像这样:
+ (instancetype)queryWithType:(EMObjectType)objectType {
EMQuery *query = [[self alloc] initWithQueryType:objectType];
return query;
}
不要调用两个init方法;打一次电话。像这样:
+ (instancetype)queryWithType:(EMObjectType)objectType {
EMQuery *query = [[self alloc] initWithQueryType:objectType];
return query;
}
啊,我明白了。完美的解释!谢谢你的链接。:)啊,我明白了。完美的解释!谢谢你的链接。:)啊,我明白了。完美的解释!谢谢你的链接。:)啊,我明白了。完美的解释!谢谢你的链接。:)这还不够。您必须调用一个且只能调用一个init方法。一个还不够。您必须调用一个且只能调用一个init方法。一个还不够。您必须调用一个且只能调用一个init方法。一个还不够。必须调用一个且只能调用一个init方法。