• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Creating shared classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Creating shared classes


  • Subject: Creating shared classes
  • From: Graham Wihlidal <email@hidden>
  • Date: Wed, 18 Jul 2001 00:52:24 -0600

I have a problem. I am trying to learn how to call class functions from different classes. I originally was just using one large class for everything just to get the real basics, and am not expanding to better code structure, etc...

I have placed the code from my test below and am trying to call setUsername from the UserSession class and then print out the value using Username from that same class. All called from main.m It seems to compile with no warnings or errors, but the message is never received by the class (the NSLog I placed in the setUsername function is never called)

Any ideas?

TIA,

Graham


-- Code follows:


/// main.m

#import <Cocoa/Cocoa.h>
#import "UserSession.h"

int main(int argc, const char *argv[])
{
[[UserSession sharedUserSession] setUsername:@"Lord Storm"];
NSLog([[UserSession sharedUserSession] Username]); // Always prints out blank text
return NSApplicationMain(argc, argv);
}



/// UserSession.h

#import <Cocoa/Cocoa.h>

@interface UserSession : NSObject {
NSMutableString* sessionUsername;
}

+ (UserSession*)sharedUserSession;
- (NSMutableString*)Username;
- (void)setUsername:(NSString*)newUsername;
@end



/// UserSession.m

#import "UserSession.h"

static UserSession* mainUserSession;

@implementation UserSession

- (id)init {
if (self=[super init]) {
mainUserSession=self;
}
return self;
}

+ (UserSession*)sharedUserSession {
return mainUserSession;
}

- (NSMutableString*)Username {
return sessionUsername;
}

- (void)setUsername:(NSString*)newUsername {
NSLog(@"Got goodness");
[sessionUsername setString:newUsername];
}

@end


  • Prev by Date: Re: Collection of Cocoa & objc questions from a "newbie"
  • Next by Date: Re: Creating shared classes
  • Previous by thread: Re: catching an option-return
  • Next by thread: Re: Creating shared classes
  • Index(es):
    • Date
    • Thread