Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you access variable declared in a class extension?

MyClass.h:

@interface MyClass : NSObject
@end

MyClass.m:

// Define a private variable in a class extension
@interface MyClass () {
    NSString *name;
}
@end

Then later on in lldb:

(lldb) po myClassInstance->name
error: 'MyClass' does not have a member named 'name'
error: 1 errors parsing expression

So how do you access that variable in the debugger?

Using xcode 4.3.2

Thanks!

like image 877
sherrman Avatar asked Apr 25 '12 00:04

sherrman


People also ask

How do you access class variables?

To access class variables, you use the same dot notation as with instance variables. To retrieve or change the value of the class variable, you can use either the instance or the name of the class on the left side of the dot.

Can we access Fileprivate variable in extension Swift?

Swift 3 added the fileprivate keyword. An entity that is declared fileprivate is only accessible from within the file it is defined in.

What is CoC in x++?

X++ Copy. [ExtensionOf(classStr(BusinessLogic1))] final class BusinessLogic1_Extension { str doSomething(int arg) { // Part 1 var s = next doSomething(arg + 4); // Part 2 return s; } } In this example, the wrapper around doSomething and the required use of the next keyword create a Chain of Command (CoC) for the method ...


1 Answers

(lldb) po [myClassInstance valueForKey:@"name"]

like image 100
Grady Player Avatar answered Sep 28 '22 06:09

Grady Player