0

I want to implement singleten design pattern in iphone code

I have one array. I want it to retain its value between function calls of from single class function.

How Can I use singleten design pattern to do above task? Thanks.

Nic
  • 221
  • 4
  • 12

2 Answers2

3

better you can initialize it in appdelegate of your project. then you can access this array anywhere in your project.

#define UIAppDelegate ((yourAppDelegate *)[UIApplication sharedApplication].delegate)

include this in your your appDelegate, then you can access your array any where you want.

UIAppDelegate.yourArray
Rahul
  • 66
  • 2
1

Matt Gallagher has a pretty good writeup, with a very simple to use preprocessor macro to set create a singleton for class:

http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html

duncanwilcox
  • 3,498
  • 21
  • 18