如何查看NSLog函数的输出信息

  • 三月 7th, 2010

NSLog类似flash里的 “trace” 或者PHP中的 “echo”,其输出信息可以在XCode console里面看到,快捷键是 CMD+Shift+R

Objective-C 不同类型数据的输出

  • 三月 2nd, 2010

rogramming Guide for Cocoa 中描述道.
The format specifiers supported by the NSString formatting methods and CFString formatting functions follow the IEEE printf specification; the specifiers are summarized in Table 1. Note that you can also use the “n$” positional specifiers such as %1$@ %2$s. For more details, see the IEEE printf specification. You can also use these format specifiers with the NSLog function.
Table 1 Format specifiers supported by the NSString formatting methods and CFString formatting functions.

定义 说明
%@ Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function.
%% ‘%’ character
%d, %D, %i Signed 32-bit integer (int)
%u, %U Unsigned 32-bit integer (unsigned int)
%hi Signed 16-bit integer (short)
%hu Unsigned 16-bit integer (unsigned short)
%qi Signed 64-bit integer (long long)
%qu Unsigned 64-bit integer (unsigned long long)
%x Unsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and lowercase a–f
%X Unsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and uppercase A–F
%qx Unsigned 64-bit integer (unsigned long long), printed in hexadecimal using the digits 0–9 and lowercase a–f
%qX Unsigned 64-bit integer (unsigned long long), printed in hexadecimal using the digits 0–9 and uppercase A–F
%o, %O Unsigned 32-bit integer (unsigned int), printed in octal
%f 64-bit floating-point number (double)
%e 64-bit floating-point number (double), printed in scientific notation using a lowercase e to introduce the exponent
%E 64-bit floating-point number (double), printed in scientific notation using an uppercase E to introduce the exponent
%g 64-bit floating-point number (double), printed in the style of %e if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise
%G 64-bit floating-point number (double), printed in the style of %E if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise
%c 8-bit unsigned character (unsigned char), printed by NSLog() as an ASCII character, or, if not an ASCII character, in the octal format \\ddd or the Unicode hexadecimal format \\udddd, where d is a digit
%C 16-bit Unicode character (unichar), printed by NSLog() as an ASCII character, or, if not an ASCII character, in the octal format \\ddd or the Unicode hexadecimal format \\udddd, where d is a digit
%s Null-terminated array of 8-bit unsigned characters. %s interprets its input in the system encoding rather than, for example, UTF-8.
%S Null-terminated array of 16-bit Unicode characters
%p Void pointer (void *), printed in hexadecimal with the digits 0–9 and lowercase a–f, with a leading 0x
%L Length modifier specifying that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument
%a 64-bit floating-point number (double), printed in scientific notation with a leading 0x and one hexadecimal digit before the decimal point using a lowercase p to introduce the exponent
%A 64-bit floating-point number (double), printed in scientific notation with a leading 0X and one hexadecimal digit before the decimal point using a uppercase P to introduce the exponent
%F 64-bit floating-point number (double), printed in decimal notation
%z Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument
%t Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a ptrdiff_t or the corresponding unsigned integer type argument
%j Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a intmax_t or uintmax_t argument

平台依赖
Mac OS X uses several data types—NSInteger, NSUInteger,CGFloat, and CFIndex—to provide a consistent means of representing values in 32- and 64-bit environments. In a 32-bit environment, NSInteger and NSUInteger are defined as int and unsigned int, respectively. In 64-bit environments, NSInteger and NSUInteger are defined as long and unsigned long, respectively. To avoid the need to use different printf-style type specifiers depending on the platform, you can use the specifiers shown in Table 2. Note that in some cases you may have to cast the value.

Table 2 Format specifiers for data types
类型 定义 建议
NSInteger %ld or %lx Cast the value to long
NSUInteger %lu or %lx Cast the value to unsigned long
CGFloat %f or %g %f works for floats and doubles when formatting; but see below warning when scanning
CFIndex %ld or %lx The same as NSInteger
pointer %p %p adds 0x to the beginning of the output. If you don’t want that, use %lx and cast to long.
long long %lld or %llx long long is 64-bit on both 32- and 64-bit platforms
unsigned long long %llu or %llx unsigned long long is 64-bit on both 32- and 64-bit platforms

as3开源游戏引擎

  • 十月 26th, 2009

从 9ria.com上看到的一篇帖子,觉得还是不错的,有空可以研究一下。

FFlimation

Fflimation 引擎是as3的二维(类似暗黑破坏神)引擎。主要用于游戏开发。这个项目的主要目的是提供一个稳定的开发平台,这样游戏设计师就可以忘记游戏渲染引擎把精力集中在游戏内容的细节方面。从“关卡制作”的角度来看,这个引擎的可用性非常的高。
http://www.ffilmation.org/website/

pushbutton engine
pushbutton引擎是一个开源的,flash游戏引擎,它所设计的框架结构提供了一种新的游戏形成机制。Pushbutton引擎集合了非常多的现存的制作flash游戏的库和组件。花很少的时间写代码,更多的时间用在制作有趣的游戏上面。
http://pushbuttonengine.com/

