想要创建实例化对象的方法。实例化对象的方法
- (NSArray *) make3Of : (Class) type
{
...
type * temp = [[type alloc] ...
...
}
但我得到的Xcode警告...
实际警告: “类方法+页头未找到(返回类型默认为‘身份证’)”
有没有更好的/正确的方式来做到这一点?
实际代码:
- (NSArray *) getBoxesOfType: (Class <ConcreteBox>) type StartingFrom: (uint64_t) offset
{
NSMutableArray *valueArray = [[NSMutableArray alloc]initWithObjects: nil];
for (uint64_t i = offset; i< boxStartFileOffset + self.size; i += [self read_U32_AtBoxOffset:i])
{
if ([[self read_String_OfLen:4 AtBoxOffset:offset + 4] isEqual:[type typecode]]) {
[[type alloc]initWithFile:file withStartOffset:i]; //warning here;
//yes I plan to assign it to a variable
//(originally of "type" but that won't work as AliSoftware pointed out, will be using "id" instead.
...
}
}
}
与实例,我试图实例化一个连接对象。
代码协议:
#import <Foundation/Foundation.h>
@protocol ConcreteBox
+ (NSString *) typecode;
- (id) initWithFile: (NSFileHandle *) aFile withStartOffset: (uint64_t) theOffset;
@end
的问题是没有多少明确的。请给出实际的代码,应该有助于理解问题。 – objectivecdeveloper
添加实际代码。 – WanderingInLimbo
我没有看到你提供的问题。你能提供实际的班级定义吗?如果可能的话,你会得到实际的错误吗? –