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 ...
随机推荐
- 第一章 SQL基础
第一部分:SQL基础1. 为什么学习SQL自人类社会形成之日起,社会的运转就在不断地产生和使用各种信息(文献.档案.资料.数据等):在如今所谓的信息时代,由于计算机和互联网的作用,信息的产生和使用达到 ...
- .NET性能优化方面的总结
从2004年底开始接触C#到现在也有2年多的时间了,因为有C++方面的基础,对于C#,我习惯于与C++对比.现在总结一些.NET方面的性能优化方面的经验,算是对这两年多的.NET工作经历的总结. ...
- AutoResetEvent 详解
AutoResetEvent 允许线程通过发信号互相通信.通常,此通信涉及线程需要独占访问的资源. 线程通过调用 AutoResetEvent 上的 WaitOne 来等待信号.如果 AutoRese ...
- JS 定時刷新父類頁面
function timeCount() { var url = "MAC.aspx"; parent.location.href = url; } function beginC ...
- 查看oracle 启动了多久
想看一下系统正常运行了多少天?开机多长时间没有重启了? windows系统 C:\>systeminfo |find “系统启动时间”系统启动时间: 265 天 4 小时 26 分 32 ...
- oracle编译 失效对象方式
如果procedure 所使用的表结构发生了改变等其它情况,在相应的xxx_objects表的status字段会变为invalid状态,但是如果在调用时procedure会自动编译,grant失效对象 ...
- 3.SQL*Plus命令
3.1SQL*Plus与数据库的交互 主要用来数据库查询和数据处理的工具. 3.2SQL*Plus运行环境设置 3.2.1SET命令概述 用户可以使用SET命令设置SQL*Plus的运行环境,SET命 ...
- SVM对偶形式
dual svm 对偶SVM linear SVM 可以用二次规划方法解 xn通过非线性转换变成zn SVM配合非线性特征转换 透过large-margin降低模型复杂度 透过特征转换得到弯弯曲曲的边 ...
- 简单的完全背包HDU1114
今天广州下雨啦,不过没关系啦,反正我最近也都在刷题学习算法. 昨天做了五题01背包,今天还是背包,不过是完全背包,估计做动态规划要持续好一段时间,一开始选了一道简单题目啦. HDU1114,看了小一段 ...
- [LeetCode OJ] Word Search 深度优先搜索DFS
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...