博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Objective - c Chapter 1 -2 Hello world
阅读量:4334 次
发布时间:2019-06-07

本文共 2695 字,大约阅读时间需要 8 分钟。

 

Objective - c   Chapter 1  Hello world    

1.1

1.2.On the Welcome screen, click "Create a new Xcode project" (see Figure 2-1), or just choose

File ->New ->New Project.

 

1.3.在main里写如下代码

 

#import 
int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); } return 0;}

 

Build and run the program by clicking the Run button or pressing ⌘R.

Open the Xcode console window (by selecting View Debug Area Activate Console or pressing ⌘⇧C), which displays your program's output,

 

 

 

Now Let's pull it apart and see how it works .

 

1.4.1

#import

#import <Foundation/Foundation.h>

#import guarantees that a header file will be included only once, no matter how many times the #import directive is actually seen for that file.

#import 保证头文件只能被包含一次,不论#import 引入多少次这个文件。

 

1.4.2 

Introducing Frameworks

A framework is a collection of parts—header files, libraries, images, sounds, and more—collected together into a single unit.

一个框架包含了头文件,库,图片,声音甚至更多到一个单元中。

The header files for the Foundation framework take up nearly a megabyte of disk storage and contain more than 14,000 lines of code, spread across over a hundred files. When you include the master header file with #import <Foundation/Foundation.h>, you get that whole vast collection.

 

Xcode is smart: it speeds up the task by using precompiled headers, a compressed and digested form of the header that's loaded quickly when you #import it.

Xcode 很聪明: 它使用预编译头文件,压缩

1.4.3 

NSLog and @"Strings " 

NSLog (@"Hello, Objective-C!");

 

The NS Prefix: A Prescription Against Name Collisions

NS前缀: 预防名字冲突。

Rather than break compatibility with code already written for NextSTEP, Apple just continued to use the "NS" prefix. It's a historical curiosity now, like your appendix.

历史原因,原来NestStep的缩写NS。所以一直这么简写了。

1.4.4

NSString: Where it's @

 

A string in double quotes preceded by an at sign means that the quoted string should be treated as a Cocoa NSString element.

一个在双引号前加at 符号@ 意思是说被引用的字符串应该视为cocoa NSSting 元素。

an NSString is a sequence of characters in Cocoa.

一个NSstring是一些列在cocoa中得字符。

NSString elements have a huge number of features packed into them and are used by Cocoa any time a string is needed. Here are just a few of the things an NSString can do:

   Tell you its length

   Compare itself to another string
   Convert itself to an integer or floating-point value

 

You can tell Xcode to always treat warnings as  errors . 

设置xcode使得对待警告如同错误。

 

 

 

1.5 Are you the  boolean type ?

Many languages have a Boolean type, which is, of course, a fancy term for variables that store true and false values. Objective-C is no exception.

oc 也有Boolean 类型。

类型是Bool 。

 

 

转载于:https://www.cnblogs.com/ljlkfx/p/4477711.html

你可能感兴趣的文章
【解决Chrome浏览器和IE浏览器上传附件兼容的问题 -- Chrome关闭flash后,uploadify插件不可用的解决办法】...
查看>>
34 帧动画
查看>>
二次剩余及欧拉准则
查看>>
thymeleaf 自定义标签
查看>>
关于WordCount的作业
查看>>
UIView的layoutSubviews,initWithFrame,initWithCoder方法
查看>>
STM32+IAP方案 实现网络升级应用固件
查看>>
用74HC165读8个按键状态
查看>>
jpg转bmp(使用libjpeg)
查看>>
linear-gradient常用实现效果
查看>>
sql语言的一大类 DML 数据的操纵语言
查看>>
VMware黑屏解决方法
查看>>
JS中各种跳转解析
查看>>
JAVA 基础 / 第八课:面向对象 / JAVA类的方法与实例方法
查看>>
Ecust OJ
查看>>
P3384 【模板】树链剖分
查看>>
Thrift源码分析(二)-- 协议和编解码
查看>>
考勤系统之计算工作小时数
查看>>
4.1 分解条件式
查看>>
Equivalent Strings
查看>>