Question

I had a previous question about whether or not I could add SpriteKit to an Empty Application. Now that I know that this is possible, I had one more question. I have added the SpriteKit.framework to the correct area in Xcode.

enter image description here

After this, do I have to add the framework to my .pch file? If this turns out to not be necessary, will it increase performance?

Here is my current .pch file.

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <SpriteKit/SpriteKit.h> // do I have to / should I do this?
#endif

Is the #import necessary

Était-ce utile?

La solution

It's entirely optional but recommended. The main benefit is that you don't need to import the header in every file using Sprite Kit classes.

A nice side effect is faster compilation, but since Sprite Kit is a framework, most SK apps don't exceed 100,000 lines of code and Xcode's module system (sort of a cache for frameworks) it will hardly make a noticeable difference in terms of compilation time. It has absolutely no effect on runtime performance or app size.

In other words there is nothing to lose but very little gain, so do it because it's just one line of code.

Autres conseils

Adding #import or #include to your prefix.pch file only makes the imported file available in all the project. That is, after #import <SpriteKit/SpriteKit.h> you can acces to the framework within all the .h and .m files on your app.

As far as I know, there is neither a performance difference nor other type of difference between importing a file or a framework in the .pch or doing it in each file you want to use, because during compilation the preprocessor compiles the .pch imports in the same exact way that if you have manually written the imports in each file.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top