OC & Swift 单例

1. OC 单例

 

+ (NetworkTool *)sharedNetworkTool {
    
    static id instace;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instace = [[self alloc] init];
    });
    return instace;
}

 

 

2. Swift 单例 

 

   
    private static let instance = NetworkTool()
    
    class func sharedNetwork() -> NetworkTool{
        return instance
    }
    

 

posted @ 2015-05-25 23:55  杨智帆  阅读(181)  评论(0编辑  收藏  举报