sweetjk


  • 首页

  • 分类

  • 关于

  • 归档

  • 标签

  • 站点地图

  • 公益404

  • 搜索

理解类对象的用意

发表于 2017-07-06 | 阅读次数

理解 “类对象” 的用意

类对象并非在编译器就绑定好了,而是在运行期查找。

Objective-C的对象的本质是什么?

每个Objective-C的对象实例都是指向某块内存数据的指针。所以声明时,类型后面要跟一个 “*” 号

1
NSString *pointerVarible = @"Some String";

编过C语言的人都知道这是什么意思,对于没有写过C语言的程序员来说,pointerVarible可以理解成为存放内存地址的变量,而NSString自身的数据就存在与那个地址中。因此说可以说,pointerVarible改变量“指向”(point)NSString实例。所有Objective-C对象都是如此,若是想把对象所需的内存分配到栈上,编译器则会报错

1
2
NSString stackVarible = @"Some String";
// error: Interface type cannot be statically allocated

对于通用的对象类型id,由于其本身已经是指针了,所以我们能够这样写:

1
id genericTypeString = @"some string ";

上面这种定义方式和NSString* 来定义相比,其语法意义相同。唯一的区别在于,如果声明时指定了具体类型
,那么在该类实例上调用其所没有的方法时,编译器会探知此情况,并发出警告信息。

描述Objective-C对象所用的数据结构定义在运行期程序库的头文件里,id本身也定义在这里:

1
2
3
4
5
6
struct objc_object {
Class isa OBJC_ISA_AVAILABILITY;
};
/// A pointer to an instance of a class.
typedef struct objc_object *id;

由此可见,每个对象的首个成员是Class类的变量。改变量定义了对象所属的类,同常称之为“isa”指针。例如刚才的例子中的对象
“是一个”(isa)NSString,所以其“isa”指针就指向了NSString。Class对象也定义在运行期程序库的头文件中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct objc_class {
Class isa OBJC_ISA_AVAILABILITY;
#if !__OBJC2__
Class super_class OBJC2_UNAVAILABLE;
const char *name OBJC2_UNAVAILABLE;
long version OBJC2_UNAVAILABLE;
long info OBJC2_UNAVAILABLE;
long instance_size OBJC2_UNAVAILABLE;
struct objc_ivar_list *ivars OBJC2_UNAVAILABLE;
struct objc_method_list **methodLists OBJC2_UNAVAILABLE;
struct objc_cache *cache OBJC2_UNAVAILABLE;
struct objc_protocol_list *protocols OBJC2_UNAVAILABLE;
#endif
} OBJC2_UNAVAILABLE;
/* Use `Class` instead of `struct objc_class *` */
阅读全文 »

Blocks

发表于 2017-04-24 | 阅读次数

Objectvie-C Block

block 在 Objective-C开发中应用非常广泛,我们知道block会捕获外部对象,也知道使用block要防止循环引用。
“知其然不知所以然“是一件非常痛苦的。那么block这套机制在OC中是如何实现的呢?本文通过从C/C++到汇编层面分析block的实现原理。

Clang

clang 是Xcode的编译器前端,编译器前端负责语法分析、语义分析、生成中间代码。

比如当你再xcode中进行build一个.m 文件的时候,实际的编译命令如下:

1
2
3
4
5
6
7
8
9
10
11
12
clang -x objective-c -arch x86_64
-fmessage-length=0
-fobjc-arc...
-Wno-missing-field-initializers ...
-DDEBUG=1 ...
-isysroot iPhoneSimulator10.1.sdk
-fasm-blocks ...
-I headers.hmap
-F 所需要的Framework
-iquote 所需要的Framework ...
-c ViewController.m
-o ViewController.o
阅读全文 »

RN之集成到现有iOS项目

发表于 2017-04-17 | 阅读次数

Guides

Integration With Existing Apps (集成到已存在的app上)

Platform:Objective-C

Key Concepts (核心概念)

React Native is great when you are starting a new mobile app from scratch. However, it also works well for adding a single view or user flow to existing native applications. With a few steps, you can add new React Native based features, screens, views, etc.

当你重头开始一个新的项目的时候React Native 是伟大的。然而,它也可以为现有的本地应用程序添加单个视图或用户流。通过几个步骤,您可以基于本机的功能、屏幕、视图等等添加React Native。

The keys to integrating React Native components into your iOS application are to:

将React Native 组件集成到iOS应用程序的关键是:
1.Understand what React Native components you want to integrate.
了解你想要集成的React Native 组件

2.Create a Podfile with subspecs for all the React Native components you will need for your integration.
创建一个对所有React Native组件管理的描述文件 subspecs podfile

3.Create your actual React Native components in JavaScript.
在JavaScript中创建具体的React Native 组件

4.Add a new event handler that creates a RCTRootView that points to
your React Native component and its AppRegistry name that you defined in index.ios.js.
添加一个事件处理程序用来创建一个RCTRootView 指定 React Native 组件 并在index.ios.js中定义 AppRegistry 的名字

5.Start the React Native server and run your native application.
启动Rect Native 服务 ,运用你的程序

6.Optionally add more React Native components.
可选添加更多的ReactNative组件。

7.Debug.
调试

8.Prepare for deployment (e.g., via the react-native-xcode.sh script).
准备部署(例如,通过react-native-xcode.sh脚本

9.Deploy and Profit!
部署和Profit

阅读全文 »

RN基础

发表于 2017-04-14 | 阅读次数

React Native 参考官方文档

Tutorial

React Native is like React, but it uses native components instead of web components as building blocks. So to understand the basic structure of a React Native app, you need to understand some of the basic React concepts, like JSX, components, state, and props. If you already know React, you still need to learn some React-Native-specific stuff, like the native components. This tutorial is aimed at all audiences, whether you have React experience or not.

Let’s do this thing.

HelloWorld

In accordance with the ancient traditions of our people, we must first build an app that does nothing except say “Hello world”. Here it is:

1
2
3
4
5
6
7
8
9
10
11
12
13
import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';
class HelloWorldApp extends Component {
render() {
return (
<Text>Hello world!</Text>
);
}
}
AppRegistry.registerComponent('HelloWorldApp', () => HelloWorldApp);
阅读全文 »

RN之flexbox布局

发表于 2017-04-12 | 阅读次数

React Native 之 flexbox布局

本文详情
本文讲解React Native中的布局,该布局用CSS的flex布局,掌握了这个布局对后面RN应用的开发用途非常之大。

常用属性

RN的flexbox主要有以下几个属性:

  • felxDirection
  • alignItems
  • justifyContent
  • alignSelf
  • flex
  • flexWrap
阅读全文 »

Mac终端命令

发表于 2017-04-07 | 阅读次数

基本命令

1、列出文件

  • ls 参数 目录名 例: 看看驱动目录下有什么:
    1
    $ ls /Users/apple/Library

参数 -w 显示中文,-l 详细信息, -a 包括隐藏文件

2、转换目录

  • cd 例:
    1
    $ cd /Users/apple/Library/Accounts/

3、建立新目录

  • mkdir 目录名 例:在驱动目录下建一个备份目录 backup

    1
    $ mkdir /System/Library/Extensions/backup
  • 在桌面上建一个备份目录 backup

    1
    $ mkdir /User/用户名/Desktop/backup
阅读全文 »

git 命令总结

发表于 2017-04-07 | 阅读次数



一 、新建代码库

#当前目录新建一个Git代码库
$ git init

新建一个目录、将其初始化为Git代码库

$ git init [project-name]

下载一个项目和它的整个代码历史

$ git clone [url]

阅读全文 »
sweetjk

sweetjk

7 日志
© 2017 sweetjk
由 Hexo 强力驱动
主题 - NexT.Pisces