Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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_Fast Enumeration - Fatal编程技术网

Objective c 用于快速枚举的打印输出

Objective c 用于快速枚举的打印输出,objective-c,fast-enumeration,Objective C,Fast Enumeration,哪些代码行允许我们通过快速枚举打印迭代,而无需重复序言语句?我的代码如下: #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // Create an empty mutable array NSMutableArray *listGroceries = [NSMutableArray array];

哪些代码行允许我们通过快速枚举打印迭代,而无需重复序言语句?我的代码如下:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {

        // Create an empty mutable array
        NSMutableArray *listGroceries = [NSMutableArray array];

        // Add two dates to the array
        [listGroceries addObject:@"Container of milk"];
        [listGroceries addObject:@"Stick of butter"];

        // Add yesterday at the beginning of the list
        [listGroceries insertObject:@"Loaf of bread" atIndex:0];

        // How many dates are in the array?
        NSLog(@"There are %lu Groceries", [listGroceries count]);

        for (NSDate *d in listGroceries) {
            NSLog(@"My grocery list is: %@", d);
        }

    }
    return 0;
}
我如何使程序生成以下内容,而不在以后每行重复
我的购物清单

    My grocery list is:
    Loaf of bread
    Container of milk
    Stick of butter
以下是你的答案:

    int main(int argc, char * argv[]) {
    @autoreleasepool {

    // Create an empty mutable array
    NSMutableArray *listGroceries = [NSMutableArray array];

    // Add two dates to the array
    [listGroceries addObject:@"Container of milk"];
    [listGroceries addObject:@"Stick of butter"];

    // Add yesterday at the beginning of the list
    [listGroceries insertObject:@"Loaf of bread" atIndex:0];

    // How many dates are in the array?
    NSLog(@"There are %lu Groceries", [listGroceries count]);

    printf("My grocery list is: \n");

    for (NSString *d in listGroceries) {

        printf("%s \n", d.UTF8String);
    }


    return 0;
    }
}
使用printf()而不是NSLog,并应用有效的逻辑
    int main(int argc, char * argv[]) {
    @autoreleasepool {

    // Create an empty mutable array
    NSMutableArray *listGroceries = [NSMutableArray array];

    // Add two dates to the array
    [listGroceries addObject:@"Container of milk"];
    [listGroceries addObject:@"Stick of butter"];

    // Add yesterday at the beginning of the list
    [listGroceries insertObject:@"Loaf of bread" atIndex:0];

    // How many dates are in the array?
    NSLog(@"There are %lu Groceries", [listGroceries count]);

    printf("My grocery list is: \n");

    for (NSString *d in listGroceries) {

        printf("%s \n", d.UTF8String);
    }


    return 0;
    }
}