查找从中调用方法的位置 [英] Finding where a method was called from

查看:95
本文介绍了查找从中调用方法的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何知道方法是从哪里调用的?就像你在堆栈跟踪中看到的。

How would I find out where a method was called from? Like you see in a stack trace.

基本上,只是为了解释,我观察一个核心数据属性和方法,当属性更改调用另一个方法IBAction),但是在这个IBAction中,它添加了核心数据对象,其触发触发IBAction等的KVO方法。这就是为什么我试图找出方法被调用的地方,所以我可以停止这个无限循环。

Basically, just to explain, I am observing a core data property and the method that gets called when the property changes calls another method (the IBAction) but in this IBAction it adds Core Data objects which triggers the KVO method which triggers the IBAction and so forth. That is why I was trying to figure out where the method was called from so I could stop this infinite loop.

推荐答案

没有很大的重复调试器,dtrace和/或各种其他工具的功能完全正是这种事情。它显然是架构依赖和特殊情况和情况下,flat out不工作。

You can't without going to great lengths to duplicate the functionality of the debugger, dtrace, and/or the various other tools that do exactly this kind of thing. It is remarkably architecture dependent and rife with special cases and situations that flat out don't work.

你肯定不会想在生产代码中做这样的事情。对于调试,有足够的工具,在足够的上下文中,这是没有必要这样做。

You certainly would never want to do such a thing in production code. For debugging, there are enough tools that do this in enough contexts that there is no need to do so.

你想做什么?


基本上我使用KVO,如果KVO
方法是从另一个
方法触发的,这是一个IBAction我不
它会做什么它通常
否则它会进入一个循环
(与我的早期问题相关)。

Basically i'm using KVO and if the KVO method is triggered from another method which is an IBAction I don't what it to do what it would normally do otherwise it would go into a loop (related to my earlier question).

这条道路就在于疯狂。它完全打破了封装,有一个方法的执行受到调用者的影响,而不是某种显式的参数或隐式配置,表明行为应该改变。

Down this path lies madness. It totally breaks encapsulation to have a method whose execution is impacted by a caller without their being some kind of explicit argument or implicit configuration indicating that the behavior should change.

如果你

特别是,当KVO通知触发时,应该几乎不会

In particular, when a KVO notification fires, it should almost never trigger a KVO notification of the same property either directly or indirectly. In the exceedingly rare case where this is unavoidable, you should make sure you do the KVO triggers by hand using -willChangeValueForKey: and -didChangeValueForKey: conditionally.


基本上,只是为了解释,我是
观察核心数据属性,
方法,当
属性更改调用另一个方法
(IBAction)时调用,但在此IBAction它
添加Core Data对象,触发
KVO方法触发
IBAction等。这就是为什么I
试图找出
方法被调用的位置,因此我可以停止
这个无限循环

Basically, just to explain, I am observing a core data property and the method that gets called when the property changes calls another method (the IBAction) but in this IBAction it adds Core Data objects which triggers the KVO method which triggers the IBAction and so forth. That is why I was trying to figure out where the method was called from so I could stop this infinite loop

换句话说,你有一个模型层改变,然后在视图层和控制层之间的接口(IBAction方法)调用一个方法,然后,毫不奇怪,触发另一个模型层次的改变,然后

In other words, you have a model layer change that is then calling a method at the interface between view layer and control layer (the IBAction method) that then, not surprisingly, triggers another model level change which then goes off the rails....

一旦你的观察器触发,你需要在模型中做一个更改,你应该保持所有的更改逻辑模型层。毕竟,它是你的模型,它应该有智能来适当地应用更改。

Once your observer fires and you need to make a change in the model as a result, you should keep all of the change logic within the model layer. It is your model, after all, and it should have the smarts to apply changes appropriately.

不应该发生的是,控制层或视图层触发更改模型响应模型变化。

What should never happen is that the control layer or view layer triggers changes to the model in response to the model changing. Changes to the model -- to the data -- from the control/view layer should only ever occur in response to user action or some external event (a timer, perchance).

这篇关于查找从中调用方法的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