码迷,mamicode.com
首页 > 其他好文 > 详细

单例设计模式逐步讲解004

时间:2015-09-17 17:29:21      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

获得app实例的静态方法:

单例类:

UIApplication:+sharedApplication

NSUserDefaults:+standardUserDefaults

NSNotificationCenter:+defaultCenter

NSFileManager:+defaultManager

NSBundle:+mainBundle

 

每次要获得单例类的实例方法的时候就要使用静态方法:

UIApplication.sharedApplication

NSUserDefaults.standardUserDefaults

NSNotificationCenter.defaultCenter

NSFileManager.defaultManager

NSBundle.mainBundle //经常用在访问属性列表文件

 

 


+ mainBundle
Returns the NSBundle object that corresponds to the directory where the current application executable is located.

Declaration声明
SWIFT
class func mainBundle() -> NSBundle
OBJECTIVE-C
+ (NSBundle *)mainBundle
Return Value返回值
The NSBundle object that corresponds to the directory where the application executable is located, or nil if a bundle object could not be created.

Discussion
This method allocates and initializes a bundle object if one doesn’t already exist. The new object corresponds to the directory where the application executable is located. Be sure to check the return value to make sure you have a valid bundle束. This method may return a valid bundle object even for unbundled applications.

In general, the main bundle corresponds to an application file package or application wrapper: a directory that bears the name of the application and is marked by a “.app” extension.

Import Statement
OBJECTIVE-C
@import Foundation;
SWIFT
import Foundation

单例设计模式逐步讲解004

标签:

原文地址:http://www.cnblogs.com/wenios/p/4816707.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!