2

これは可能ですか?

具体的な例を作るために、次のマクロを考えてみましょう:

define pos
po ([self $arg0])
end

したがって、pos テキストを入力すると、po [self text] に変換されます。しかし、複数の引数を指定すると失敗します。たとえば、pos textLabel テキストは、目的の po [[self textLabel]text] ではなく、po [self textLabel] に変換されます。

別の例として、3 つのコマンドのように

po someIvar_
po [self someMethod]
po [[self someMethod]someOtherMethod] 

参照されている 3 つのオブジェクトの説明を出力します。整数に対して同じことを行うマクロ pi を定義するとよいでしょう。つまり、

pi [self someMethod] 

呼び出しと同じです

print (int)[self someMethod], 

同様に

pi [[self someMethod]someOtherMethod].
4

2 に答える 2

1

user-defined commands are just a bit more than string-replaces before executing. Your example pos textLabel text passes two parameters to a command which only considers one parameter. The second is thrown away. It should result in po [self textLabel] before executing. What you do is comparable to the following java-sum-function:
int sum(int[] args){return args.get(0);}

what you need is sth mentioned here :

define pos
    if $argc == 1
        po [self $arg0]
    end
    if $argc == 2
        po [[self $arg0] $arg1]
    end
    ..... (as many you need)
end

I have not found any kind of a loop. So this should be the only way to do this except it is possible to to pop arg0 out of args and recursive-calls of user-defined-commands are allowed. But I think its easier to complete the example above.

pi should be implemented the same way

define pi
    if $argc == 1
        print (int)[self $arg0]
    end
    if $argc == 2
        print (int)[[self $arg0] $arg1]
    end
    ....
end

maybe there is a better solution but this brings you a step further towards your destination.

于 2011-09-29T16:16:07.130 に答える
0

ターミナルでpopiコマンドを使用してオブジェクトの値を確認しようとしている場合、または実行時に値を変更したい場合は、次の解決策があります。

XCode 4でObjectiveCコードをデバッグおよび分析するための最良のソリューションは、次のとおりです。実行時に変数の値を変更する場合は、[実行]>[表示]>[式...]をクリックするだけで簡単に変更できます。変数名に値を提供できます。

しかし、あなたの問題はObjective-Cの問題ではないと思いますが、それでも私は解決策を提供するために最善を尽くしました。

于 2011-09-29T17:46:08.550 に答える