object -c  OOP ,  源码组织  ,Foundation 框架 详解1

1.1 So what is OOP? OOP is a way of constructing software composed of objects. Objects are like little machines living inside your computer and talking to each other to get work done.

oop 就是由对象构成的软件。 对象就像一些小的机器存在在你的电脑中,通过相互对话来进行工作。 

 

1.2 Source File organization 

If you use .mm for the file extension, you're telling the compiler you've written your code in Objective-C++, which lets you use C++ and Objective-C together.

如果你用.mm文件,那么你在告诉编译器你在用oc++ 在写代码。

 

1.3 

 1.3.1  a quick tour of the foundation kit 

Foundation framework has a bunch of useful low-level, data-oriented classes and types. We'll be visiting a number of these, such as NSString, NSArray, NSEnumerator, and NSNumber.

基础框架 有一系列低层次,面向数据的类和类型。

 

Foundation framework is built on top of another framework called CoreFoundation.

基础框架建立在核心框架之上。

If you come across function names or variable names that start with "CF," they are part of CoreFoundation.

Most of them have equivalents in Foundation framework, and some of them can be easily converted from one to the other.

 

1.3.2   Some useful types 

home on the range 

 

typedef struct _NSRange

{

 unsigned int location;

 unsigned int length;

} NSRange;

 

First, you can assign the field values directly:

NSRange range;

range.location = 17;

range.length = 4;

