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

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

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

      为什么没有相应 ivar 的子类 @property 隐藏超类 ivar?

      时间:2023-10-03

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

          <tbody id='WKnGv'></tbody>

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

      • <legend id='WKnGv'><style id='WKnGv'><dir id='WKnGv'><q id='WKnGv'></q></dir></style></legend>

        <tfoot id='WKnGv'></tfoot>
          <bdo id='WKnGv'></bdo><ul id='WKnGv'></ul>

                本文介绍了为什么没有相应 ivar 的子类 @property 隐藏超类 ivar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                以下内容似乎很简单.有一个带有 ivar 的超类,以及一个访问(@protected)超类 ivar 的子类:

                The following seems simple enough. There's a superclass with an ivar, and a subclass which accesses the (@protected) superclasses ivar:

                // Testclass.h    
                @interface TestClass : NSObject {
                    NSString *testIvar;
                }
                @end
                
                //TestClass.m
                @implementation TestClass
                @end
                
                //TestSubclass.h
                @interface TestSubClass : TestClass {
                }
                
                @property (nonatomic, retain) NSString *testProperty;
                - (void) testMethod;
                
                @end
                
                //TestSubclass.m    
                #import "TestSubClass.h"
                @implementation TestSubClass
                
                @synthesize testProperty;
                
                - (void) testMethod{
                    NSLog(@"The value was: %@", testIvar);
                }
                @end
                

                简单而正确——看起来足够了.但是,尝试编译(对于 iOS 4.2 SDK,使用 GCC 4.2)会产生指向 NSLog 行的错误:'testIvar undeclared'.

                Simple and correct-seeming enough. However, attempting to compile (for iOS 4.2 SDK, with GCC 4.2) produces this error pointing to the NSLog line: 'testIvar undeclared'.

                我是 Objective-C 的新手,但我一生都无法理解为什么这应该是一个错误.注释掉 testProperty 的东西,它就可以编译了.似乎在子类中添加一个综合属性,没有对应的 ivar,实际上是在隐藏一个不相关的超类 ivar.

                I'm new to Objective-C, but can't for the life of me see why this should be an error. Comment out the testProperty stuff, and it compiles OK. It seems like adding a synthesized property in a subclass, without a corresponding ivar, is actually hiding an unrelated superclass ivar.

                谁能告诉我这里发生了什么?与此相关的是,编译错误是否可以预见?(预见到它会为我节省一些时间和挫败感).

                Can anyone enlighten me as to what's happening here? Relatedly, was the compilation error foreseeable? (Foreseeing it would have saved me some time and frustration).

                推荐答案

                LLVM编译源码不报错,切换到LLVM:Select target → Get Info → Build → C/C++ Compiler Version → LLVM 1.5.根据我有限的经验,无论如何它是一个更好的编译器.不知道为什么 GCC 会这样做——有趣的问题.

                LLVM compiles the source without complaints, switch to LLVM: Select target → Get Info → Build → C/C++ Compiler Version → LLVM 1.5. From my limited experience it’s a better compiler anyway. No idea why GCC behaves the way it does – interesting catch.

                这篇关于为什么没有相应 ivar 的子类 @property 隐藏超类 ivar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 iphone 中暂停和恢复 NSTimer 下一篇:黑白 iPhone 的区别?

                相关文章

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

                1. <legend id='q9fN6'><style id='q9fN6'><dir id='q9fN6'><q id='q9fN6'></q></dir></style></legend>
                2. <tfoot id='q9fN6'></tfoot>

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