Отладка Xcode 3.2: Наблюдение, что находится в массиве?

String.prototype.replaceAll = function (replaceThis, withThis) {
   var re = new RegExp(RegExp.quote(replaceThis),"g"); 
   return this.replace(re, withThis);
};


RegExp.quote = function(str) {
     return str.replace(/([.?*+^$[\]\\(){}-])/g, "\\$1");
};

var aa = "qwerr.erer".replaceAll(".","A");
alert(aa);

сообщение silmiar

16
задан Community 8 February 2017 в 14:15
поделиться

3 ответа

Я видел намного хуже, но вы могли бы его немного улучшить.

  1. Вместо StringBuilder.Append () со строкой.Format () внутри используйте StringBuilder.AppendFormat ()
  2. Добавьте вокруг него несколько модульных тестов, чтобы убедиться, что он дает желаемый результат, а затем выполните рефакторинг кода внутри, чтобы он стал лучше. Тесты гарантируют, что вы ничего не сломали. When you are debugging and you are in a method where you know a local variable must be in scope right now, open the debugger window and the area where you can see "Variable", "Value" and "Summary" column titles double click the "Summary" row entry for the variable you are interested in and enter the following (for array types like NSArray or NSCFArray):

    "{(int)[$VAR count]} objects {(NSString *)[(NSArray *)$VAR description]}:s"

    then press return. You have now overwritten the default data formatter provided by Xcode's GDB extension (to be found in various plists at "/Developer/Library/Xcode/CustomDataViews/") with your own data formatter string.

    Your own overrides are saved at "~/Library/Application Support/Developer/Shared/Xcode/CustomDataViews/CustomDataViews.plist" and if you want to have the Apple default data formatter back just double click the row for a variable of the same type and delete whatever is there.

    The nitty-gritty details: In the custom expression above the "{}" construct tells GDB to execute a command (as if you where executing it from GDB's debugger command line, which means the same restrictions apply: you need to specify the return type in cast parens in front of every function or method which returns something). The ":s" behind the closing curly brace tells Xcode and GDB to reference the "Summary" column. Also valid would be ":v" which references the "Value" column which most of the time is just the pointer value. Everything that is outside of the curly braces is shown verbatim. Unfortuntely curly braces can't be nested which invalidates ternary operator conditionals.

    So with the above data formatter you should see the following for an empty NSArray:

    "0 objects (\n)"

    If you want to write your own data formatters as GDB extensions (equivalent to specifying a function akin to Xcode_CFStringSummary above) you can do so. Take a look at the following header: "/Developer/Applications/Xcode.app/Contents/PlugIns/GDBMIDebugging.xcplugin/Contents/Headers/DataFormatterPlugin.h"

    it will tell you all you need to know. But it can be hard to get it right. It might be easier and less error prone to just define another method on your class and call that from the data formatter string instead of "description".

18
ответ дан 30 November 2019 в 21:45
поделиться

Включено ли в меню «Выполнить»> «Просмотр переменных» в Xcode «Использовать форматеры данных»?

4
ответ дан 30 November 2019 в 21:45
поделиться

Я не уверен, поможет ли это, но если вы выберете значение массива, которое хотите увидеть в окне отладчика, и перейдите в Меню: Выполнить> Просмотр переменных> Просмотреть переменную как вы можете изменить его с «NSCFString *» на «NSString *». Затем вы увидите значение, например «Планета_1».

Ура,

Кевин

2
ответ дан 30 November 2019 в 21:45
поделиться
Другие вопросы по тегам:

Похожие вопросы: