iOS开发中常用的系统单例

单例模式是开发中常见的一种模式,苹果也给我们提供了很多这样的单例,总结一下大部分常见的系统单例

常用:

[UIApplication sharedApplication] 应用程序实例

[NSBundle mainBundle] 系统资源

[NSFileManager defaultManager] 用于文件管理。

[NSNotificationCenter defaultCenter] 消息中心。

[NSUserDefaults standardUserDefaults] 数据存储。

[UIAppearance appearance] 统一外观。

[UIDevice currentDevice] 设备信息。

[NSUUID UUID] 获取UUID。

[UIScreen mainScreen] 主屏幕。

[NSRunLoop currentRunLoop] 当前Runloop。

[NSRunLoop mainRunLoop] 主Runloop。

[NSRunLoopMode currentMode] 当前RunloopMode

[NSThread currentThread] 当前线程

[NSThread  mainThread] 主线程

不常用:

[UIAccelerometer sharedAccelerometer] 加速器。

[UILocalizedIndexedCollationn currentCollation]  按字母排序。

[UIMenuController sharedMenuController] 长按一段文字或者图片的时候会弹出的菜单。

[UIPasteboard generalPasteboard]  粘贴板。

[NSCalendar currentCalendar] 日历。

[NSCalendar autoupdatingCurrentCalendar] NS_AVAILABLE(10_5, 2_0) 日历。

[NSURLCache sharedURLCache] 请求缓存。

[NSURLCredentialStorage sharedCredentialStorage]

[NSHTTPCookieStorage sharedHTTPCookieStorage] 应用程序cookies池。

[NSProgress currentProgress] 报告长时间运行的任务的进度。

非常少见的:

[UIGraphicsRendererFormat defaultFormat] NS_CLASS_AVAILABLE_IOS(10_0)

[UIRegion infiniteRegion] NS_CLASS_AVAILABLE_IOS(9_0)

[NSUbiquitousKeyValueStore defaultStore] NS_CLASS_AVAILABLE(10_7, 5_0)

花了一上午时间,将Foundation和UIKit过了一遍,其本上就是上面这些,错误和遗漏之处欢迎指正。

你可能感兴趣的:(iOS开发中常用的系统单例)