zoukankan      html  css  js  c++  java
  • iOS单例模式

     

    +(HRTNetworking *)shareHRTNetworking

    {

       static HRTNetworking *_sharedClient = nil;

        static dispatch_once_t onceToken;

        dispatch_once(&onceToken, ^{

            _sharedClient = [[HRTNetworking alloc] initWithBaseURL:[NSURL URLWithString:HrtApp_URL]];

            [[_sharedClient requestSerializer] setTimeoutInterval:NET_WORKING_TIME_OUT];//超时时间

        });

     

        return _sharedClient;

    }

     

    self,在实例方法(对象方法)中表现是实例。在类方法中则表现为一种多态(可能是某一个类)的类实例(class instance),他总是会返回正确的类型(某一类),比如这样:

    + (id)new
    {
        return [[self alloc] init];
    }

    而在本文的这个@synchronized(self)里的self,总是会指向同一个对象,即那个特殊的类实例。(class也是一个对象),故而此处可以使用self。

  • 相关阅读:
    excel生成csv后,0001变成1
    windows_server_2012_r2提示api-ms-win-crt-runtime-l1-1-0.dll 丢失
    py文件生成exe程序
    朴素贝叶斯分类(上)
    01 | 数据分析全景图及修炼指南
    BBS
    BBS
    BBS
    BBS
    BBS
  • 原文地址:https://www.cnblogs.com/dengchaojie/p/7815068.html
Copyright © 2011-2022 走看看