Second, you can use the C aggregate structure assignment mechanism (doesn't that sound impressive?):

NSRange range = { 17, 4 };

Finally, Cocoa provides a convenience function called NSMakeRange():

NSRange range = NSMakeRange (17, 4);

1.3.3 Geometric types 

You'll often see types that deal with geometry and have the prefix "CG," such as CGPoint and CGSize. These types are provided by the Core Graphics framework, used for 2D rendering.

CG prefix . 这些类型由 核心图形库框架提供。 用作2d 展示。

 

CGPoint represents an (x, y) point in the Cartesian plane:笛卡尔坐标系坐标

struct CGPoint

{

float x;

float y; };

CGSize holds a width and a height:

宽和高

struct CGSize

{

float width;

 float height;

};

 

Cocoa provides a rectangle type, which is a composition of a point and a size:

struct CGRect

{

 CGPoint origin;

 CGSize size;

};

Cocoa gives us convenience functions for making these bad boys too: CGPointMake(), CGSizeMake(), and CGRectMake().

 

1.3.4 String us along 

Cocoa's NSString has a bunch of built-in methods that make string handling much easier.

NSString 有许多内在方法让我们处理字符串更容易。

 

1.3.4.1Build That String 

NSString's stringWithFormat: method creates a new NSString just like that, with a format and arguments:

When you declare a method with the plus sign, you've marked the method as a class method.

当你声明方法前有+号时, 你标注了该方法为类方法。

Class methods used to create new objects are called factory methods.

类方法通常用来创建新对象,被称作工厂方法。

 

1.3.4.2 Size matters 长度问题

Another handy NSString method (an instance method) is length, which returns the number of characters in the string:

-(NSUInteger)length;

 

NSUInteger length=[height length];

 

1.3.4.3 Comparative Politics  比较策略

isEqualToString: compares the receiver (the object that the message is being sent to) with a string that's passed in as an argument. isEqualToString: returns a BOOL (YES or NO) indicating if the two strings have the same contents. It's declared like this:

- (BOOL) isEqualToString: (NSString *) aString;

To compare strings, use the compare: method, which is declared as follows: - (NSComparisonResult) compare: (NSString *) aString;

[@"aardvark" compare: @"zygote"] would return NSOrderedAscending.

 

1.3.4.4Insensitivity Training

compare: does a case-sensitive comparison. In other words, @"Bork" and @"bork", when compared, won't return NSOrderedSame. There's another method, compare:options:, that gives you more control:

- (NSComparisonResult) compare: (NSString *) aString

    options: (NSStringCompareOptions) mask;

For example, if you want to perform a comparison ignoring case but ordering numbers correctly, you would do this:

if ([thing1 compare: thing2 options: NSCaseInsensitiveSearch | NSNumericSearch]

    == NSOrderedSame)

{

  NSLog (@"They match!");

}

 

1.3.4.5 Is it inside ? 在里面吗

the first checks whether a string starts with another string, and the second determines if a string ends with another string:

- (BOOL) hasPrefix: (NSString *) aString;

- (BOOL) hasSuffix: (NSString *) aString;

And you'd use these methods as follows:

NSString *fileName = @"draft-chapter.pages";

if ([fileName hasPrefix: @"draft"])

{

  // this is a draft

}

if ([fileName hasSuffix: @".mov"])

{

  // this is a movie

}

If you want to see if a string is somewhere inside another string, use rangeOfString: - (NSRange) rangeOfString: (NSString *) aString;

NSRange range = [fileName rangeOfString: @"chapter"];

1.3.4.6 Mutability

NSStrings are immutable.Cocoa provides a subclass of NSString called NSMutableString. Use that if you want to slice and dice a string in place.

You can create a new NSMutableString by using the class method stringWithCapacity:, which is declared like so:  

可以用类方法 创建NSMutableString

+ (id) stringWithCapacity: (NSUInteger) capacity;

The capacity is just a suggestion to NSMutableString, like when you tell a teenager what time to be home.

这个容量只是个建议,就像你告诉年轻人什么时候回家。

Once you have a mutable string, you can do all sorts of wacky tricks with it. A common operation is to append a new string, using appendString: or appendFormat:, like this:

- (void) appendString: (NSString *) aString;

- (void) appendFormat: (NSString *) format, ...;

NSMutableString *string = [NSMutableString stringWithCapacity:50];

[string appendString: @"Hello there "];

[string appendFormat: @"human %d!", 39];

You can remove characters from the string with the deleteCharactersInRange: method:

 - (void) deleteCharactersInRange: (NSRange) aRange;

 

NSMutableString *friends = [NSMutableString stringWithCapacity:50];

[friends appendString: @"James BethLynn Jack Evan"];

NSRange jackRange = [friends rangeOfString: @"Jack"];

jackRange.length++; // eat the space that follows

[friends deleteCharactersInRange: jackRange];

 

 

 

 

 

 

object -c OOP , 源码组织 ,Foundation 框架 详解1的更多相关文章

  1. 【集合框架】JDK1.8源码分析之ArrayList详解(一)

    [集合框架]JDK1.8源码分析之ArrayList详解(一) 一. 从ArrayList字表面推测 ArrayList类的命名是由Array和List单词组合而成,Array的中文意思是数组,Lis ...

  2. Objective - c Foundation 框架详解2

    Objective - c  Foundation 框架详解2 Collection Agency Cocoa provides a number of collection classes such ...

  3. Spring源码之九finishRefresh详解

    Spring源码之九finishRefresh详解 公众号搜索[程序员田同学],专职程序员兼业余写手,生活不止于写代码 Spring IoC 的核心内容要收尾了,本文将对最后一个方法 finishRe ...

  4. 我的书籍《深入解析Java编译器:源码剖析与实例详解》就要出版了

    一个十足的技术迷,2013年毕业,做过ERP.游戏.计算广告,在大公司呆过,但终究不满足仅对技术的应用,在2018年末离开了公司,全职写了一本书<深入解析Java编译器:源码剖析与实例详解> ...

  5. nginx源码分析线程池详解

    nginx源码分析线程池详解 一.前言     nginx是采用多进程模型,master和worker之间主要通过pipe管道的方式进行通信,多进程的优势就在于各个进程互不影响.但是经常会有人问道,n ...

  6. 【源码解析】BlockManager详解

    1 Block管理模块的组件和功能 BlockManager:BlockManager源码解析 Driver和Executor都会创建 Block的put.get和remove等操作的实际执行者 Bl ...

  7. vuex 源码解析(四) mutation 详解

    mutation是更改Vuex的store中的状态的唯一方法,mutation类似于事件注册,每个mutation都可以带两个参数,如下: state ;当前命名空间对应的state payload ...

  8. Java并发包源码学习系列:详解Condition条件队列、signal和await

    目录 Condition接口 AQS条件变量的支持之ConditionObject内部类 回顾AQS中的Node void await() 添加到条件队列 Node addConditionWaite ...

  9. Tomcat源码分析 | 一文详解生命周期机制Lifecycle

    目录 什么是Lifecycle? Lifecycle方法 LifecycleBase 增加.删除和获取监听器 init() start() stop() destroy() 模板方法 总结 前言 To ...

随机推荐

  1. Ios 项目从头开发 MVVM模式(三)

    1.话说,本来想做个聚合查询功能.可是我的重点想研究xmpp聊天功能.所以使用mvvm模式做了全然模式51job主界面的页面. 2.首先给大家看我执行起来的界面. 3.界面非常easy,做这个界面主要 ...

  2. vs2013发布网站提示 “未能将文件**复制到**”

    原因:年久失修,原来在项目中的一些文件给删掉或移除了 解决方法:打开.csproj文件(记事本打开),把提示的文件给删除掉.

  3. java8--网络编程(java疯狂讲义3复习笔记)

    重点复习一下网络通信和代理 java的网络通信很简单,服务器端通过ServerSocket建立监听,客户端通过Socket连接到指定服务器后,通信双方就可以通过IO流进行通信. 需要重点看的工具类:I ...

  4. Android开发之自定义对话框

    由于系统自带的对话框不好看,于是本人就自定义了一个对话框,以后有类似的就可以直接使用啦.先上效果图: 1,布局文件dialog_clear_normal.xml <?xml version=&q ...

  5. javascript 省、市、地县三级联动

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD&g ...

  6. HDU - 1863 畅通工程(最小生成树)

    d.m个村庄,n条路,计算出所有村庄畅通需要的最低成本. s.最小生成树 c.Prim算法:cost[a][b]和cost[b][a]都得赋值. /* Prim算法 Prim求MST 耗费矩阵cost ...

  7. 用jQuery插件来提升SharePoint列表表单用户体验

    本文将描述如何通过简单的CSS和jQuery插件提升SharePoint默认的列表表单体验.这些小技巧并不仅仅改善了外观,还提升了可用性. 剩余字数 我们以通知列表为例.通知正文字段假设要求不应该超过 ...

  8. thinkphp不能够将ueditor中的html文本显示

    因为这个问题花费了我好长时间,非常的急躁.fuck!! 这次我首先在富文本框中输入了一些文本,这些文本是带有样式的,比如是代码.然后存入数据库,但是当我再一次将它取出来打算放入富文本框中的时候,马丹, ...

  9. 洛谷P4216 [SCOI2015]情报传递(树剖+主席树)

    传送门 我们可以进行离线处理,把每一个情报员的权值设为它开始收集情报的时间 那么设询问的时间为$t$,就是问路径上有多少个情报员的权值小于等于$t-c-1$ 这个只要用主席树上树就可以解决了,顺便用树 ...

  10. [App Store Connect帮助]七、在 App Store 上发行(4)分阶段发布某个版本更新(iOS 和 watchOS)

    当您发布您 App 的一个版本更新时,您可以选择分阶段发布您的 iOS App.如果您正在提交一个 iOS 版本更新,且您的 App 处于以下 App 状态之一,则此选项可用. 准备提交 正在等待审核 ...