Citrus Engine
Citrus 引擎是一种基于as3和box2d的flash滚屏平台游戏引擎。Cirus引擎能让设计师和开发者非常快速的容易的创建滚屏平台游戏(又叫横版过关游戏)象超级玛丽。团队可以用citrus引擎给游戏门户制作广告游戏,市场推广游戏,搏逸游戏等等。
http://blueflamedev.com/

Yogurt3D
Yogurt3D 游戏引擎是一款非常新的flash三维引擎,他不需要用户下载插件,因为他是通过浏览器中的flashplayer运行的。Yogurt3d的核心部 分,swiftgl,是开源并且与opengl兼容。这意味着有opengl开发经验的开发者很容易的就可以开发出3d flash游戏和应用程序。他还可以轻易的将opengl代码转化成swiftgl并在flashplayer中运行。
http://www.yogurt3d.com/en/

flixel
flixel 是一款完全免费的as3文件集。它可以帮助你规划,自动的优化flash游戏。面向对象的框架可以让任何人在几个小时内制作出原创的复杂的,包含上千个物件的游戏。
http://flixel.org/

[转]PHP Json函数不能处理中文的解决办法

  • 十月 8th, 2009

php5.2新增的json功能是非常受欢迎的,但是经过测试发现,json_encode对中文的处理是有问题的;

  • 不能处理GB编码,所有的GB编码都会替换成空字符.
  • utf8编码的中文被编码成unicode编码,相当于javascript的escape函数处理的结果.

为了能正确使用json,首先我们就应该在编码上采用utf8编码,然后再对json_encode的返回结果稍加处理就可以得到正确的结果了。
我写了一个简单的类,将这两个函数包装了一下:

class Json{
	public static function encode($str){
		$code = json_encode($str);
		return preg_replace("#\\\u([0-9a-f]+)#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", $code);
	}
 
	public static function decode($str){
		return json_decode($str);
	}
}

使用的时候

Json::encode($code);
Json::decode($code);

这样可以正确处理utf8编码的中文了。

PS:对于GB编码的中文,我们可以在编码时先转成UTF8编码,再进行编码,解码的时候再进行一个utf8 -> gb的转换就可以了。
另外一般json_encode的结果我们是返回到客户端来使用,我们其实还可以用javascript的unescape函数来对unicode编码的中文进行解码,从而还原成正确的中文。

或者用:

$title = mb_convert_encoding($title, 'HTML-ENTITIES', $this->_outCharset);
//任意编码下都正常显示

FLVTool2操作命令

  • 九月 29th, 2009

vtool2下载连接:
http://rubyforge.org/frs/?group_id=1096&release_id=4615

有些来路不明的FLV文件Meta Data是损坏的,播放起来很是不方便。今天试着找到Flvtool2,Flvmdi,效果确实可以,非常方便。感觉两者没有太大差别,只是后者还提供了一个Windows下的GUI而已。

Flvtool2
http://blog.inlet-media.de/flvtool2/

其命令格式:flvtool2.exe [-ACDPUVaciklnoprstvx]… [-key:value]… in-path|stdin [out-path|stdout]

如果out-path未定义,则将覆盖原文件,如果指定in-path为目录,out-path应为同一目录,否则将被忽略。

命令:

-A            Adds tags from -t tags-file
-C            Cuts file using -i inpoint and -o outpoint
-D            Debugs file (writes a lot to stdout)
-H            Helpscreen will be shown
-P            Prints out meta data to stdout
-U            Updates FLV with an onMetaTag event

可选参数:

-a            Collapse space between cutted regions
-c            Compatibility mode calculates some onMetaTag values different
-key:value    Key-value-pair for onMetaData tag (overwrites generated values)
-i timestamp  Inpoint for cut command in miliseconds
-k            Keyframe mode slides onCuePoint(navigation) tags added by the
add command to nearest keyframe position
-l            Logs FLV stream reading to stream.log in current directory
-n            Number of tag to debug
-o timestamp  Outpoint for cut command in miliseconds
-p            Preserve mode only updates FLVs that have not been processed
before
-r            Recursion for directory processing
-s            Simulation mode never writes FLV data to out-path
-t path       Tagfile (MetaTags written in XML)
-v            Verbose mode
-x            XML mode instead of YAML mode

举个简单的例子,新建文本文件,敲入下列内容,另存为.DAT批处理文件

Windows: “C:\Program Files\flvtool2.exe” -UPx “C:\in.flv” “C:\out.flv”
Linux:flvtool2 –UPx in.flv out.flv

运行该批处理文件,将更新(修复)C:\in.flv文件的Meta Data,同时按照XML格式输出Meta Data信息内容到屏幕。

PHP调用方法(未测试):

$str = 'flvtool2 -C -i 480000  /usr/local/apache2/htdocs/www/200811211441000000.flv   /usr/local/apache2/htdocs/www/new200811211441000000.flv';
echo $showtime=date("Y-m-d H:i:s");
$result = exec($str);
if($result){
    echo $showtime=date("Y-m-d H:i:s");
}else{
    echo 3333;
}

听说只有root权限才可以运行php的命令

@