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 8222581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:19:44+00:00 2026-06-07T14:19:44+00:00

I have two view controllers and nibs. I populated one view controller with a

  • 0

I have two view controllers and nibs. I populated one view controller with a toggle switch and declared this in its header file:

@public UISwitch *toggleSwitch;

and exposed it as a property like this:

@property (nonatomic,retain) IBOutlet UISwitch *toggleSwitch;

I also connected the switch with toggleSwitch outlet. Now I want to use this toggleSwitch field in my other view controller, how do I do that? Isn’t using @public in the field declaration enough? Please help. Thank you.

  • 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-06-07T14:19:46+00:00Added an answer on June 7, 2026 at 2:19 pm

    No problem at all. Just use the switch like this:

    vcWhereYouDeclaredTheSwitch.toggleSwitch.on = YES;
    

    or

    BOOL test = [vcWhereYouDeclaredTheSwitch.toggleSwitch isOn];
    

    inside your other view controller.

    Here are some general thoughts about propertys:

    • Memory management : Behind the scenes it will create a setter which creates the variable with correct memory management. It will save you some headaches because you can easily see how the memory management is done (strong/weak and retain/copy/assign).

    • Accessibility from other classes: if you declare your @property in the .h and @synthesize it in the .m you ivar will be public readable and writeable. You can prevent this with a privat class extension. You even can declare a @property public readonly and declare them internally readwrite via a privat class extension.
      Eg: a private property

       // [In the implementation file]  
       @interface MyClass ()  
       @property (nonatomic, retain) NSMutableArray* someData; // private!!   
       @end  
    
       @implementation MyClass @synthesize someData   
       @end
    
    • Custom getter and setter: If you like you can still write custom getter and setters and you can even just write a getter or setter and let the other one automatically @synthesize. And you can write custom logic into such a getter and setter e.g. you can reload a tableview after a @property has changed.

    • Automatic Key-Value-Observing (KVO) compliant: If you use or planning to use KVO you get it basically for free by just declaring the property. Nothing else need to be done!

    • If you need you iVar to be public it is simpler to write one @property than writing a getter and setter for a iVar

    • With a @property you do not need to declare in iVar (in iOS and 64bit Mac Os X applications). You can do it via the @synthesize:

        @synthesize myiVar = _myIvar;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two view controllers and nibs. I populated one view controller with a
I have two view controllers, one is main and second is detail. Whenever I
I have two View Controllers: TableViewController (which is used as a modal view controller)
So I have two view controllers in my iphone project - one of them
I have this iPad application with different NIBs and views. Each view has two
The Problem: I have two View Controllers loaded into a root View Controller. Both
I'm trying to get this graphing calculator to work. I have two view controllers,
I have two view controllers, in which I am using navigation controller to navigate
Hey guys I need some help with this: I have two view controllers, let's
I have a view controller that initializes two other view controllers. The view for

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.