2 Questions, one about a problem with my app now and another unimportant one:
1)
I have a document based application with 2 classes:
My problem is at the end of the first class' implementation, it has two 'semantic' errors for this line (which used to assign before I reduced it to a variable declaration)
Lesson *newLesson; //Error 1 is "use of undeclared identifier 'Lesson' ", 2 is "use of undeclared identifier 'newLesson' "
I don't understand why because Lesson is a class name and is not an iVar. Help!
2)
What the the header file @interface method declarations do? Why are they important? I ask because the documentation says it is necessary but when I create a document based app (as shown above) it sets up methods in @implementation with declaring them in the header, it also seems to work.
Thanks in advance for replies or even a solution!
1)
I have a document based application with 2 classes:
Code:
#import <Cocoa/Cocoa.h>
@interface LPDocument : NSDocument {
NSMutableArray *lessonArray;
}
@property(retain) NSMutableArray *lessonArray;
-(IBAction)createNewLesson:(id)sender;
@end
#import "LPDocument.h"
@implementation LPDocument
@synthesize lessonArray;
- (id)init
{
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
}
return self;
}
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"LPDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
/*
Insert code here to write your document to data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning nil.
You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
*/
if (outError) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
return nil;
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
/*
Insert code here to read your document from the given data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning NO.
You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
If you override either of these, you should also override -isEntireFileLoaded to return NO if the contents are lazily loaded.
*/
if (outError) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
return YES;
}
+ (BOOL)autosavesInPlace
{
return YES;
}
-(void)createNewLesson:(id)sender
{
Lesson *newLesson;
//newLesson [Lesson lessonWith];
}
@end
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
@interface Lesson : NSObject {
NSString *title;
NSDate *creationDate;
NSArray *keyPoints;
NSTextStorage *notes;
}
@property(retain) NSString *title;
@property(retain, readonly) NSDate *creationDate;
@property(retain) NSArray *keyPoints;
@property(retain) NSTextStorage *notes;
+ (Lesson *)lessonWithTitle:(NSString *)newTitle keyPoints:(NSArray *)newKeyPoints notes:(NSTextStorage *)newNotes;
@end#import "Lesson.h"
@implementation Lesson
@synthesize title, creationDate, keyPoints, notes;
+ (Lesson *)lessonWithTitle:(NSString *)newTitle
keyPoints:(NSArray *)newKeyPoints
notes:(NSTextStorage *)newNotes
{
Lesson *newLesson = [[[self alloc] init] autorelease];
newLesson.title = newTitle;
newLesson.keyPoints = newKeyPoints;
newLesson.notes = newNotes;
return newLesson;
}
- (id)init
{
self = [super init];
if (self) {
creationDate = [NSDate date];
}
return self;
}
@end
My problem is at the end of the first class' implementation, it has two 'semantic' errors for this line (which used to assign before I reduced it to a variable declaration)
Lesson *newLesson; //Error 1 is "use of undeclared identifier 'Lesson' ", 2 is "use of undeclared identifier 'newLesson' "
I don't understand why because Lesson is a class name and is not an iVar. Help!
2)
What the the header file @interface method declarations do? Why are they important? I ask because the documentation says it is necessary but when I create a document based app (as shown above) it sets up methods in @implementation with declaring them in the header, it also seems to work.
Thanks in advance for replies or even a solution!
Last edited: