Learner Learner - 1 year ago 275
Objective-C Question

cannot assign to variable with const-qualified type

Im trying to change the value of SWSegueFrontIdentifier dynamically as follows because the the front views are dynamic. Following is my code

if ([prefs boolForKey:@"isDashboardAvailable"])
SWSegueFrontIdentifier = @"sw_front";
} else {
SWSegueFrontIdentifier = @"sw_second_front";

but im getting the following error

Cannot assign to variable 'SWSegueFrontIdentifier' with
const-qualified type 'NSString *const __strong'

why am I getting this error? How can I be able to change the SWSegueFrontIdentifier value?

Answer Source

since you want it to be dynamic front view controller, try the following..

create another const variable as following

NSString * const SWSegueSecondFrontIdentifier = @"sw_second_front";

then implement the following code in loadStoryboardControllers method

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
     if ([prefs boolForKey:@"isDashboardAvailable"])
       [self performSegueWithIdentifier:SWSegueSecondFrontIdentifier sender:nil];
     } else {
       [self performSegueWithIdentifier:SWSegueFrontIdentifier sender:nil];

revert back if you have any difficulties.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download