objective-c-runtime

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

帅比萌擦擦* 提交于 2019-12-01 16:50:51
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 if the runtime has already instantiated your class object using the class description. So are all Class definitions allocated statically at first run to provide the ability to instantiate using the Class object? Or if they are allocated dynamically (on initial

Get the object which called a method

强颜欢笑 提交于 2019-12-01 16:41:07
If I have a call from within a random class like this: @implementation SomeClass - (void) classMethodFoo { int a = [SomeSingleton sharedInstance].aValue; } @end Inside SomeSingleton sharedInstance , is there a way to get a reference to the object which called this method (without the called passing self as a parameter of course)? No, information about the caller isn't passed along automatically. This is why IBAction methods, for instance, have a sender parameter, and why delegate methods often have a parameter that refers to the delegate's object. 来源: https://stackoverflow.com/questions

What's wrong with using a category on NSObject to provide a default protocol implementation?

安稳与你 提交于 2019-12-01 16:23:48
I've been looking for a way to use optional protocol methods and have clean code. In other words: 1: No respondsToSelector: calls all over my code 2. Should work for any method signature, so a category method on NSObject making the check and calling performSelector: is out (and NSInvocation has problems cooperating with ARC) 3: This solution , IMO, pretends to be universal but has all the drawbacks of 1 I eventually came up with this idea: @protocol MyProtocol <NSObject> @optional -(void)optionalMethod; @end @interface ClassA : NSObject <MyProtocol> @end @implementation ClassA -(void

Get the object which called a method

谁说胖子不能爱 提交于 2019-12-01 15:39:17
问题 If I have a call from within a random class like this: @implementation SomeClass - (void) classMethodFoo { int a = [SomeSingleton sharedInstance].aValue; } @end Inside SomeSingleton sharedInstance , is there a way to get a reference to the object which called this method (without the called passing self as a parameter of course)? 回答1: No, information about the caller isn't passed along automatically. This is why IBAction methods, for instance, have a sender parameter, and why delegate methods

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

社会主义新天地 提交于 2019-12-01 15:27:54
问题 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 if the runtime has already instantiated your class object using the class description. So are all Class definitions allocated statically at first run to provide

Understanding uniqueness of selectors in Objective-C

南笙酒味 提交于 2019-12-01 10:34:05
I am having problem understanding part of the function of "selectors", as described in Apple's guide. I've bolded the parts where I am getting confused: In Objective-C, selector has two meanings. It can be used to refer simply to the name of a method when it’s used in a source-code message to an object. It also, though, refers to the unique identifier that replaces the name when the source code is compiled. Compiled selectors are of type SEL. All methods with the same name have the same selector. You can use a selector to invoke a method on an object—this provides the basis for the

how to override/swizzle a method of a private class in runtime objective-c?

邮差的信 提交于 2019-12-01 00:31:52
To give a bit of context of why I'm asking this: basically I would like to change the location of the myLocationButton of the google map on iOS. So I first fetch the actual button like so: @implementation GMSMapView (UIChanges) - (UIButton *)myLocationButton { UIButton *myLocationButton; for (myLocationButton in [settingView subviews]) { if ([myLocationButton isMemberOfClass:[UIButton class]]) break; } return myLocationButton; } Then I try to change it's position in the screen using NSLayoutConstraints (directly changing values of the frame property of the button does nothing with google maps

how to override/swizzle a method of a private class in runtime objective-c?

半城伤御伤魂 提交于 2019-11-30 19:43:46
问题 To give a bit of context of why I'm asking this: basically I would like to change the location of the myLocationButton of the google map on iOS. So I first fetch the actual button like so: @implementation GMSMapView (UIChanges) - (UIButton *)myLocationButton { UIButton *myLocationButton; for (myLocationButton in [settingView subviews]) { if ([myLocationButton isMemberOfClass:[UIButton class]]) break; } return myLocationButton; } Then I try to change it's position in the screen using

Why can't gcc or clang properly @encode SIMD vector types?

时光毁灭记忆、已成空白 提交于 2019-11-30 19:13:22
While doing some messing around with vector types and the ObjC runtime, I came across a very perplexing problem. Neither clang or GCC will give the 'proper' type-encoding for any SIMD vector type, as far as I can tell. #import <Foundation/Foundation.h> int main() { typedef int int4 __attribute__((vector_size(16))); typedef float float4 __attribute__((vector_size(16))); NSLog(@"Int4: %s", @encode(int4)); NSLog(@"Float4: %s", @encode(float4)); } When compiled & run with either GCC or clang, I get the following output: 2014-04-09 06:21:01.102 test[1707:507] Int4: 2014-04-09 06:21:01.103 test[1707

object_getInstanceVariable works for float, int, bool, but not for double?

懵懂的女人 提交于 2019-11-30 12:48:57
问题 I've got object_getInstanceVariable to work as here however it seems to only work for floats, bools and ints not doubles. I do suspect I'm doing something wrong but I've been going in circles with this. float myFloatValue; float someFloat = 2.123f; object_getInstanceVariable(self, "someFloat", (void*)&myFloatValue); works, and myFloatValue = 2.123 but when I try double myDoubleValue; double someDouble = 2.123f; object_getInstanceVariable(self, "someDouble", (void*)&myDoubleValue); I get