Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am now creating cocoapod library. If I want to load json,png and other xib files, I need to use [NSBundle bundleForClass:[self class]]] instead of using main bundle. I wanted to know is this recommend way to do like this and what does that mean?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
413 views
Welcome To Ask or Share your Answers For Others

1 Answer

Apple uses bundles to represent apps, frameworks, plug-ins, and many other specific types of content. Bundles organize their contained resources into well-defined subdirectories, and bundle structures vary depending on the platform and the type of the bundle.

-[NSBundle bundleForClass:] gives you the bundle for a given class.

For example:

AwesomeApp:
 AppController
 FrameworkA:
  FrameController

Calling in the AppController -[NSBundle bundleForClass:[self class]] would return the AwesomeApp.app bundle. And within FrameController it would return the FrameworkA.framework-


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...