Ios 从UICollectionView的numberOfItemsInSection的plist中计算项目时调试/发布配置文件之间的差异

Ios 从UICollectionView的numberOfItemsInSection的plist中计算项目时调试/发布配置文件之间的差异,ios,build,plist,uicollectionview,initwithcontentsoffile,Ios,Build,Plist,Uicollectionview,Initwithcontentsoffile,我有一个UICollectionView,其collectionView:numberOfItemsInSection:定义如下: - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.contents.count; } - (NSArray *)contents { if (!_contents

我有一个UICollectionView,其collectionView:numberOfItemsInSection:定义如下:

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.contents.count;
}
- (NSArray *)contents
{
    if (!_contents) {
        _contents = [[XYZSharedMemoryStore sharedStore] clContents];
    }
    return _contents;
}
- (NSArray *)clContents
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cl_contents" ofType:@"plist"];
    NSArray *products = [[NSArray alloc] initWithContentsOfFile:path];
    return products;
}
+ (id)sharedStore
{
    static XYZSharedMemoryStore *sharedStore = nil;
    if (!sharedStore) {
        sharedStore = [[super allocWithZone:NULL] init];
    }
    return sharedStore;
}


+ (id)allocWithZone:(NSZone *)zone
{
    return [self sharedStore];
}


- (id)init
{
    self = [super init];
    if (self) {
        // STUFF
    }
    return self;
}
self.contents的延迟分配如下:

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.contents.count;
}
- (NSArray *)contents
{
    if (!_contents) {
        _contents = [[XYZSharedMemoryStore sharedStore] clContents];
    }
    return _contents;
}
- (NSArray *)clContents
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cl_contents" ofType:@"plist"];
    NSArray *products = [[NSArray alloc] initWithContentsOfFile:path];
    return products;
}
+ (id)sharedStore
{
    static XYZSharedMemoryStore *sharedStore = nil;
    if (!sharedStore) {
        sharedStore = [[super allocWithZone:NULL] init];
    }
    return sharedStore;
}


+ (id)allocWithZone:(NSZone *)zone
{
    return [self sharedStore];
}


- (id)init
{
    self = [super init];
    if (self) {
        // STUFF
    }
    return self;
}
clContents返回NSArray,如下所示:

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.contents.count;
}
- (NSArray *)contents
{
    if (!_contents) {
        _contents = [[XYZSharedMemoryStore sharedStore] clContents];
    }
    return _contents;
}
- (NSArray *)clContents
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cl_contents" ofType:@"plist"];
    NSArray *products = [[NSArray alloc] initWithContentsOfFile:path];
    return products;
}
+ (id)sharedStore
{
    static XYZSharedMemoryStore *sharedStore = nil;
    if (!sharedStore) {
        sharedStore = [[super allocWithZone:NULL] init];
    }
    return sharedStore;
}


+ (id)allocWithZone:(NSZone *)zone
{
    return [self sharedStore];
}


- (id)init
{
    self = [super init];
    if (self) {
        // STUFF
    }
    return self;
}
XYZSharedMemoryStore是定义如下的单例:

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.contents.count;
}
- (NSArray *)contents
{
    if (!_contents) {
        _contents = [[XYZSharedMemoryStore sharedStore] clContents];
    }
    return _contents;
}
- (NSArray *)clContents
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cl_contents" ofType:@"plist"];
    NSArray *products = [[NSArray alloc] initWithContentsOfFile:path];
    return products;
}
+ (id)sharedStore
{
    static XYZSharedMemoryStore *sharedStore = nil;
    if (!sharedStore) {
        sharedStore = [[super allocWithZone:NULL] init];
    }
    return sharedStore;
}


+ (id)allocWithZone:(NSZone *)zone
{
    return [self sharedStore];
}


- (id)init
{
    self = [super init];
    if (self) {
        // STUFF
    }
    return self;
}
循环一周,我遇到的问题是collectionView:numberOfItemsInSection:中的self.contents.count在发布配置文件中返回0,在调试模式下返回正确的数字(10),因此在发布配置文件中,我的UICollectionView不显示任何单元格。配置文件处于Xcode创建它们时的默认状态


有什么想法吗?

所以,这是一个程序员错误的案例

我将我的self.contents设置为弱引用,因此根据所有权利,它应该立即被释放,并且始终返回0计数。由于调试配置的优化级别为None[-O0],因此它没有立即解除分配,允许我使用它

版本配置设置为最快、最小[-Os],导致弱引用数组立即取消分配,不允许my UICollectionView获取其值


感谢Artur Ozierański的帮助。

尝试在目标的构建设置中找到优化级别属性,并将其在调试配置文件中切换到“-Os”(与发布版本相同)。如果问题将出现在调试模式中,我想这是内存相关的问题。好的,这肯定会导致调试配置文件的行为相同。内存相关,你说呢?是的,ARC行为可能与较低的优化级别略有不同,并且可能无法正确地(在适当的时间)发布内容。可能计数为0,因为self.contents为零。请检查一下,在调试中将opt level设置为-Os,这将给我们提供另一个线索:)是的,我在调试中将它设置为-Os,最初是从-O0开始的,问题发生了。降低发布概要文件的优化级别是否是不明智的?看起来还是有点奇怪。作为一个getter,self.contents应该是一个阻塞调用,通过为_contentsivar指定一个值来结束。。。