2

So I have created a jpeg file using the Facebook graph url with a user id in ViewControllerA. This image is saved as profilePicture. My question is how do I make this image (UIImage) global?

In other words, I just want to make this image available to any ViewController or other type of class that I make, outside from ViewControllerA. I am not sure if making it global or public will be more appropriate, I just need the best way to make it accessible from any controller. thanks for the help!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Brennan Casey
  • 887
  • 2
  • 7
  • 17

2 Answers2

1

You can declare a property in AppDelegate class

In Objective C :

#import <UIKit/UIKit.h>
@property(nonatomic,strong)UIImage *yourImage;

And Access it Like

[(AppDelegate *)[[UIApplication sharedApplication] delegate] yourImage]

In Swift >=1.2:

import UIKit
var UIImage *yourImage

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

appDelegate.yourImage

In Swift < 1.2

let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
appDelegate.yourImage
Babul Prabhakar
  • 2,373
  • 1
  • 18
  • 25
1
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
ViewControllerB *vcb = segue.destinationViewController;
vcb.Bpic = profPicture;
}

Set up a

 @property (nonatomic, retain)  UIImage *pic;

in ViewControllerA. Set up a property like this in B and then set the background as profPicture.

This is a simple way to have it go from 1 VC to another. Apply this to where ever you need. Hope this helps!

Will Von Ullrich
  • 2,129
  • 2
  • 15
  • 42