• <small id='Ma504'></small><noframes id='Ma504'>

    <i id='Ma504'><tr id='Ma504'><dt id='Ma504'><q id='Ma504'><span id='Ma504'><b id='Ma504'><form id='Ma504'><ins id='Ma504'></ins><ul id='Ma504'></ul><sub id='Ma504'></sub></form><legend id='Ma504'></legend><bdo id='Ma504'><pre id='Ma504'><center id='Ma504'></center></pre></bdo></b><th id='Ma504'></th></span></q></dt></tr></i><div id='Ma504'><tfoot id='Ma504'></tfoot><dl id='Ma504'><fieldset id='Ma504'></fieldset></dl></div>
    <legend id='Ma504'><style id='Ma504'><dir id='Ma504'><q id='Ma504'></q></dir></style></legend>
    • <bdo id='Ma504'></bdo><ul id='Ma504'></ul>

      <tfoot id='Ma504'></tfoot>

        使用 @synthesize 的自动 iVar

        时间:2023-10-23
        <legend id='6pQww'><style id='6pQww'><dir id='6pQww'><q id='6pQww'></q></dir></style></legend>

              <bdo id='6pQww'></bdo><ul id='6pQww'></ul>
                  <tfoot id='6pQww'></tfoot>

                    <tbody id='6pQww'></tbody>

                • <small id='6pQww'></small><noframes id='6pQww'>

                  <i id='6pQww'><tr id='6pQww'><dt id='6pQww'><q id='6pQww'><span id='6pQww'><b id='6pQww'><form id='6pQww'><ins id='6pQww'></ins><ul id='6pQww'></ul><sub id='6pQww'></sub></form><legend id='6pQww'></legend><bdo id='6pQww'><pre id='6pQww'><center id='6pQww'></center></pre></bdo></b><th id='6pQww'></th></span></q></dt></tr></i><div id='6pQww'><tfoot id='6pQww'></tfoot><dl id='6pQww'><fieldset id='6pQww'></fieldset></dl></div>
                • 本文介绍了使用 @synthesize 的自动 iVar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我了解从 iOS 4 开始,现在可以完全不声明 iVar,并允许编译器在您合成属性时自动为您创建它们.但是,我找不到 Apple 提供的有关此功能的任何文档.

                  I understand that starting with iOS 4, there is now the ability to not declare iVars at all, and allow the compiler to automatically create them for you when you synthesize the property. However, I cannot find any documentation from Apple on this feature.

                  另外,是否有关于使用 iVar 和属性的最佳实践或 Apple 推荐指南的任何文档?我一直使用这样的属性:

                  Also, is there any documentation on best practices or Apple recommended guidelines on using iVars and properties? I have always use properties like this:

                  .h 文件

                  @interface myClass {
                      NSIndexPath *_indexPath
                  }
                  
                  @property(nonatomic, retain) NSIndexPath *indexPath
                  
                  @end
                  

                  .m 文件

                  @implementation myClass
                  
                  @synthesize indexPath = _indexPath;
                  
                  - (void)dealloc {
                      [_indexPath release];
                  }
                  @end
                  

                  我使用 _indexPath 而不是 indexPath 作为我的 iVar 名称,以确保在需要使用 self.indexPath 时不会使用 indexPath.但是现在 iOS 支持自动属性,我不需要担心这个.但是,如果我遗漏了 iVar 声明,我应该如何处理在我的 dealloc 中释放它?我被教导在 dealloc 中释放时直接使用 iVar,而不是使用属性方法.如果我在设计时没有 iVar,我可以只调用属性方法吗?

                  I use the _indexPath instead of indexPath as my iVar name to make sure that I don't ever use indexPath when I need to use self.indexPath. But now that iOS supports automatic properties, I don't need to worry about that. However, if I leave out the iVar declaration, how should I handle releasing it in my dealloc? I was taught to use iVars directly when releasing in dealloc, rather than using the property methods. If I don't have an iVar at design-time, can I just call the property method instead?

                  推荐答案

                  我经历了许多不同的方法来处理这个问题.我目前的方法是使用dealloc中的属性访问.不这样做的原因(在我看来)太做作了,除非我知道该物业有奇怪的行为.

                  I've went through many different ways of dealing with this. My current method is to use the property access in dealloc. The reasons not to are too contrived (in my mind) to not do it, except in cases where I know the property has odd behavior.

                  @interface Class
                  @property (nonatomic, retain) id prop;
                  @end
                  
                  @implementation Class
                  @synthesize prop;
                  
                  - (void)dealloc;
                  {
                      self.prop = nil;
                      //[prop release], prop=nil; works as well, even without doing an explicit iVar
                      [super dealloc];
                  }
                  @end
                  

                  这篇关于使用 @synthesize 的自动 iVar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:达到 50 个条目限制时如何自动删除最旧的核心数据条目? 下一篇:iPhone:如何允许在自定义单元格的表格视图中进行多项选择?

                  相关文章

                      <legend id='RDBNP'><style id='RDBNP'><dir id='RDBNP'><q id='RDBNP'></q></dir></style></legend>

                    1. <i id='RDBNP'><tr id='RDBNP'><dt id='RDBNP'><q id='RDBNP'><span id='RDBNP'><b id='RDBNP'><form id='RDBNP'><ins id='RDBNP'></ins><ul id='RDBNP'></ul><sub id='RDBNP'></sub></form><legend id='RDBNP'></legend><bdo id='RDBNP'><pre id='RDBNP'><center id='RDBNP'></center></pre></bdo></b><th id='RDBNP'></th></span></q></dt></tr></i><div id='RDBNP'><tfoot id='RDBNP'></tfoot><dl id='RDBNP'><fieldset id='RDBNP'></fieldset></dl></div>

                      <small id='RDBNP'></small><noframes id='RDBNP'>

                      • <bdo id='RDBNP'></bdo><ul id='RDBNP'></ul>
                      <tfoot id='RDBNP'></tfoot>