• 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: Quincey Morris <email@hidden>
  • Date: Tue, 01 Dec 2015 15:55:27 -0800
  • Feedback-id: 167118m:167118agrif8a:167118soRIVe_FhK:SMTPCORP

On Dec 1, 2015, at 12:58 , Carl Hoefs <email@hidden> wrote:

> available to all classes via [[UIApplication sharedApplication] delegate].

> Are there any drawbacks to this?

I don’t find this practice very objectionable, but the drawback is that '[[UIApplication sharedApplication] delegate]’ has the wrong class, so you usually end up writing some sort of global function to get it pre-cast.

In that case, you may as well use a different object, make it a local static variable in a class implementation, and write a static method (“[MyContextCache sharedContextCache]”) to get it. Don’t forget to use dispatch_once to create the singleton. You may not have any thread safety concerns right now, but you might easily do so later.


_______________________________________________

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: Carl Hoefs <email@hidden>
References: 
 >iOS: Using AppDelegate as an app-wide singleton (From: Carl Hoefs <email@hidden>)

  • Prev by Date: Re: FSIsAliasFile deprecated - typeOfFile is slow
  • Next by Date: Re: iOS: Using AppDelegate as an app-wide singleton
  • 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