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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:09:47+00:00 2026-06-15T22:09:47+00:00

you have a class or ViewController using model/service class like so: @interface MainViewController :

  • 0

you have a class or ViewController using model/service class like so:

@interface MainViewController : UIViewController <TweetServiceDelegate> {

   NSArray *_tweets;
}

@property (nonatomic, strong) TweetService *tweetService;

@end

@implementation MainViewController

- (void)viewDidLoad {

  [super viewDidLoad];
  [self.twitterService queryForLatestTweets];
}

// delegate methods the tweetservice calls back after async getting data

- (void)querySucceededWithTweets:(NSArray *)tweets {

   _tweets = [tweets copy];
}

@end

The reason I ask because the Service has a weak reference to the delegate, which is the ViewController.

So I know with ARC you don’t want 2 things that use each other to both have a strong reference, so if it’s weak but the ViewController retains the NSArray, then the Service wouldn’t be collected once it went out of scope, assuming the service did go out of scope but the ViewController didn’t

@interface TweetService 

@property (nonatomic, weak) id<TweetServiceDelegate> delegate;

@end

@implementation TweetService

- (void)queryForLatestTweets {

   // do the query with AFNetworking, when succeed block fires, call the delegate

   [self.delegate querySucceededWithTweets:arrayOfTweets];
}

@end
  • 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-15T22:09:48+00:00Added an answer on June 15, 2026 at 10:09 pm

    I would say this is rather the recommended way of doing this sort of things. The service is held strongly by the controller that needs it, but the service holds the controller only weakly as a delegate because it does not need to know what its delegate is — or even if it exists — to function.

    When the service returns something through delegate methods back to its delegate, the delegate should claim ownership of the data. The preferred way is to copy, since the delegate does not know anything about the return value’s lifecycle. copy makes a new instance that can be think as a “snapshot” of the data. Working on this “snapshot” guarantees that your data are not modified when you don’t want them to. This effectively decouples the service and the delegate.

    A side note: Your self._tweets won’t work because _tweets is an instance variable, but the dot syntax expects a property. _tweets = [tweets copy]; would be correct.

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

Sidebar

Related Questions

I have the following ViewController class #import <UIKit/UIKit.h> @interface SampleViewController : UIViewController { IBOutlet
I have a ViewController class called GamePlay. In GamePlay there is a nested class
I have a class that is viewcontroller and I'v putted it inside of tabbar.
I have a UIButton that I create in my sub class ViewController, and add
I have a UITableView in a ViewController class. The ViewController class uses a custom
I have Class and Student objects. Both have collection of another as property. Which
I'm using PHP 5.2 to make a website I like to have explicit names
I have a root UIViewController subclass that has a UITabBar, (I'm not using UITabBarController)
I have annotated my fields in my model and am using the @Valid annotation
I am considering using class extension as a way to connect my model with

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.