Learn Objectvie-C on the Mac 2nd Edition 笔记
Chapter 1
Apple’s Cocoa (for OS X) 和 Cocoa Touch (for iOS) toolkits 都是用 Objective-C写的.
Chapter 2
(1) .m 代表 “messages”的缩写
.m -> Object-C compiler
.c -> C compiler
.cpp -> C++ compiler
(2)在 Objective-C中, #import 保证了每个头文件只被包含一次,如同c中的#ifdef头文件卫士的作用一样。
#import <> // 系统头文件
#import " " // 用户自定义头文件
(3)NSLog()如同 C中的printf(),不过增加了时间和日期戳,并自动在行尾加了“\n"换行符。
@(" ")表示" "中的字符串被当做一个NSString单元来处理。在NSLog中如果直接使用了C风格的字符串”“而缺少@(),则在编译时得到一个warning,运行时会crash。
(4)BOOL 类型
在Objectvie-C中,BOOL类型是实际上是一个signed char的typedef,因此不仅可以用YES(值=1)和NO(值=0)表示C中的true和false,而且可以存放其他的值。这里会有一个易错点:如果将一个short或int等类型的值赋给BOOL变量后,会截断末尾的8位,如果这末尾8位值刚好为0(如8960,其十六进制值为 0X2300),此值的BOOL值就是0,即NO,而不是非NO了。
Chapter 3
(1)计算机科学的核心思想:Indirection。Instead of using a value dirctly in your code, use a pointer to the value; Instead of doing something by yourself, ask another person to do it.
(2)一个文件读取示例:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
if(argc == )
{
NSLog (@"You need to provide a file Name");
return ().
} FILE *wordFile = fopen(argv[1], "r"); // argv[0] is the code file path
char word[];
while(fgets(word, , wordFile)
{
// strip off the trailing \n
word[strlen(word) - ] = '\0';
NSLog(@"%s kis %lu characters long", word, strlen(word));
}
fclose(wordFile);
return().
} // main
(3)在Objective-C中,方法调用采用的是中缀表示法(infix notation),如
[circle setFillColor: kRedColor];
如果一个方法无参数,则无冒号和参数列表;如果有参数,则有冒号:
- (void) scratchTheCat; // 无参数
- (void) scratchTheCat: (CatType) critter; // 有参数
Chapter 6
(1)Objective-C类的代码可以分为2个部分:
1>. @interface 部分 .h 文件
#define part
extern global variables;
@interface XX : YY
{
public structs;
} public method declarations. @end
提供了该类的公共接口声明。
2>. @implementation 部分 .m文件
@interface XX
{
private structs;
}
@end @implementation XX private self-used methods @end
提供了该类的实现以及内部函数。
如果以.mm为文件后缀,则表示使用了Objective -C++,即使用C++和Objective-C混合代码。
(2) 头文件中,使用类前置声明,以避免交叉编译出错:
@class XYX;
chapter 8 User Interface Kit(UIKit)
(1) Foundation framework 类:
NSString
NSArray
NSEnumerator
NSRange
NSNumber
(2) CoreFoundation (Foundation framework build on it )
函数名或变量名以”CF“开头:
CGSize
CGPoint, CGPointMake()
CGRect, CGRectMake()
Learn Objectvie-C on the Mac 2nd Edition 笔记的更多相关文章
- C++11新特性——The C++ standard library, 2nd Edition 笔记(一)
前言 这是我阅读<The C++ standard library, 2nd Edition>所做读书笔记的第一篇.这个系列基本上会以一章一篇的节奏来写,少数以C++03为主的章节会和其它 ...
- C++11的一般概念——The C++ standard library, 2nd Edition 笔记(二)
( 原书第四章,General Concepts) 只介绍新内容,关于头文件格式和后缀等C++03已经规范化的内容,不再赘述. namespace std:新的std子空间包括: std::tr1, ...
- Entity Framework 6 Recipes 2nd Edition 译 -> 目录 -持续更新
因为看了<Entity Framework 6 Recipes 2nd Edition>这本书前面8章的翻译,感谢china_fucan. 从第九章开始,我是边看边译的,没有通读,加之英语 ...
- 第十五周翻译-《Pro SQL Server Internals, 2nd edition》
<Pro SQL Server Internals, 2nd edition> 作者:Dmitri Korotkevitch 翻译:赖慧芳 译文: 55-58页 第三章 统计 SQL Se ...
- 第十四周翻译-《Pro SQL Server Internals, 2nd edition》
<Pro SQL Server Internals, 2nd edition> 作者:Dmitri Korotkevitch 翻译:赖慧芳 译文: 设计和优化索引 定义一种应用于所有地方的 ...
- 第十三周翻译-《Pro SQL Server Internals, 2nd edition》
<Pro SQL Server Internals, 2nd edition> 作者:Dmitri Korotkevitch 翻译:赖慧芳 译文: 聚集索引 聚集索引指示表中数据的物理顺序 ...
- 第十二周翻译-《Pro SQL Server Internals, 2nd edition》
<Pro SQL Server Internals, 2nd edition> 作者:Dmitri Korotkevitch 翻译:赖慧芳 译文: 专业SQL服务器内部 了解在引擎盖下发生 ...
- RobotCraft 2017 第二届国际机器人学暑期学校 2nd Edition of International Robotics Summer School
原文网址:http://www.ros.org/news/2017/02/2nd-edition-of-international-robotics-summer-school-robotcraft- ...
- Elasticsearch Server,2nd Edition pdf 翻译 中文
很偶然的机会,就需要接触到搜索,入门就是google trend已然超过solr的ES.在入门的时候找书的时候发现没有中文版的.于是自己开始翻译Elasticsearch Server,2nd Edi ...
随机推荐
- My97 DatePicker 选择时间后弹出选择的时间
项目中用到这个时间插件,注册用户时可以选中永久和选择时间,二者是互斥关系, 所以在选择时间插件时,需要绑定一个事件,所以看到了这个插件: <input id="yydate" ...
- Java:Date、Calendar、Timestamp的使用
一.Java.util.Date 该对象包含了年月日时分秒信息.具体使用如下代码: //String 转换为Date private static void dateDemo() throws Par ...
- [Twisted] deferred
Twisted提供一个优雅的实现(Deferred)来管理回调函数. Deferred Object 的结构 Deferred Object包含两个回调函数列表.一个用来保存成功的回调函数,另一个用来 ...
- CSS Display(显示) 与 Visibility(可见性)
display属性设置一个元素应如何显示,visibility属性指定一个元素应可见还是隐藏. Box 1 Box 2 Box 3 隐藏元素 - display:none或visibility:hid ...
- web应用程序servlet的映射名称的规则及请求过程
首先用MyEclipse创建一个web Project(工程名起为TestServletProject),新建一个Servlet(这里servlet的名字起TestServlet),将请求的servl ...
- SQL Server2012连接SQL Server2000完美解决方案
在SQL Server2012中连接其他SQL Server数据库时可以使用以下代码: exec sp_addlinkedserver 'ITSV', '', 'SQLOLEDB', 'serveri ...
- nginx服务器,php-fpm重启
1.重启nginx服务器:首先whereis nginx找到你的nginx命令执行文件所在目录,直接/usr/local/nginx/sbin/nginx -s reload 这个路径可能每个人不一样 ...
- CentOS+Apache+php无法访问redis的解决方法
PHP 使用 Redis 安装 开始在 PHP 中使用 Redis 前, 我们需要确保已经安装了 redis 服务及 PHP redis 驱动,且你的机器上能正常使用 PHP. 接下来让我们安装 PH ...
- memcached在windows安装
下载地址: http://s3.amazonaws.com/downloads.northscale.com/memcached-win64-1.4.4-14.ziphttp://s3.amazona ...
- 【python】只执行普通除法:添加 from __future__ import division
from __future__ import division 注意future前后是两个下划线