开发者

Objective-C newbie question re: global instances

Is there a way to make one (1) instance of an object and share that instance between different files?

For instance, I have Class "A" (created in fileA.m), and I create an instance of it in a different file (fileB.m). Now, I want to use that same instance created in fileB.m in several other files (fileC.m and fileD.m) so I can share ivar's (s开发者_Python百科uch as a database).

How do I do that?


You would want Class A to be a singleton. Here's a great guide to help you out with that.


You need to use a static class method as a constructor which will return a singleton instance of the object you're looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