Get access to integer and string globally in iphone?

I want to access an integer and a string from a class to all other classes? What is the best way to do this? I want the values ​​to be incremented anywhere in the program, and then want to update them in the declared class ....

any idea how to achieve this ???

+3
source share
2 answers

Here's a question (and good answers) about singletones .

You can also use the application delegate, as frankodwyer suggested, and access it from anywhere using:

id delegate = [[UIApplication sharedApplication] delegate];

For ease of use and type safety, I use this category:

// put his in your delegate header file
@interface UIApplication(MyAppAdditions)
+ (MyAppDelegate*)sharedDelegate;
@end

// put his in your delegate implementation file
@implementation UIApplication(MyAppAdditions)
+ (MyAppDelegate*)sharedDelegate {
    return (MyAppDelegate*)[[self sharedApplication] delegate];
}
@end

: [UIApplication sharedDelegate]

+5

. - , , , , , .

( , , ), (google singleton pattern) integer/string. / . , ,

+2

Source: https://habr.com/ru/post/1711809/


All Articles