oa414 / objc-zen-book-cn Goto Github PK
View Code? Open in Web Editor NEWObjC Zen Book 中文翻译
Home Page: https://github.com/oa414/objc-zen-book-cn
License: Other
ObjC Zen Book 中文翻译
Home Page: https://github.com/oa414/objc-zen-book-cn
License: Other
关于这个 pull-request 提到的翻译问题 #18 ,大家可以在这里讨论下 @KevinHM @heistings
原文
Private properties should be declared in class extensions (anonymous categories) in the implementation file of a class. Named categories (e.g.
ZOCPrivate
) should never be used unless extending another class.
译文
私有属性应该定义在类的实现文件的类的扩展 (class extensions) 中。不允许在有名字的的 category(如
ZOCPrivate
)中定义私有属性,除非你扩展其他类。
从Designated initializer开始往下,每一个概念里面,涉及到的知识点,差不多有一半翻译得比较生硬。。。出现很多小错误,有些甚至跟原文意思彻底相反,慢慢来呀,别太急哥们。。。
extern NSString *const ZOCCacheControllerDidClearCacheNotification;
@interface ViewController : UIViewController
static NSString * const ZOCCacheControllerDidClearCacheNotification = @"ZOCCacheControllerDidClearCacheNotification";
@implementation ViewController
错误信息如下:
Static declaration of "ZOCCacheControllerDidClearChacheNotification" follows non-static declaration.
查询了一下iOS SDK中, 使用类似这个:
UIKIT_EXTERN NSString * const NSForegroundColorAttributeName
来提供外部使用
猜测,在.m中,实现方式如下
NSString * const NSForegoundColorAttributeName = @"NSForegoundColorAttributeName";
于是,实验了一下,编译通过:
UIKIT_EXTERN NSString * const kKey;
@interface ViewController : UIViewController
NSString * const kKey = @"Key";
@implementation ViewController
编译通过,运行拿到数据。
如果命名重复,在外部引用时,定义了相同的名字
NSString *kKey = @"a";
NSLog(@"Key: %@",kKey);
这个时候,kKey 是 a。
这句话在第5章。
我不确定,这里的 It's interesting to
似乎相当于 It's good to
,你觉得呢?
我感觉 practice 这个词的含义应该是惯例
,或者引申为编程规范
or 规范
。
practice的定义
noun
the actual application or use of an idea, belief, or method as opposed to theories about such application or use.
"the principles and practice of teaching"
同义词: application, exercise, use, operation, implementation, execution
在"属性定义" 一节中
"为了完成一个共有的 getter 和一个私有的 setter,你应该声明公开的属性为 readonly 并且在类扩展总重新定义通用的属性为 readwrite 的。"
类扩展"总"应该是 " 中" 吧, 一个小错字
你好,原文在讲__weak和__strong关键字的时候举了官方文档的一个例子
MyViewController *myController = [[MyViewController alloc] init...];
// ...
MyViewController * __weak weakMyController = myController;
myController.completionHandler = ^(NSInteger result) {
MyViewController *strongMyController = weakMyController;
if (strongMyController) {
// ...
[strongMyController dismissViewControllerAnimated:YES completion:nil];
// ...
}
else {
// Probably nothing...
}
};
然后作者说self不能被delloc和赋值为nil。我觉得这里是没有问题的,文档中使用MyViewController * __weak weakMyController = myController;
,这里让一个新的指针指向weakMyController所指的指针,但是引用计数应该是没有增加的,这里可以理解成是一个局部变量?然后当block结束该指针会自动释放,所以self还是能够被正常的销毁。
我也不知道我理解的对不对,希望大神指教。
嘿!为中文版设计一个封面吧
There are three different situations that may present when defining a new class:
当顶一个一个新类的时候有三个不同的解决方法
: 1. 不需要重载任何初始化函数 2. 重载 designated initializer 3. 定义一个新的 designated initializer
做了一本Gitbook,方便导出PDF和EPUB查看
有一大段没有翻译,从下面这段开始:
It should rather be valid to call any designated initializer in the class hierarchy, and it should be guaranteed that all the designated initializer in the class hierarchy are called starting from the furthest ancestor (typically NSObject) down to your class. Practically speaking this means that the first initialization code executed is the furthest ancestor, and then going down to the class hierarchy; giving to all the classes in the hierarchy the chance to do their specific part of initialization. This totally make sense: you want that everything you inherit from your superclass is in an usable state before doing your actual work. Even though it isn't explicitly stated, all the classes in Apple's frameworks are guaranteed to respect this contract and your classes should do the same to be sure to be a good citizen and behave correctly and as expected
中文翻译文档中多次提到"重载"这个词,不过根据我个人的理解,它们在文中的意思应该都是"重写"(Override)吧,应该是子类重写父类的方法。OC是没有重载这个特性的 =。=
“你在第一次访问的时候改变了初始化的消耗,产生了副作用,这会让优化性能变得困难(以及测试)”
请问这句话怎么理解?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.