Array enumerieren ?

  • Array enumerieren ?

    Hallo,
    ich habe ein Problem mit der Abzählung eines Arrays.

    MainController.h

    Quellcode

    1. @interface MainController : NSObject
    2. {
    3. NSArray *array;
    4. }
    5. -(IBAction)fastEnumerateArray:(id)sender;
    6. @end


    Maincontroller.m

    Quellcode

    1. - (void)awakeFromNib
    2. {
    3. array = [NSArray arrayWithObjects:@"One", @"Two", @"Three", @"Four", nil];
    4. }
    5. - (IBAction)fastEnumerateArray:(id)sender
    6. { for (NSString *element in array)
    7. { NSLog(@"element: %@", element); }
    8. }


    Wenn ich das Array in 'awakeFromNib' initialisiere, stürzt das Programm mit folgender Fehlermeldung ab.

    [Session started at 2009-12-12 16:55:23 +0100.]
    GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all
    Attaching to process 2346.
    (gdb)


    Wenn ich das Array in der 'IBAction'-Methode initialisiere funktioniert der Code.

    Kann mir jemand erklären warum das so ist ?

    Gruß Michael
  • Original von MichaelP
    Danke, Danke, Danke.
    Speicherverwaltung !!! Genau das wars.

    Ich muss unbedingt das Kapitel in 'Objective-C und Cocoa' noch einmal durcharbeiten.

    Gruß Michael

    Ist in diesem Falle einfach: Nur mit einem Setter zuweisen!
    Es hat noch nie etwas gefunzt. To tear down the Wall would be a Werror!
    25.06.2016: [Swift] gehört zu meinen *Favorite Tags* auf SO. In welcher Bedeutung von "favorite"?