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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:32:54+00:00 2026-06-18T11:32:54+00:00

I read enough information about singleton and delegation. So, I think I understand what

  • 0

I read enough information about singleton and delegation. So, I think I understand what is singleton. About delegation I still confuse. I understand conception of delegation, but I need to create my protocol for understanding delegation.

Ok, I create singleton for work with my entities from CoreData. Maybe I wrong and it is not singleton, tell me please about it. My singleton is FetchData.

Fetchdata.h

#import <Foundation/Foundation.h>

@interface FetchData : NSObject <UIApplicationDelegate>

+(FetchData*) fetchData;

-(NSArray*)fetchLogin:(NSString*)name;
-(BOOL)newGroup:(NSString*)group forLogin:(NSString*)login;
-(NSMutableArray*)contactsForGroup:(NSString*)group;
-(BOOL)newContact:(NSString*)name surname:(NSString*)surname withDatas:(NSArray*)array;
//other methods 

@end

Fetchdata.m

#import "FetchData.h"
#import "Contact.h"
#import "Login.h"
#import "Group.h"
#import "AppDelegate.h"

@interface FetchData ()
@property (nonatomic, strong) NSEntityDescription *loginEntity;
@property (nonatomic, strong) NSEntityDescription* groupEntity;
@property (nonatomic, strong) NSManagedObjectContext* context;
@property (nonatomic, strong) NSEntityDescription* contactEntity;
@property (nonatomic, strong) AppDelegate* appDelegate;
//other properties
@end

@implementation FetchData
@synthesize //my properties

+(FetchData*) fetchData
{
 static  FetchData* fetchData = nil;
 if (!fetchData) 
    fetchData = [[super allocWithZone:nil]init];
 return fetchData;
}

+(id)allocWithZone:(NSZone *)zone
{
 return [self fetchData];
}

//implementation my methods
@end

So, it is very easy to work with CoreData now for me. I need only import FetchData and simply use methods for create/delete/change/add/sort…

SomeClass.m

#import "FetchData.h"
#define fetching [FetchData fetchData]

But I think that I can use for my aim delegation. Or maybe it is the best decesion as compared with singleton. So I want to remake singleton for delegation. And I need help with this question. What I must do?

If I understand correctly I need create protocol with all my methods from FetchData.h, FetchData.m I can leave without changes. And in SomeClass I need import FetchData and add my protocol. Like:

#import <Foundation/Foundation.h>

@protocol FetchingDelegate

//all methods from FetchData.h

@end

@interface FetchData : NSObject
@property (nonatomic, strong) id <FetchingDelegate> delegate;
@end

FetchData.m

@interface FetchData()
//all properties without changing
@end

@implementation FetchData
@synthesize //all properties and delegate

//implementation of methods
@end

SomeClass

#import "FetchData.h"

@interface SomeClass : NSObject <FetchingDelegate>
@end

@implementation SomeClass

-(void)viewDidLoad
{
  FetchData* fetching = [FetchData new]
  fetching.delegate = self
}
//and now I can use any methods from protocol like [fetching anyMethod]
//such I used with singleton
  • 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-18T11:32:55+00:00Added an answer on June 18, 2026 at 11:32 am

    The idea of a singleton is that your entire app can access this one class. Multiple view controllers may need data coming from your database. In your case, I would change your fetchData method (and maybe change its name as it doesn’t really follow convention now):

    +(FetchData*) fetchData
    {
        static FetchData *fetchData;
        dispatch_once_t token;
        dispatch_once(&token, ^{
            if (!fetchData) 
                fetchData = [super init];
        }
     return fetchData;
    }
    

    Delegates are meant for one-on-one communication, meaning that one object has a delegate and sends any messages to that one particular delegate.

    That means that a singleton and delegation don’t go well together. The singleton is made to send messages to multiple receivers, while the delegation pattern is meant for one-on-one communication. So you have two options: you could either not use a singleton and use the delegation pattern, or you could use a singleton, and use NSNotificationCenter to notify observers of changes.

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

Sidebar

Related Questions

Read about the issue in this stackoverflow question . Still have the same issue
I read an article about a regular expression to detect base64 but when I
I've seen a few topics about linked lists, and I've read enough to glean
I have read a few good articles about coding a socket server but thought
I read about Session Hijacking articles and would like to some more information related
Read (skimmed enough to get coding) through Erlang Programming and Programming Erlang . One
Read about Server push here . I want to push data to client from
I read past questions but I couldn't solve my issue :( This is my
I haven't found information about this anywhere. Is there a minimal required length for
I've read a few other posts like this one about avoiding repetition in Java

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.