Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4577968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:25:11+00:00 2026-05-21T20:25:11+00:00

I have a UISwitch that sets a BOOL to 1 or 0 in CoreData.

  • 0

I have a UISwitch that sets a BOOL to 1 or 0 in CoreData. However, when a user loads a view with the Switch, core data recognizes the Switch is set to 1 (on) but the switch still shows off. Here’s the code below. Note: the switch shows on correctly when you enter and exit the application, but it will show off if you turn off and one the phone, or stop and start the iPhone simulator. Can someone help?

“setSwtich” is the method on the UISwitch, “list” is the name of the UISwitch and “indicator” is the core data event attribute the BOOL is stored in.

-(IBAction)setSwitch
{
    if (list.on) 
    {
        [event setIndicator:[NSNumber numberWithInt:1]];
        NSError *error;
        if (![managedObjectContext save:&error]) 
        {
            NSLog(@"there was an error in Save");
        }
    }
    else [event setIndicator:[NSNumber numberWithInt:0]];
    NSError *error;
    if (![managedObjectContext save:&error]) 
    {
        NSLog(@"there was an error in Save");
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (event.indicator == [NSNumber numberWithInt:1]) {
        [list setOn:YES animated:NO];
    }
    else nil;
}

-(void)viewDidAppear:(BOOL)animated
{
    if (event.indicator == [NSNumber numberWithInt:1]) {
        [list setOn:YES animated:NO];
    }
}

- (void)viewDidUnload
{
    if (list.on) {
        [event setIndicator:[NSNumber numberWithInt:1]];
    }
    NSError *error;
    if (![managedObjectContext save:&error]) 
    {
        NSLog(@"there was an error in Save");
    }
    [super viewDidUnload];

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
-(void)viewDidDisappear:(BOOL)animated
{
    if (list.on) {
        [event setIndicator:[NSNumber numberWithInt:1]];
    }
    NSError *error;
    if (![managedObjectContext save:&error]) 
    {
        NSLog(@"there was an error in Save");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:25:12+00:00Added an answer on May 21, 2026 at 8:25 pm

    Maybe it’s just the way you use ==.Try the comparison as defined by Apple:

    isEqualToNumber:
    
    Returns a Boolean value that indicates whether the receiver and a given number are equal.
    - (BOOL)isEqualToNumber:(NSNumber *)aNumber
    Parameters
    
    aNumber
    
        The number with which to compare the receiver.
    
    Return Value
    
    YES if the receiver and aNumber are equal, otherwise NO.
    Discussion
    
    Two NSNumber objects are considered equal if they have the same id values or if they have equivalent values (as determined by the compare: method).
    
    This method is more efficient than compare: if you know the two objects are numbers.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TableViewCell with a UISwitch in accessoryView. I don't want that blue
I have a textfield that is hidden to start with and when the user
I have set up a UITableView with 3 sections that pulls from 3 NSArrays
I have a loging screen with a UISwitch for letting the user choose remember
I have a tableview with UISwitch in each row of the table. Switch is
I have made a game which has a UISwitch that turns the music off.
I have a UITableView with cells that contain a UISwitch control. It's similar to
I have this observer that watches the UISwitch for a change in value: [cell.switcher
I have a simple problem. I created a custom UITableViewCell that includes a UISwitch
I have a problem with UISwitch repositioning on device rotation. the switch is part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.