Comments (10)
Works fine for me. Can you show your code?
from maobjcruntime.
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.
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.
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.
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.
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.
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.
Right. Primitives get wrapped in NSValue objects, and automatically unwrapped on the other side.
from maobjcruntime.
Terrific, thanks so much for the info.
from maobjcruntime.
Glad I could help!
from maobjcruntime.
Related Issues (9)
- Attribution for spawned project HOT 6
- Associated Object API HOT 11
- How to get the use of a app traffic?
- Definition of 'Protocol' must be imported from module 'ObjectiveC.Protocol' before it is required HOT 2
- Does it support arc? HOT 1
- How to better use of PLCrashReporter? HOT 1
- TestProtocolQuery fails for i386 HOT 1
- Deployable to App Store? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from maobjcruntime.