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

  • SEARCH
  • Home
  • 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 998705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:14:24+00:00 2026-05-16T07:14:24+00:00

I am trying to create an application were 2 classes share a variable. Just

  • 0

I am trying to create an application were 2 classes share a variable. Just to keep the code looking a little bit cleaner I created a 3rd class. This “third class” sole job is to house this variable.

In class 3 I put a “get” and “set” method.

SharedURL.H (Class 3)

@interface SharedURL : NSObject {
 NSString *theURL;
}
-(NSString *)getTheURL;
-(void)setTheURL:(NSString *)blah;
@property (readwrite, copy) NSString  *theURL;
@end

Implementation:

#import "SharedURL.h"


@implementation SharedURL

@synthesize theURL;

-(NSString *)getTheURL;
{
 return theURL;

}
-(void)setTheURL:(NSString *)blah;
{
 theURL=blah;

}
@end

In classes 1 and 2:
I Import the class header
I set up the instance variable like so

SharedURL *XMLURL;

I define the property like so

@property (readwrite, assign) SharedURL *XMLURL;

Then in the implementation I set the set method like this

[XMLURL setTheURL:@"http://localhost:8888/xml/MyXMLFile.xml"];

However whenever I implement the fallowing code the getter method returns nil.

NSLog(@” the url is %@”, [XMLURL getTheURL]);

How can I get this to actually save the variable that I imput and then return it. I’m looking at some sample code and i cannot find my error it looks to me like I am doing it perfectly fine I think I am overlooking something stupid.

  • 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-05-16T07:14:25+00:00Added an answer on May 16, 2026 at 7:14 am

    If I understand this right you are calling class 3 from either class 1 or 2 (lets say 1) and set the URL then your go to class 2 and and only ask for the URL, right?

    I think your problem is that you are calling something that is independent for each object. I think you can fix this by instead of saying -(NSString *)getTheURL and -(void)setTheURL you need to change it to +(NSString *)getTheURL and +(void)setTheURL (in both the .h and .m files) making it not variable dependent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Wikipedia's article on TCP suggests that the FIN/ACK packets are… May 16, 2026 at 4:57 pm
  • Editorial Team
    Editorial Team added an answer There's no clear rule of how to create and organize… May 16, 2026 at 4:57 pm
  • Editorial Team
    Editorial Team added an answer Try using Application.Exit(0); in the form_closing/form_closed event. Bug: I think… May 16, 2026 at 4:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am trying to create a site-specific browser application. I've created a new Cocoa
I'm trying to familiarize myself a bit more with database programming, and I'm looking
I'm trying to create a facebook application that is flash (actually flex 4.1) based.
I'm trying to create an android application which will generate random series of values
I am trying to create a very simple application (part of my learning program),
I am trying to create a Cocoa wrapper around a Flash application. I've got
I'm trying to create a Trial part of my cocoa application. I have the
I am trying to create a 1-2 second splashcreen for my application using a
I'm getting in trouble. I'm trying to emulate the call Application.Run using Application.DoEvents... this
I have an application that is already using the Spring Framework and Spring JDBC

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.