Error importing implementation file .m

I tried to import the .m file to use the static variable declared there in another class.

#import "Faculty.m"

I received the error message "There is no such file or directory." Now it may be a bad programming practice to declare variables in .m implementation files, but just out of curiosity, what kind of error is this? Does the .m file really exist? Why "No such file" then?

+3
source share
4 answers

, , , *.hmap, . Xcode *.h.

(, , " "), *.m , , #import.

+7

, .m - , , , , . , Faculty.m , .

, , , . , , , , . , , , #include #import - . , Faculty.m "foo", Student.m Administrator.m, Faculty.m "foo", Student.m "foo" Administrator.m "foo".

, , - Faculty.m, extern Faculty.h .m, import Faculty.h.

+2

:

#import "Faculty.h"

Falculty:

// Faculty.h
@interface Faculty : NSObject {
}
+ (VarType*)variable;
+ (void)setVariable:(VarType*)newVariable;
@end

// Faculty.m
#import "Faculty.h"

static VarType* variable;

@implementation Faculty

+ (VarType*)variable {
    return variable;
}

+ (void)setVariable:(VarType*)newVariable {
    if (variable != newVariable) {
        [variable release];
        variable = [newVariable copy];
    }
}
@end
+1

Usually ".m" files (module) are not imported. Instead, you import the ".h" files (header), which contain class and method declarations. They contain enough information to give the compiler an idea of ​​how to make everything work.

0
source

Source: https://habr.com/ru/post/1776560/


All Articles