{"id":566,"date":"2012-09-13T10:20:37","date_gmt":"2012-09-13T10:20:37","guid":{"rendered":"http:\/\/phyline.com\/blog\/?p=566"},"modified":"2015-08-13T18:56:33","modified_gmt":"2015-08-13T18:56:33","slug":"depurando-con-dlog","status":"publish","type":"post","link":"http:\/\/sophyonline.com\/blog\/2012\/09\/depurando-con-dlog\/","title":{"rendered":"Depurando con DLog"},"content":{"rendered":"<p>Muchas veces, sino siempre, es necesario realizar depuraciones en nuestro c\u00f3digo para determinar si hemos hecho las cosas bien o no, y b\u00e1sicamente para imprimir en la consola los valores que nos interesa observar. En Objective-C existe una forma, la tradicional de depurar que es usando la macro NSLog<\/p>\n<pre> NSLog(@\"Bla blah\");\r\n\r\n<\/pre>\n<p>NSLOG seguir\u00e1 mostrando informaci\u00f3n en consola, aunque activemos la opci\u00f3n DEBUG (debug flag). Para evitar esto, existe la opci\u00f3n para debug llamada DLOG, que es otro macro que dejar\u00e1 de imprimir en consola cuando la bandera DEBUG este desactivada. De este modo, podremos dejar nuestros comentarios DLOG si desactivamos el modo debug.<\/p>\n<p>Basta simplemente con hacer una cabecera (.h) (que yo llamare Macros.h) con el siguiente c\u00f3digo:<\/p>\n<p>&nbsp;<\/p>\n<pre>#ifdef DEBUG\r\n#define DLog(...) NSLog(@\"%s %@\", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])\r\n#else\r\n#define DLog(...) do { } while (0)\r\n#endif<\/pre>\n<p>y para usarlo en todo el proyecto, simplemente importalo al archivo<\/p>\n<pre>MyProjectExample-Prefix.pch<\/pre>\n<p>que se ver\u00eda as\u00ed<\/p>\n<pre>\/\/\r\n\/\/ Prefix header for all source files of the 'ProjectExample' target in the 'ProjectExample' project\r\n\/\/\r\n#import\r\n#ifndef __IPHONE_4_0\r\n#warning \"This project uses features only available in iOS SDK 4.0 and later.\"\r\n#endif\r\n\r\n#ifdef __OBJC__\r\n#import &lt;UIKit\/UIKit.h&gt;\r\n#import &lt;Foundation\/Foundation.h&gt;\r\n#import \"Macros.h\"\r\n#endif<\/pre>\n<p>Ahora intenta emplearlo de la misma forma que con el NSLog. \u00bfQu\u00e9 tal?<\/p>\n<p>Dejo el c\u00f3digo fuente para que lo veas mejor: <a title=\"aqu\u00ed\" href=\"http:\/\/sophyonline.com\/blog\/codigoFuente\/dLog\/ProjectExample.zip\">aqu\u00ed<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Muchas veces, sino siempre, es necesario realizar depuraciones en nuestro c\u00f3digo para determinar si hemos hecho las cosas bien o no, y b\u00e1sicamente para imprimir en la consola los valores que nos interesa observar. En Objective-C existe una forma, la tradicional de depurar que es usando la macro NSLog NSLog(@&#8221;Bla blah&#8221;); NSLOG seguir\u00e1 mostrando informaci\u00f3n <a class=\"read-more\" href=\"http:\/\/sophyonline.com\/blog\/2012\/09\/depurando-con-dlog\/\">&hellip;&nbsp;<span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[],"tags":[],"class_list":["post-566","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts\/566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/comments?post=566"}],"version-history":[{"count":20,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts\/566\/revisions"}],"predecessor-version":[{"id":693,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts\/566\/revisions\/693"}],"wp:attachment":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/media?parent=566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/categories?post=566"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/tags?post=566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}