避免使用 description 等作为属性名

自 Xcode 6 起,继承于 NSObject 的类一定要避免使用 description 等作为属性的名字,否则会被认为是 NSObject 中的 description 属性。

警告内容:

Auto property synthesis will not synthesize property 'description' because it is 'readwrite' but it will be synthesized 'readonly' via another property.

如果在代码中执行了 setDescription,则程序会崩溃,错误信息:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AnObject setDescription:]: unrecognized selector sent to instance 0x79e8b260'

如果在代码中试图取 description 的值,则会得到 NSObject 的 description 属性,即该对象的指针,如 <AnObject: 0x7c97f870>

其实本就该避免,只不过之前不会出问题而已。