Swift中网络管理单例写法
import UIKit import AFNetworking /// 网络工具单例类 class LHNetWorkManager: AFHTTPSessionManager { static let shared=LHNetWorkManager() }
#OC中网络单例写法
+(SJBNetWorkManager *)sharedManager{ static SJBNetWorkManager *sharedNetworkSingleton = nil; static dispatch_once_t predicate; dispatch_once(&predicate,^{ sharedNetworkSingleton = [[self alloc] init]; }); return sharedNetworkSingleton; }
怎么样,是不是感觉Swift简洁多啦~~~~
原文链接:https://www.f2er.com/swift/321870.html