Giter Club home page Giter Club logo

Comments (10)

mikeash avatar mikeash commented on July 18, 2024

Works fine for me. Can you show your code?

from maobjcruntime.

mbrandonw avatar mbrandonw commented on July 18, 2024

Sorry, I just realized I'm doing something stupid. I have a setter selector, I convert it into the corresponding getter, and then try to invoke it to get it's return value:

void *value = NULL;
[self rt_returnValue:&value sendSelector:getterSelector];

Since I don't know the return type I just did a void pointer, so of course 4 bytes. And then later I do:

[target rt_returnValue:NULL sendSelector:method.selector, RTARG(value)];

Is it possible to do what I want?

from maobjcruntime.

mikeash avatar mikeash commented on July 18, 2024

I'm not really sure I follow what you're trying to do. Can you post some more complete code that illustrates the problem?

from maobjcruntime.

mbrandonw avatar mbrandonw commented on July 18, 2024

The exact snippet is around line 120: https://github.com/mbrandonw/OPUIKit/blob/master/OPUIKit/Source/OPStyle.m

Basically, an OPStyle instance has a bunch of properties that ultimately get transferred to a target. To do that I loop through the methods in [OPStyleProtocol](https://github.com/mbrandonw/OPUIKit/blob/master/OPUIKit/Source/OPStyleProtocol.h, for each setter I find the corresponding getter, and then do the little snippet I posted above to transfer the property.

Does that make any more sense?

from maobjcruntime.

mikeash avatar mikeash commented on July 18, 2024

Yes, I think I see. Seems to me like this could be done more cleanly by using KVC. Use valueForKey: to get the value, then setValue:forKey: to set it. All problems of argument size, primitives, etc. are handled for you by the KVC internals.

from maobjcruntime.

mikeash avatar mikeash commented on July 18, 2024

I should mention for completeness that there's no good way to do this with MAObjCRuntime directly. The method invocation stuff there is only intended for cases where you know the types in advance. You could do it directly with NSInvocation, but that would be harder than just using KVC.

from maobjcruntime.

mbrandonw avatar mbrandonw commented on July 18, 2024

Wow, that is much cleaner. So, even though we cannot do something like [target setValue:CGRectMake(0,0,100,100) forKey:@"frame"] directly, if we retrieve an value from an object we can set it another object, even if it is a primitive?

from maobjcruntime.

mikeash avatar mikeash commented on July 18, 2024

Right. Primitives get wrapped in NSValue objects, and automatically unwrapped on the other side.

from maobjcruntime.

mbrandonw avatar mbrandonw commented on July 18, 2024

Terrific, thanks so much for the info.

from maobjcruntime.

mikeash avatar mikeash commented on July 18, 2024

Glad I could help!

from maobjcruntime.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.