How can we implement singleten design pattern in iphone code [duplicate] - iphone

This question already has answers here:
What should my Objective-C singleton look like? [closed]
(26 answers)
Closed 8 years ago.
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.

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

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

Related

Obj-C to swift in xcode [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am a swift newbie. I have an old app in obj-c, I would like to translate it to swift. Despite what I read, I am not quite sure how to use the convert to swift feature in Xcode. Can some one give me some guidances? Thanks. I am mainly confused about how the .h and .m on the obj-c side merge into one .swift file. In the .h file, I have a lot of variables and IBOutlets and IBActions declared. How does these all translate to the swift side. Thanks
AFAIK there is no convert Objective C to swift code feature in Xcode. There is only a convert from Swift X to newer Swift Y features.
That said. The .h file is the header file of your objective c. These are the methods and properties that other objects in your code can call on that specific class.
Swift has a similar feature but its all in the Swift file. If you mark a function as private then its roughly equivalent to a method being in the .m file but NOT in the .h file.
However, when you're just getting started with swift, don't sweat it too much. Use the default func declaration in place of -( declaration in objective c and just forget about the .h file for now. This will expose all functions and properties as if they were in the .h file in Objective C. But while you're getting started, thats the easier, more permissive way. Once you get more experienced you can start marking functions and methods as private and then they will no longer be exposed to other parts of your code.

Where should I create the Core Data Stack [duplicate]

This question already has answers here:
Where to place the "Core Data Stack" in a Cocoa/Cocoa Touch application
(6 answers)
Closed 9 years ago.
I want to add core data to my app. should i need to add the core data methods in app delegate .h and .m files after adding the framework. please help
I prefer to create the core data stack later on in a view controller.
The examples and the templates create it for you in the AppDelegate. If you don't know how to do it, just create a dummy project with Core data and copy the boilerplate over.

how to define same macro but different value depending on platforms? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there a specific Xcode compiler flag that gets set when compiling for iPad?
I want to define same macros but different values depending on whether its ipad or iphone. For example, i want define THUMB_WIDTH for iphone is 40 but for ipad is 100. Is this possible? If possible, how to do?
Yes, it's possible. First, you have to understand that the macro is just some code that will be replaced in your code at compile time.
I think that you want an universal app (iPhone/iPad), that means that you will have the same code compiled and shared for both platforms. So you cannot use a #if macro to change this value. The logic part have to be in the macro, this way the value is know at execution time and will change depending if you execute on iPhone or iPad.
You can use something like to do it:
#define THUMB_WIDTH (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) ? 40 : 100

I want to pass data between two UIViewControllers in my universal app [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
UISplitViewController Master / Detail communication
For iPad i am using UISplitViewController,for phone i m using navigation controller,i am unable to find a common way to pass object from master to detail view controller.
You're looking for what's called Delegation. Check here for my previous SO Answer and quick example , also includes a Link to Apple's Documentation on Delegates and Data Sources. Objective C View to Controller Communication
Hope this helps.

iPhone adding blur effect to image [duplicate]

This question already has answers here:
How to implement a box or gaussian blur on iOS
(7 answers)
Closed 9 years ago.
I have browsed stack for this so common issue, and have found that there is no default function to add blur effect to UIImage, and in order to make it one would have to manipulate individual pixels... I presume there are many advanced users who have tried and accomplished this. Does anyone have code to this, or some really specific pointers how this should be done?
Here's an iOS image filter library which you could possibly use.
https://github.com/esilverberg/ios-image-filters
an other one could be this: Filtrr for iOS