Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:43:13+00:00 2026-06-11T20:43:13+00:00

I have use a singleton class that contained just one passed value. I then

  • 0

I have use a singleton class that contained just one passed value. I then tried to add another one.

#import <Foundation/Foundation.h>

@interface GlobalValueContainer : NSObject {


    NSString *passedText;
    NSString *myPassedPictureName;
}


@property (nonatomic, strong) NSString* passedText;
@property (nonatomic, strong) NSString* myPassedPictureName;


+ (GlobalValueContainer *) sharedStore;

@end


#import "GlobalValueContainer.h"

@implementation GlobalValueContainer;

@synthesize passedText;
@synthesize myPassedPictureName;

static GlobalValueContainer *sharedStore = nil;


+ (GlobalValueContainer *) sharedStore {
    @synchronized(self){
        if (sharedStore == nil){
            sharedStore = [[self alloc] init];
        }
    }

    return sharedStore;
}


@end

From the first view I then try to set the myPassedPictureName

-(IBAction)setPicture:(id)sender{

    myPicture = @"Hus";
    GlobalValueContainer* localContainer = [GlobalValueContainer sharedStore];
    localContainer.myPassedPictureName = myPicture;


}

and on the second view I want to set an imageview with that name (+png that is)

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Store* myStore = [Store sharedStore];


    GlobalValueContainer* localContainer = [GlobalValueContainer sharedStore];
    myPassedPictureName = localContainer.myPassedPictureName;
    myPicture.image = [UIImage imageNamed:myPassedPictureName];
    whatFile.text = myPassedPictureName;

   //object.imageView.image = [UIImage imageNamed:@"downloadedimage.png"];

}

the picture doesnt show. I have also tried to add a UIlabel and set the string that should have been passed. But it also turns out blank.

When I pass text using the “passedText” it works fine. When I added the second NSString, nothing happens?.

First things first. Can anyone see what´s wrong (still learning obj c here 🙂 and, is it the correct way I try to manipulate an UIImageView. I want to use the myPassedPictureName to set a picture on a number of UIViews depending on the button being pressed.

Looking forward to your input.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:43:14+00:00Added an answer on June 11, 2026 at 8:43 pm

    I’m quite sure using singleton for passing value like this is not a good idea.Singleton is not designed for passing value,but for doing something.So you can not use Property like

    sharedManager.passValue
    Here has some good discussion about singleton.
    When should you use the singleton pattern instead of a static class?
    and
    What should my Objective-C singleton look like?

    So I suggest write it like this:

    #import <Foundation/Foundation.h>
    
    @interface GlobalValueContainer : NSObject {
    
    }
    
    + (id) sharedManager;
    -(NSString*)myText;
    -(NSString*)myPictureName;
    
    @end
    
    
    #import "GlobalValueContainer.h"
    
    @implementation GlobalValueContainer;
    
    
    static GlobalValueContainer *sharedManager = nil;
    
    
    + (id) sharedManager {
        @synchronized(self){
            if (sharedManager == nil){
                sharedManager = [[self alloc] init];
            }
        }
    
        return sharedManager;
    }
    
    -(NSString*)myText
    {
        return @"your text";
    }
    -(NSString*)myPictureName
    { 
        return @"yourPictureName.png";
    }  
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a singleton object that use another object (not singleton), to require some
I have a C# singleton class that multiple classes use. Is access through Instance
i make one class file for jar. and this class have use wurfl. and
I have an object, based on the Singleton design, that I use for user
I have a class that is managed by ninject as a singleton that looks
I have just re-implemented an ASP.NET web application that uses NHibernate to use a
I have a singleton class that is shared by some threads. within a method
I have a JavaScript Websockets implementation where I would like to use a singleton
I have tried many PHP MVC frameworks and I noticed that in many frameworks
I have created a hashmap in a singleton class, we will call it Class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.