Hi,
This is probably a bit of a noob question but here goes.
My app has some constant/global variables that are set from the off and some that require setting during an authentication process such as a token. I'm having trouble with the getting/setting of external variables and it's possible I'm going about this completely the wrong way. I've re-created my code in a really simple example app to demonstrate:
constants.h
constants.m
View Controller Implementation:
So I *think* the string should be outputted to NSLog and also available to any other methods in the app, but it isn't. I'm pretty sure my initialisation of the string in the getter is wrong, but I'm not sure what to do about it.
Help anyone?
Many thanks,
This is probably a bit of a noob question but here goes.
My app has some constant/global variables that are set from the off and some that require setting during an authentication process such as a token. I'm having trouble with the getting/setting of external variables and it's possible I'm going about this completely the wrong way. I've re-created my code in a really simple example app to demonstrate:
constants.h
Code:
#import <Foundation/Foundation.h>
extern NSString *myConstString;
extern NSString *const anotherConstString;
@interface constants : NSObject {
}
+(void)setString:(NSString*)withString;
+(NSString*)getString;
@end
constants.m
Code:
#import "constants.h"
@implementation constants
NSString *const anotherConstString = @"12345678";
+(void)setString:(NSString*)withString{
NSString *myConstString = [[NSString alloc] initWithString:withString];
}
+(NSString*)getString{
NSString *myConstString2 = [[NSString alloc] init];
return myConstString2;
}
@end
View Controller Implementation:
Code:
#import "stringTestViewController.h"
#import "constants.h"
@implementation stringTestViewController
-(IBAction)stringTest{
[constants setString:@"1234"];
NSString *returnedString = [constants getString];
NSLog(@"The string is %@", returnedString);
}
So I *think* the string should be outputted to NSLog and also available to any other methods in the app, but it isn't. I'm pretty sure my initialisation of the string in the getter is wrong, but I'm not sure what to do about it.
Help anyone?
Many thanks,