0

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.

Error enter image description here

Shadowrun
  • 3,572
  • 1
  • 15
  • 13
Alwaysblue
  • 9,948
  • 38
  • 121
  • 210
  • Recommended reading: [Encapsulating Data](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html#//apple_ref/doc/uid/TP40011210-CH5-SW2) in [Programming with Objective-C](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011210-CH1-SW1). – Willeke Jun 10 '21 at 10:42
  • 2
    `self.authToken = authToken;` is syntactic sugar for `[self setAuthToken:authToken];`. Your override of `setAuthToken:` is recursive. – Willeke Jun 10 '21 at 10:45

1 Answers1

2

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

Shadowrun
  • 3,572
  • 1
  • 15
  • 13