简体   繁体   English

如何以2种不同的方法使用对象

[英]How to use an object in 2 different methods

So I have an object and I want the object to be able to use in 2 different methods. 所以我有一个对象,并且希望该对象能够在2种不同的方法中使用。 Is it possible? 可能吗? If not, is there any work arounds for this. 如果没有,是否有任何解决方法。

Of course. 当然。 Objects live in dynamic memory and are pointed to by pointers. 对象位于动态内存中,并由指针指向。 So long as you have a reference (the pointer) to an object you can access it from wherever you want. 只要您有对象的引用(指针),就可以从任意位置访问它。

NSObject *theReference = [[NSObject alloc] init];

After this call, and where theReference is in scope, you will have access to the object. 调用之后,并且在引用的作用域中,您将有权访问该对象。

Yes, this is possible. 是的,这是可能的。 An object can be used in 2 different methods. 一个对象可以用两种不同的方法来使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM