objective-c-runtime

Objective-C property assignment returns the assigned value?

Say I have the following: @interface MyClass : NSObject { NSString* _foobar; } @property (nonatomic, retain) NSString* foobar; @end @implementation MyClass @dynamic foobar; - (void) setFoobar:(NSString*)fbSet; { [_foobar release]; _foobar = [fbSet retain]; } - (NSString*) foobar; { return _foobar; } @end Then: MyClass* mcInst = [[[M...

Why doesn't Objective-C support private methods?

I've seen a number of strategies for declaring semi-private methods in Objective-C, but there does not seem to be a way to make a truly private method. I accept that. But, why is this so? Every explanation I've essentially says, "you can't do it, but here's a close approximation." There are a number of keywords applied to ivars (memb...

How does the Objective-C runtime instantiate the root metaclass and other class descriptions?

I'm trying to implement a basic object-oriented ANSI C runtime and using Objective-C as a guide. They're seems to be three parts. A Class Description, Class Interface, and Class Implementation. In order for the Class Interface to be instantiated, the familiar method of using the Class object to instantiate one's object can only happen i...

How to obtain the list the current instantiated objects for a given class in Objective-C?

Since class_poseAs(..) is deprecated in Objective-C 2.0, I need to find another way to change the class of an object at runtime. I've found I can change an object's class using object_setClass(..). My problem now is finding all the current instances of a given class in order to update them. A solution would be to maintain a global dicti...

Does +(void)initialize do any thread locking?

Looking at the definition for "initialize": + (void)initialize Discussion The runtime sends initialize to each class in a program exactly one time just before the class, or any class that inherits from it, is sent its first message from within the program. (Thus the method may never be invoked if the class is not used.) The runtime s...

Objective-C class -> string like: [NSArray className] -> @"NSArray"

I am trying to get a string name of a class from the class object itself. // For instance [NSArray className]; // @"NSArray" I have found object_getClassName(id obj) but that requires an instance be passed to it, and in my case that is needless work. So how can I get a string from a class object, and not an instance? ...

Any way to check if an instance is still in memory?

Example: I have a view controller and get rid of it. But there's still an variable holding it's memory address. Accessing that results in EXEC_BAD_ACCESS. Of course. But: Is there any way to check if that variable is still valid? i.e. if it's still pointing to something that exists in memory? ...

iSimulate Automatic Hooks

I was wondering if anyone knew how iSimulate automatically registers/hooks itself into a debugged iDevice application? It's as simple as including the static library (and a couple of frameworks) and it just works. There are no methods or functions to call. How is this possible? ...

target-action cocoa touch

Hi there, I want to add at-runtime some behaviour to some controls: Suppose we have a UISwitch. The next thing I want to do, is reading an UIML file and add some action to the UISwitch. This action is described in the UIML document. UIML is an XML document. Suppose we have an interface with 1 switch and 1 textfield. When changing the ...

Building Dynamic Classes in Objective C

I'm a somewhat competent ruby programmer. Yesterday I decided to finally try my hand with Apple's Cocoa frameworks. Help me see things the ObjC way? I'm trying to get my head around objc_allocateClassPair and objc_registerClassPair. My goal is to dynamically generate a few classes and then be able to use them as I would any other class....

Forwarding Class Messages

I know that I can forward messages to instances of a class using -forwardInvocation:. Can I do the same for messages sent to a class object (as in +forwardInvocation:)? ...

How to extend iWork's Number'09 formulas?

I have specific formulas that I'd like to write (in Objective-C perhaps) and integrate with Numbers'09 of Apple's iWork suite in iPad and wonder if there is such a way to do so? ...

How to create a protocol at runtime in Objective-C?

Hi, First of all, I want to be clear that I'm not talking about defining a protocol, and that I understand the concept of @protocol someprotocol - (void)method; @end I know that the Obj-C runtime allows creation of classes at RUNTIME, as well as its ivars and methods. Also available for creation are SEL-s. I think I'm just missing s...

Objective C: Method have knowledge of context within which it was called?

I'd like to have a reusable logging method or function that spits out the name of the method it's called from. Example: - (void)exampleMethod { CustomLog(); //Outputs "exampleMethod" } ...

Interpret Objective C scripts at runtime on iPhone?

Is there anyway to load an objective c script at runtime, and run it against the classes/methods/objects/functions in the current iPhone app? MAJOR NOTE: The major reason I'd like to do this is to allow me to rapidly prototype an application, and then, after I'm done a major prototyping phase, take the scripts I was writing and compile...

Looking for marg_setValue fix in iPhoneOS

I am trying to compile a library originally written for Cocoa. Things are good until it looks for the function marg_setValue(). It says there is a syntax error before char in marg_setValue(argumentList,argumentOffset,char,(char)lua_toboolean(state,luaArgument)); (it's talking about the third argument, not (char) ) I am trying to port...

variable parameter function - EXC_BAD_ACCESS when calling [obj release];

I have the following method: (void)makeString:(NSString *)str1,... { va_list strings; NSString *innerText = [[NSString alloc] init]; NSString *tmpStr = [[NSString alloc] init]; if (str1) { va_start(strings, str1); while (tmpStr = va_arg(strings, id)) { innerText = [innerText stringByAppend...

GNU Objective-C runtime trickery

Can I, in the GNU Objective-C runtime, attach semi-arbitrary pieces of data to instance variables? Challenge: I'm currently working on a kind of Cocoa workalike for Linux, as a sort of pet project. (Please, let's not get sidetracked by all the "use GNUStep" stuff. I know about it, but it doesn't suit my needs. Moving on…) For this purp...

What exactly is super in Objective-C?

As far as I know, it's a pointer to the superclass. It's hard-wired with the superclass, and not dynamically figured out at runtime. Would like to know it more in detail... Anyone? ...

object_setClass to bigger class

I am changing the class of some objects using object_setClass(id object, Class cls). I am changing the class to a subclass of the original class. Then I set some properties that are only defined on the subclass, and things seem to work fine. I was a bit surprised that this worked, because object_setClass, as far as I understand, doesn't...