o CGPoint , ad esempio. A sintaxe NSLog(@"%@", ... ); funciona e é usado para obter informações sobre objetos, mas não funciona em tipos de dados, tais como C struct CGRect ou CGPoint , por exemplo. o NSStringFromCGPoint : Para aproveitar NSLog(@"%@", ... ); mesmo em estilo C structs podem contar com funções de conversão como NSStringFromCGRect() ou NSStringFromCGPoint :
1 2 3 4 5 | CGRect ) { 10 , 20 , 30 , 40 } ; CGRect mioRect = (CGRect) {10, 20, 30, 40}; CGPoint ) { 32 , 64 } ; CGPoint mioPoint = (CGPoint) {32, 64}; / / "Info rettangolo: %@" , NSStringFromCGRect ( mioRect ) ) ; NSLog (@ "rectângulo Info:% @", NSStringFromCGRect (mioRect)); "Info point: %@" , NSStringFromCGPoint ( mioPoint ) ) ; NSLog (@ "ponto de Info:% @", NSStringFromCGPoint (mioPoint)); |
Especificamente, é possível melhorar este procedimento escreve de pequenas macros úteis como:
1 | # Define NSLogRect (rect) NSLog (@ "0.0fx%% s (% 0.0f,% 0.0f) 0.0f%", # rect, rect.origin.x, rect.origin.y, rect.size.width , rect.size.height) |
Ou:
1 2 3 4 | # Define NSLogCGPoint (ponto) NSLog (@ "% s (% 0.0f,% 0.0f)", # ponto point.x, Point.y) CGPoint ) { 32 , 64 } ; CGPoint mioPoint = (CGPoint) {32, 64}; ; NSLogCGPoint (mioPoint); |
Que dará como saída:
1 | 32 , 64 ) mioPoint: (32, 64) |










Não há comentários para este post
Deixe um comentário