Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.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
Ios 数组中的对象处理_Ios_Objective C_Xcode_Object_Nsmutablearray - Fatal编程技术网

Ios 数组中的对象处理

Ios 数组中的对象处理,ios,objective-c,xcode,object,nsmutablearray,Ios,Objective C,Xcode,Object,Nsmutablearray,我已经在这里阅读了一些关于类似问题的答案,但我仍然无法让代码正常工作 我试图将我的代码块保存在不同的部分,以便在使它们变得更复杂时进行调整 对象层次结构是PieceProperties——我正试图将其作为数组存储在PieceStartInfo中,其他函数可以使用PieceStartInfo.h. 计件属性.h #import <Foundation/Foundation.h> @interface PieceProperties : NSObject - (id)initWithDe

我已经在这里阅读了一些关于类似问题的答案,但我仍然无法让代码正常工作

我试图将我的代码块保存在不同的部分,以便在使它们变得更复杂时进行调整

对象层次结构是
PieceProperties
——我正试图将其作为数组存储在
PieceStartInfo
中,其他函数可以使用
PieceStartInfo.h.

计件属性.h

#import <Foundation/Foundation.h>
@interface PieceProperties : NSObject
- (id)initWithDetail:(NSInteger)PeiceID WithValue:(NSInteger)Value WithOwner:(bool)Owner WithShape:(NSInteger)Shape;

@property (nonatomic, readonly) NSInteger P_ID;
@property (nonatomic, readonly) NSInteger P_Value;
@property (nonatomic, readonly) bool P_True_Own;
@property (nonatomic, readwrite) bool P_Current_Own;
@property (nonatomic, readonly) NSInteger P_Shape;

@end
保持类标题

#import <Foundation/Foundation.h>
#import "PieceProperties.h"
NSMutableArray *PieceData;
@interface PieceStartInfo : NSObject{
}
- (id) initCreateArray;
@property (nonatomic, assign) PieceProperties *PieceData;
@end
那条线

IndividualData = [DataArray.PieceData objectAtIndex:2]
给出了错误

No visible @interface for 'PieceProperties' declares the selector 'objectAtIndex'

我的第一个想法是将
PieceProperties
改为从
NSMutableArray
派生出来,但我试了一下,它似乎没有什么帮助:(它针对的是带有Xcode Build 5.02的IOS 7.0)

您的代码中有很多问题。对于您当前的错误,您最好执行以下操作:

1) 将属性类型更改为NSMUTABLEARRY*,并将修饰符从
assign
更改为
strong

@property (nonatomic, strong) NSMutableArray *pieceDatas;
2) 将init更改为以下样式。您最好也更改PieceProperties类中的init方法

- (id)init
{
    self = [super init];
    if(self) {
        _pieceDatas = [[NSMutableArray alloc] initWithCapacity:60];

        NSInteger N_Val, N_Shape;
        bool N_Own;
        for(NSInteger i = 0; i<60;i++){
            if (i == 0){
            // a whole bunch of code defining the N_Val for each i
             }       
              N_Own = (i % 2 == 1);        
             PieceProperties *PInterest = [[PieceProperties alloc] initWithDetail:i WithValue:N_Val WithOwner:N_Own WithShape:N_Shape];
             [_pieceDatas addObject:PInterest];
        }
    }    
    return self.
}
-(id)init
{
self=[super init];
如果(自我){
_pieceDatas=[[NSMutableArray alloc]initWithCapacity:60];
NSInteger N_Val,N_Shape;
布尔诺自己;

对于(NSInteger i=0;iWell
PieceProperties
当然必须以某种方式继承自
NSArray
,因为它当前继承自的
NSObject
没有实现
objectAtIndex:。
这就是我从您的代码中所能知道的一切


这里面有很多让人困惑的东西,很难回答。但是,别忘了在
initCreateArray
中指定top实际属性在一个头中有两个相同的命名变量也不是一个好主意。老实说,我建议实现
NSDictionary
,这样你就可以在数组..这会让它更可读!很抱歉我帮不上更多的忙!

作为旁注,苹果建议您坚持使用实例变量和属性的命名约定。这听起来可能很迂腐,但在共享代码时,其他人可以更轻松地阅读您的代码。请看:谢谢,它确实解决了这一问题错误,因此现在代码编译时我遇到了其他问题(与内存释放相关),我承认目前我的代码相当糟糕,几乎没有内存控制。我会做到的。@Bookkeeper我很高兴它对你有帮助。你可以阅读一些有关objective c的内容,以便更快地学习它。如果你觉得我的答案可以回答你的问题,你也可以接受我的答案:)。哪些方面令人困惑,如果我得到反馈,它可能会帮助我清理代码并帮助防止错误。从逻辑上讲,NSdictionary是有意义的,尽管除了搜索我不需要的内容(我将始终知道我需要引用哪个实例)之外,我没有看到太多优势,或者我缺少其他因素?
No visible @interface for 'PieceProperties' declares the selector 'objectAtIndex'
@property (nonatomic, strong) NSMutableArray *pieceDatas;
- (id)init
{
    self = [super init];
    if(self) {
        _pieceDatas = [[NSMutableArray alloc] initWithCapacity:60];

        NSInteger N_Val, N_Shape;
        bool N_Own;
        for(NSInteger i = 0; i<60;i++){
            if (i == 0){
            // a whole bunch of code defining the N_Val for each i
             }       
              N_Own = (i % 2 == 1);        
             PieceProperties *PInterest = [[PieceProperties alloc] initWithDetail:i WithValue:N_Val WithOwner:N_Own WithShape:N_Shape];
             [_pieceDatas addObject:PInterest];
        }
    }    
    return self.
}