Search code examples
iosimportreachability

Reachability.m - File not found - Odd behavior


I have two files which are of relevance: CollectionViewController.m and ImageDetailViewController.m

For CollectionViewController.m, the "#import "Reachability.m" + functionality works just fine. I have added all Frameworks as well.

However, when trying to import the Reachability.m file in my ImageDetailViewController.m as well, I get the "Reachability.m - File Not Found"-error. I don't understand why this is happening. Both files are in the same group, folder everything.

CollectionViewController.m ImageDetailViewController.m

Has anyone come across this? I'd appreciate a solution, this is driving me Crazy!


Solution

  • You generally don't import Reachability.m, only required files to be imported are having .h extensions called header files. Problem with importing .m files would be that compiler might not be able to find the .m file and would complain.

    I would recommend you to use forward declarations its quite faster way of building your code and indexing it, You can add the class like this in your code

    CollectionViewController.h

    @class Reachability; in your CollectionViewController.h Header file

     @property(strong,nonatomic)Reachability *reachability; // here you are declaring a property
    

    CollectionViewController.m

    `#import "Reachability.h"` //only .h file is required to be imported
    

    now you can use the reachability property in your class by self.reachability