Hide instance variable from header file in Objective C

后端 未结 10 1033
梦如初夏
梦如初夏 2020-12-30 14:35

I came across a library written in Objective C (I only have the header file and the .a binary). In the header file, it is like this:

@interface MyClass : MyS         


        
10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 15:00

    According to the documentation I've been looking at there is no problem. All you have to do to hide instance variables is to declare them at the start of the @implementation section, inside { ... }. However, I'm a relative newcomer to Objective C and there's a chance I have misunderstood something - I suspect that the language has changed. I have actually tried this system, using XCode 4.2, building code for the iPad, and it seems to work fine.

    One of my sources for this idea is the Apple developer documentation at http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/Chapters/ocDefiningClasses.html, which gives this pattern:

    @implementation ClassName

    {

    // Instance variable declarations.
    

    }

    // Method definitions.

    @end

提交回复
热议问题