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

  • Home
  • SEARCH
  • 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 8667653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:01:07+00:00 2026-06-12T18:01:07+00:00

I have a very simple TableViewController. I’m only implementing the data source methods and

  • 0

I have a very simple TableViewController. I’m only implementing the data source methods and two other methods to modify the data source. The table’s dataSource array is an array retrieved from the @"dataSource key in TableViewController’s NSDictionary property classData. I’m probably over thinking this, which is the best way to use dataSource array in my TableViewController:

1) Define a property in .h and set the property to the dictionary’s @"dataSource key in viewDidLoad

@property (strong, nonatomic) NSMutableArray *dataSource;

2) Define the variable in .m interface

@interface TableViewController () {
    NSMutableArray *dataSource;
}
@end 

3) Create an instance of the array in every method I need it

NSMutableArray *dataSource = [self.classData objectForKey: @"dataSource"];

I’m leaning towards option 2 because none of the classes in my app need access to the array. However, option 3 keeps it encapsulated even further. I would like to know the correct approach for this simple situation.

  • 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-12T18:01:08+00:00Added an answer on June 12, 2026 at 6:01 pm

    The decision between option 1 and 2 is pretty easy to resolve: it all depends on whether your datasource should be public or private; if it is private, then go with option 2.

    On the other hand, option 3 does does not seem really a good option (if either 1 or 2 is).

    If your datasource is meant to be a local variable (i.e., a variable whole lifecycle is bound by the containing method runtime), then it is fine; but in this case you would not even think of declaring that variable as an instance variable.

    You declare a variable as instance variable when you need to share its value across multiple calls to some methods of the declaring class (even the same method called at different times). This will decide if the variable is local or instance.

    If you mean using a static global variable whose scope is limited to the declaring method, then this is only superficially appealing. Indeed, the issue with it is that you cannot exactly foresee the use that will be required of datasource in the future: it may be the case that you will need to access it – for whatever reasons – from another method, then that design would not adapt itself.

    More generally speaking, in terms of encapsulation, I think that in OOP, the correct level of encapsulation is the class level, IMO. This would also rule out again option 3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very simple data model like this: create table Company ( id int
I have a very simple table called Member , which consists of the following:
I have very simple script for submitting the form. This is html template: <table>
I have very simple form along with two database tables. In this form is
I have very simple div(1). I need other simple div(2) slide slowly on it(1)
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very simple WPF application in which I am using data binding
I have very simple piece of code. The goal is when i input four-digit
I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As
I have very simple window where I have 2 buttons - one for cancel,

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.