Хотелось бы создать метод, который создает экземпляры объектов.
- (NSArray *) make3Of : (Class) type
{
...
type * temp = [[type alloc] ...
...
}
Но я получаю предупреждение от Xcode ...
Фактическое предупреждение: "Метод класса + alloc не найден (тип возвращаемого значения по умолчанию равен 'id')"
Есть ли лучший / правильный способ сделать это?
Фактический код:
- (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