ios 在转发类对象中找不到属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8577457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Property cannot be found in forward class object
提问by Spencer Cole
I'm adapting This tutorialto my app, and I've got it boiled down to one last error, which is stopping me in my tracks. The program is unable to find a property in another file, but that property is clearly defined. Here is the code in question:
我正在将本教程改编为我的应用程序,我已经把它归结为最后一个错误,这让我无法正常工作。程序无法在另一个文件中找到属性,但该属性已明确定义。这是有问题的代码:
The actual error line:
实际的错误行:
for (DTContact *dtc in _dtContact.contact) {
the .h for the file, and items in question:
文件的 .h 和相关项目:
#import <UIKit/UIKit.h>
@class XMLTestViewController;
@class DTCXMLResponse;
@interface XMLTestController : UIViewController{
UIWindow *window;
XMLTestViewController *viewController;
DTCXMLResponse *_dtContact;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet XMLTestViewController *viewController;
@property (nonatomic, retain) DTCXMLResponse *dtContact;
@property (nonatomic, retain) IBOutlet UIButton *mybutton;
-(IBAction)buttonClicked;
@end
It's having issues with the _dtContact.contact. It can't find the contact in the file DTCXMLResponse. Here is the .h file and the section of the .m:
_dtContact.contact 有问题。它在文件 DTCXMLResponse 中找不到联系人。这是 .h 文件和 .m 的部分:
.h
。H
#import <Foundation/Foundation.h>
@interface DTContactXMLResponse : NSObject {
NSMutableArray *_contact;
}
@property (nonatomic, retain) NSMutableArray *contact;
@end
.m
.m
#import "DTCXMLResponse.h"
@implementation DTContactXMLResponse
@synthesize contact = _contact;
- (id)init {
if ((self = [super init])) {
self.contact = [[NSMutableArray alloc] init];
}
return self;
}
@end
So theres that. As you can see, I have 'contact' propertied in the DTCXMLResponse.h, and linked in the .m.
所以就是这样。如您所见,我在 DTCXMLResponse.h 中有“联系”属性,并在 .m 中链接。
回答by shannoga
This error usually points out that Xcode can not recognize your symbol. I can assume this is DTContact.
此错误通常指出 Xcode 无法识别您的符号。我可以假设这是 DTContact。
Try to insert this in your .h file:
尝试将其插入到您的 .h 文件中:
#import DTContact.h
回答by Priyanka
Its not relevant to ur case but I was getting the same error. I googled for a solution but the problem was in my code. I was using different class object as I was copy pasting similar snippet of code in my project. So here is the problem that I had for the same error :
它与您的案例无关,但我遇到了同样的错误。我用谷歌搜索了一个解决方案,但问题出在我的代码中。当我在项目中复制粘贴类似的代码片段时,我使用了不同的类对象。所以这是我遇到相同错误的问题:
For my classA , I had some code snippet like :
对于我的 classA ,我有一些代码片段,例如:
ManagedObjectOfClassA * managedObjectOfClassA = [NSEntityDescription insertNewObjectForEntityForName:@"ManagedObjectOfClassA" inManagedObjectContext:managedObjectContext];
managedObjectOfClassA.somePropertyA = sameValue; //somePropertyA is an attribute of ManagedObjectOfClassA
And similar code for class B :
和 B 类的类似代码:
ManagedObjectOfClassA *managedObjectOfClassB = [NSEntityDescription insertNewObjectForEntityForName:@"ManagedObjectOfClassB" inManagedObjectContext:managedObjectContext];
managedObjectOfClassB.somePropertyB = someValue;////somePropertyB is an attribute of ManagedObjectOfClassB
If u look closely, the mistake was in assigning the right entities to the corresponding objects in class B.
如果仔细观察,错误在于将正确的实体分配给 B 类中的相应对象。
So the problem is in code of class B. And the correct code would be :
所以问题出在 B 类的代码中。正确的代码是:
ManagedObjectOfClassB*managedObjectOfClassB = [NSEntityDescription insertNewObjectForEntityForName:@"ManagedObjectOfClassB" inManagedObjectContext:managedObjectContext];
ManagedObjectOf ClassB*managedObjectOfClassB = [NSEntityDescription insertNewObjectForEntityForName:@ "ManagedObjectOf ClassB" inManagedObjectContext:managedObjectContext];
managedObjectOfClassB.somePropertyB.someValue;
managedObjectOf ClassB。somePropertyB.someValue;
I hope that helps someone.
我希望能帮助某人。