單例: 一個類中在整個程序只會建立一個對象,這個單例對象的數據是整個程序全部的文件全部的函數能夠共享。和全局變量相似
NSFileManager
UIApplication
//函數開頭 defaultXXXX或者 sharedXXX函數
非標準單例 + (MyPlane *)defaultPlane{ static MyPlane * plane = nil; @synchronized(self){ if (!plane) { plane = [[self alloc]init]; } } return plane; } //或者 + (MyPlane *)sharedPlane{ static MyPlane * plane = nil; @synchronized(self){ if (!plane) { plane = [[self alloc]init]; } } return plane; }