• 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。

  • 相关阅读:
    POJ 2506 Tiling
    POJ 2586 Y2K Accounting Bug
    POJ 2965 The Pilots Brothers' refrigerator (DFS)
    POJ 2499 Binary Tree
    POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (素数)
    beautifulsoup 基本语法 含class属性查找小技巧class_
    xlrd库的使用
    pytest框架 里 fixture 参数化的方法
    ddt数据驱动
    mac电脑 pip安装包后 撞到了系统python里面的解决方法
  • 原文地址:https://www.cnblogs.com/dengchaojie/p/7815068.html
Copyright © 2020-2023  润新知