Чтобы получить доступ к listOfSites
из других классов, вам нужно сделать его свойством этого класса:
В файле MyClass.h
@interface MyClass : NSObject
// ...
@property (strong, nonatomic) NSMutableArray *listOfSites;
// ...
@end
Тогда у вас естьсинтезировать в MyClass.m
файле
@interface MyClass
@synthesize listOfSites;
// ...
@end
Теперь, если вы импортируете MyClass.h
в другой класс, вы можете получить доступ к свойству listOfSites
.Например, в другом файле OtherClass.m
:
#import "MyClass.h"
// ...
- (void)someMethod {
MyClass *item = [[MyClass alloc] init];
item.listOfSites = [[NSMutableArray alloc] init];
// ...
}
Вы допустили много ошибок в размещенном коде.(Даже если вы правильно объявили listOfSites
как свойство).
Сначала измените строку:
NSMutableArray *listOfSites = [[NSMutableArray alloc] init];
на:
listOfSites = [[NSMutableArray alloc] init];
Во-вторых, вследующие строки:
slSQLite *dbCode = [[slSQLite alloc] init]; // Create an object
[dbCode getListOfSites]; // Generate the content of listOfSites
// put site data into array for display
slSQLite *item = [[slSQLite alloc] init]; // Create another object
NSLog(@"\n2-The array listOfSites contains %d items", item.listOfSites.count); // Log the length of listOfSites in this new object
вы генерируете содержимое listOfSites
для объекта dbCode
и проверяете длину listOfSites
в item
, который является другим объектом и для которого вы не сделалине генерировать содержимое listOfSites
.
Попробуйте выполнить следующее:
slSQLite *dbCode = [[slSQLite alloc] init]; // Create an object
[dbCode getListOfSites]; // Generate the content of listOfSites
NSLog(@"\n2-The array listOfSites contains %d items", dbCode.listOfSites.count); // Log the length of listOfSites in dbCode