• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: iOS: Using AppDelegate as an app-wide singleton
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iOS: Using AppDelegate as an app-wide singleton


  • Subject: Re: iOS: Using AppDelegate as an app-wide singleton
  • From: Alex Zavatone <email@hidden>
  • Date: Tue, 01 Dec 2015 22:15:31 -0500

What does Apple do on this?

I think their standard is to use shared in the name.


On Dec 1, 2015, at 7:33 PM, Quincey Morris <email@hidden> wrote:

> On Dec 1, 2015, at 16:20 , Carl Hoefs <email@hidden> wrote:
>
>> The following seems to be working out for me.
>>
>> #import "AppCommon.h"
>> @implementation AppCommon
>> + (AppCommon *)shared
>> {
>>    static AppCommon *shared = nil;
>>    static dispatch_once_t token;
>>    dispatch_once(&token, ^{
>>        shared = [[self alloc] init];
>>    });
>>    return shared;
>> }
>
> Looks functionally perfect.
>
> PSA #1: I would encourage you avoid naming the method ‘shared’, indeed to avoid naming anything with a brief name that doesn’t say what it is. Even the argument that it’s easier to type isn’t good any more, since Xcode is going to autocomplete almost every name for you.
>
> PSA #2: I can’t help mentioning that you can write all of this in Swift as so:
>
> 	class AppCommon {
> 		static let shared = AppCommon ()
> 	}
>
> Sometimes, Swift really is Obj-C-but-better. ;)
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: iOS: Using AppDelegate as an app-wide singleton
      • From: Luther Baker <email@hidden>
References: 
 >iOS: Using AppDelegate as an app-wide singleton (From: Carl Hoefs <email@hidden>)
 >Re: iOS: Using AppDelegate as an app-wide singleton (From: Quincey Morris <email@hidden>)
 >Re: iOS: Using AppDelegate as an app-wide singleton (From: Carl Hoefs <email@hidden>)
 >Re: iOS: Using AppDelegate as an app-wide singleton (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: How to import a Framework
  • Next by Date: Re: How to import a Framework
  • Previous by thread: Re: iOS: Using AppDelegate as an app-wide singleton
  • Next by thread: Re: iOS: Using AppDelegate as an app-wide singleton
  • Index(es):
    • Date
    • Thread