Reputation: 11830
In my AppDelegate.m, I am doing something like this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
@try {
// initalizing Meeting config
MeetingConfig *config = [[MeetingConfig alloc] init];
NSLog(@"Initalized Meeting Config: %@", config);
[config setRoomName:@"test123"];
NSLog(@"SetRoom name for Meeting config: %@", config.roomName);
NSString *clientId = @"";
NSLog(@"Unused Client id is: %@", clientId);
//Call UIView from here
}@catch (NSException *exception) {
NSLog(@"exception: %@", exception);
}
return YES;
}
Where my MeetingConfig.m file looks like this
@implementation MeetingConfig
- (id) init
{
if (self = [super init]) {
self.apiBase = @"https://api.in";
self.showSetupScreen = false;
self.autoTune = true;
}
return self;
}
- (void) setAuthToken:(NSString *)authToken
{
self.authToken = authToken;
}
- (void) setApiBase:(NSString *)apiBase
{
self.apiBase = apiBase;
}
// more code
and MeetingConfig looks like this
#import <Foundation/Foundation.h>
@interface MeetingConfig : NSObject
@property (nonatomic, assign) NSString* roomName;
@property (nonatomic, assign) NSString* authToken;
@property (nonatomic, assign)Boolean autoTune;
@property (nonatomic, assign)NSString* apiBase;
@property (nonatomic, assign)Boolean showSetupScreen;
- (void) setRoomName:(NSString *)roomName;
- (void) setAuthToken:(NSString *)authToken;
- (void) setShowSetupScreen:(Boolean)showSetupScreen;
- (void) setAutoTuneEnabled:(Boolean)autoTune;
- (id) init;
@end
Can someone help me in determining what I could be doing wrong here? and why doesn't it log exception in NSLog? Also, I am super new to objective C (i have been asked to stick with Objective c) and if anyone have any suggestion in regards to the code then please let me know.
Upvotes: 0
Views: 39
Reputation: 3857
You're using assign for reference/pointer types: @property retain, assign, copy, nonatomic in Objective-C
They should probably be declared copy, because this is a kind of value object, I think.
No exceptions were caught because no exceptions were thrown. Throwing/catching exceptions for control flow is not common in Objective-C
You don't need to write explicit setter functions for @properties
You should prefer to use BOOL type instead of Boolean, with values of YES/NO instead of true/false.
You should return instancetype not id from init, at least in reasonably modern Objective C
Consider making an initialiser that takes all the properties (initWithRoomName:clientID:) and make them read only once set
You don't need to declare -(id) init in your header since it gets that from NSObject
Upvotes: 2