我想将 4 个来自 url 的书名(.php?info=1& b=1第一本书的显示名称)存储在数组中,然后运行该代码并使用这些名称。
我也想创建类的对象并将名字专用于第一个对象(第二个名称用于第二个对象等)
这是我的代码:
#import "Recipe.h"
for (int i = 1; i <= 4; i++)
{
Recipe *booki = [Recipe new]; // create object
NSLog(@"%d,%@",i,booki);
NSString *c = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.102:81/temp/book.php?info=1&b=%d",i]]];
NSMutableArray *b = [[NSMutableArray alloc]init];
[b addObject:c];
NSLog(@"%@,%@",c,b);
booki.name = [NSString stringWithString:c];
recipes = [NSMutableArray arrayWithCapacity:4];
//NSLog(@"%@",recipes);
recipes = [NSMutableArray arrayWithObjects:booki, nil];
在这段代码中,我在对象中只看到一个名字和它的书名