Asked 7 years ago
7 Jan 2017
Views 1568
ajamil

ajamil posted

difference between #import and #include in Objective-C?

it seems #import and #include both do same job , #import and #include both do include header file . so why one made two function do the same work.

so is there any difference between #import and #include ? or #import and #include are same .
fatso

fatso
answered Nov 30 '-1 00:00

#import is like include once . means it will include file only one time in program life
#import "classic_lib.h" means its will load classic_lib only once in time in program life.

it means if you #include "class_lib.h" more than one time in program compiler will generate error ,
and if you put #import "class_lib.h" more than one time in program than compiler will not generate error . but simply ignore it to import it second time.

please Note :: #include "swift_imporver.h" two time not give you error but it included function and code give you error suppose like if swift_imporver.h have function swift_imporver , when it include second time and try to initialize same function again . it give error .
[b]in objective C it means #import , skip second import of same file and include really include rather less it second time or first of time of that file , include will not skip it./b]



to avoid error by include "class.h"( including same file multiple time) , put usual header gards (#ifndef FILE_NAME_H #define FILE_NAME_H #end) so it will not generate error .
Phpworker

Phpworker
answered Nov 30 '-1 00:00

i thin #import will used to import library and include for one file which is need to include in objective c
Post Answer