在Object-C中我们很多时候都会重写init方法。一般情况下我们都会这样写:

-(instancetype)initWithDic:(NSDictionary *)dic{
if(self=[super init]){
code
}
return self;
}

我们来分析下:

1.[super init]在面向对象的编程中,我们的所有对象都是继承于Object。因此我们在初始化当前的

这样对象的时候都需要进行初始化Objce.开辟属于Object的内存。

2.self =[super init]:

为了防止父类的初始化方法release掉了self指向的空间并重新alloc了一块空间。

[super init]可能alloc失败,这时就不再执行if中的语句。

self = [super init]的解释的更多相关文章

  1. self = [super init] 最终解释

    答:      init 中调用super的 init方法来初始化自己所包含有的父类信息 1.内存分配      内存应该在[Class alloc]的时候就已经分配了,大小和类型应该由对应的Clas ...

  2. [转] "self = [super init]"的解释与潜藏bug

    Objective-C的推荐init方法写法如下: - (id) init { if(self = [super init]) { //为子类增加属性进行初始化 } return self; } 这里 ...

  3. iOS self = [super init]

    self = [super init] 这个问题一直不太明白,今天研究了一下,在stackoverflow找到了下面的答案: http://stackoverflow.com/questions/29 ...

  4. [super init]方法的调用

    当重新覆盖父类的init方法时,需要调用[super init]方法确认父类中的init是返回一个实例,而不是一个空的实例. 那为什么要调用这个呢? 我得猜测是这样的:因为这是一个初始化方法,需要对对 ...

  5. 关于 self = [super init];

    [plain] view plaincopyprint? - (id)init { self = [super init]; // Call a designated initializer here ...

  6. OC self = [super init] , 点语法 , @property

    OC self = [super init] , 点语法 , @property 构造方法为啥这么写? self = [super init]; [super init] 的结果可能有三种: 第一种: ...

  7. Swift - Property ''not initialized at super.init call

    Property ''not initialized at super.init call 这个错误应该挺常见的的,为什么在百度上没有找到呢,stack over flow找到了,也不能说是什么解决办 ...

  8. 刨根问底:对于 self = [super init] 的思考

    对象初始化有两种方式:[class new] 与 [[class alloc] init] 对于后者,有分配和初始化的过程,alloc 从应用程序的虚拟地址空间上为该对象分配足够的内存,并且将新对象的 ...

  9. 关于self和super在oc中的疑惑与分析 (self= [super init])

    这个问题貌似很初级,但很容易让人忽略,me too .直到在一次面试时被问到,稀里糊涂的回答了下.实在惭愧, 面试一定都是很注重 基础的,不管高级还是初级. 虽然基础好跟基础不好都可以写代码,网上那么 ...

随机推荐

  1. EXT.JS以下两种写法在初始载入时是一样的效果

    /* Ext.application({ name: 'MyfirstApplication', launch: function () { Ext.Msg.alert("Hello&quo ...

  2. Codeforces A. Bear and Big Brother

    ...不行.这题之后.不做1000分以下的了.很耻辱   A. Bear and Big Brother time limit per test 1 second memory limit per t ...

  3. OAuth 2.0 in Web API #Reprinted

    http://www.codebetter.com/howarddierking/2011/10/11/oauth-2-0-in-web-api/

  4. SQL Server 监控系列 —— 二

    http://www.cnblogs.com/bhtfg538/archive/2011/01/21/1939706.html

  5. weblogic日志管理

    服务器日志  每个 WebLogic Server 实例将来自子系统和应用程序的所有消息写入位于本地主机上的服务器日志文件.默认情况下,服务器日志文件位于服务器实例根目录下的 logs 目录中: 例如 ...

  6. tensorflow提示出错'module' object has no attribute 'pack'

    编译旧的代码,会像下面这样提示出错: deconv_shape3 = tf.pack([shape[0], shape[1], shape[2], NUM_OF_CLASSESS]) Attribut ...

  7. 制作一个可以滑动操作的 Table View Cell

    本文转载至 https://github.com/nixzhu/dev-blog Apple 通过 iOS 7 的邮件(Mail)应用介绍了一种新的用户界面方案——向左滑动以显示一个有着多个操作的菜单 ...

  8. iOS开发 Coretext基本用法

    转至 http://blog.csdn.net/fengsh998/article/details/8691823 API接口文档. https://developer.apple.com/libra ...

  9. git/icode操作记录

    之前有一篇文章写了团队git的管理方式:link 今天处理了一个自动退款的脚本.提交到git.步骤如下: 1. 切换到本地master,update: git checkout master git ...

  10. 分布式服务框架选型:面对Dubbo,阿里巴巴为什么选择了HSF?

    转载:http://www.sohu.com/a/141490021_268033 阿里巴巴集团内部使用的分布式服务框架 HSF(High Speed Framework,也有人戏称“好舒服”)已经被 ...