Questions tagged [nsproxy]

NSProxy is an abstract superclass defining an API for objects that act as stand-ins for other objects or for objects that don’t exist yet. Typically, a message to a proxy is forwarded to the real object or causes the proxy to load (or transform itself into) the real object. Subclasses of NSProxy can be used to implement transparent distributed messaging (for example, NSDistantObject) or for lazy instantiation of objects that are expensive to create.

NSProxy is an abstract superclass defining an API for objects that act as stand-ins for other objects or for objects that don’t exist yet. Typically, a message to a proxy is forwarded to the real object or causes the proxy to load (or transform itself into) the real object. Subclasses of NSProxy can be used to implement transparent distributed messaging (for example, NSDistantObject) or for lazy instantiation of objects that are expensive to create.

NSProxy implements the basic methods required of a root class, including those defined in the NSObject protocol. However, as an abstract class it doesn’t provide an initialization method, and it raises an exception upon receiving any message it doesn’t respond to. A concrete subclass must therefore provide an initialization or creation method and override the forwardInvocation: and methodSignatureForSelector: methods to handle messages that it doesn’t implement itself. A subclass’s implementation of forwardInvocation: should do whatever is needed to process the invocation, such as forwarding the invocation over the network or loading the real object and passing it the invocation. methodSignatureForSelector: is required to provide argument type information for a given message; a subclass’s implementation should be able to determine the argument types for the messages it needs to forward and should construct an NSMethodSignature object accordingly. See the NSDistantObject, NSInvocation, and NSMethodSignature class specifications for more information.

26 questions
18
votes
2 answers

Real examples where NSProxy class is useful and why?

I have been wondering why is NSProxy class so important. Why does an object need to keep its instance variables inside other objects? I need examples to understand when to use it. Thanks!
Lluís
  • 578
  • 1
  • 5
  • 10
14
votes
2 answers

NSProxy and Key Value Observing

NSProxy seems to work very well as stand-in objects for those that don't yet exist. For example. - (NSMethodSignature *)methodSignatureForSelector:(SEL)sel { return [self.target methodSignatureForSelector:sel]; } -…
Tony
  • 36,591
  • 10
  • 48
  • 83
14
votes
4 answers

Anybody successful with NSProxy of UIView (e.g., UILabel?)

I am experimenting in adding functionality to my UIViews (configuring CALayers according to state) by setting up a NSProxy subclass to stand in for any UIView I choose. Here's what I've tried: In my NSProxy subclass, I have the following…
henryaz
  • 870
  • 1
  • 8
  • 18
12
votes
2 answers

How does NSProxy "transform itself into another object"?

The NSProxy Class Reference says this: Typically, a message to a proxy is forwarded to the real object or causes the proxy to load (or transform itself into) the real object. How exactly would the "transform itself into the real object" work? To…
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
10
votes
3 answers

How can I get OCMock under ARC to stop nilling an NSProxy subclass set using a weak property?

Under ARC, I have an object, Child that has a weak property, parent. I'm trying to write some tests for Child, and I'm mocking its parent property using OCMock. Under ARC, setting an NSProxy subclass using a synthesized weak property setter doesn't…
10
votes
2 answers

Objective-C - What are some uses of the NSProxy class?

What are some uses of the NSProxy class. Why would you want to be able to have the description of an object that doesn't exist?
aryaxt
  • 76,198
  • 92
  • 293
  • 442
7
votes
1 answer

Use NSProxy in Swift 4.1

How to create an NSProxy subclass in Swift? Trying to add any of the init methods fails with error: "Super init can't be called outside of the initializer", or "Super init isn't called on all paths before returning from initializer" Using…
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115
7
votes
1 answer

NSProxy pretending to be Class doesn't handle respondsToSelector in 64-bit runtime

In OCMockito, test doubles are implemented with NSProxy. A double standing in for an instance implements -respondsToSelector: as follows: - (BOOL)respondsToSelector:(SEL)aSelector { return [_mockedClass…
Jon Reid
  • 20,545
  • 2
  • 64
  • 95
5
votes
1 answer

Disable instance method not found warning

I'm currently working on an NSProxy subclass which intercepts certain messages and never forwards them to anyone but just processes them, so these methods never really exist. And here comes the problem, obviously the compiler starts to complain…
JustSid
  • 25,168
  • 7
  • 79
  • 97
5
votes
1 answer

Proxy Pattern in iOS - Swift

I need to create proxy pattern in iOS using swift I have tried it using Objective C and here is the code MyProtocol.h #import @protocol MyProtocol @required -(void)testMessage; @end TestBO.h #import…
Girish Nair
  • 5,148
  • 5
  • 40
  • 61
2
votes
2 answers

How can I detect if an object I have is really an NSProxy?

I'm poking around a bit in some of the more suspicious objects apple APIs hand out to me, (like mutableArrayValueForKeyPath) and it got me wondering how often apple gives me what I believe to be a certain object, but is really just an NSProxy, which…
Alex Gosselin
  • 2,942
  • 21
  • 37
2
votes
3 answers

Cocoa, NSProxy, How to take over a method in an object?

I need to replace a method in an object with my own implementation. For example, Person *p; // some object NSMutableArray *array = [NSMutableArray array]; [array addObject: p]; How can I replace addObject with a method of my own? In other words,…
Abbas
  • 3,228
  • 1
  • 23
  • 27
2
votes
2 answers

CORBA on Mac OS X (Cocoa)

I am currently looking into different ways to support distributed model objects (that is, a computational model that runs on several different computers) in a project that initially focuses on Mac OS X (using Cocoa). As far as I know there is the…
user8472
  • 3,268
  • 3
  • 35
  • 62
2
votes
1 answer

Can I autorelease an instance of NSProxy?

Does NSProxy really implement -autorelease and -release? If not, do I need to manually dealloc NSProxy instances? (Please assume that I am not using GC). Thanks for clearing this up for me.
Jonathan Sterling
  • 18,320
  • 12
  • 67
  • 79
2
votes
1 answer

iOS: NSProxy can't hook method called inside of Class itself

I use NSProxy to mock a class, and want to hook all invocation of the class. But only methods called outside the class are hooked, without methods called inside the class. Below is something like my code: In my AppDelegate.m, TBClassMock is…
keywind
  • 1,135
  • 14
  • 24
1
2