标签:
获得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
标签:
原文地址:http://www.cnblogs.com/wenios/p/4816707.html