NSTextAttachment: 使用图片创建一个NSAttributedString
|
lantern 使用中遇到的问题
解决方法:
在终端运行
|
然后,重新登陆
注:此方法在 Mac OS X 10.11.5 上测试有效,Windows 操作系统,请参考百度经验-关闭蓝灯/Lantern后无法连接到网络
这里说的局域网是使用无线路由建立的局域网,各设备使用 wifi 功能连接网络。
|
比如你的电脑的ip地址是192.168.1.2,运行命令lantern -addr=192.168.1.2:8787
,然后把你的手机的代理服务器设为192.168.1.2
Mac 下获取方法:
系统偏好->网络,在网络状态下即可看到当前连接的热点和自己电脑当前的 ip 地址。
命令行下,运行命令 ifconfig,查看无线网卡信息,也可以找到 ip 地址。记住网卡的名字,(一般格式为en0,en1…),以 en0 为例,以后可直接输入ifconfig en0
来查看 ip 地址。
ipconfig getifaddr en0 (注:en0 是你电脑上正在使用的无线网卡的名字,也可能是en1)
iPhone 上设置代理方法:
注意:不需要翻墙的时候,切记把代理关闭,否则无法上网。
|
|
|
|
|
Clang /ˈklæŋ/ is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, OpenMP, OpenCL, and CUDA. It uses LLVM as its back end and has been part of the LLVM release cycle since LLVM 2.6.
It is designed to be able to replace the full GNU Compiler Collection (GCC). Its contributors include Apple, Microsoft, Google, ARM, Sony, Intel and Advanced Micro Devices (AMD). It is open-source software, with source code released under the University of Illinois/NCSA License, a permissive free software licence.
LLVM 是 Low Level Virtual Machine
(底层虚拟机)的简称,这个库提供了与编译器相关的支持,能够进行程序语言的编译期优化、链接优化、在线编译优化、代码生成。可以作为多种语言编译器的后台来使用。
clang -rewrite-objc
的作用是把 oc 代码转写成 c/c++ 代码,推测 OC 底层的实现原理。
|
比如,在 OC 中,方法调用又称为消息发送,但消息发送是怎么实现的呢?
|
在终端输入
|
在生成的 ViewController.cpp
文件中,可以找到 ViewDidLoad 方法改写后的实现:
|
也就是说 [p foo]
在动态编译的时候,会被转意为: objc_msgSend(p, sel_registerName("foo"));
。
OC 代码转写成 C/C++ 代码时,在模拟器和真机上,有时候是有区别的。如果需要指定 SDK ,那么要结合xcrun
命令。
真机:
|
模拟器:
可通过 xcodebuild -showsdks
来查看机器上的 SDK
|
如果使用了iOS frameworks,(如UIKit) 或者 第三方 SDK (如听云),执行clang -rewrite-objc
的时候会提示错误:
这是因为没有引入 framework,clang 不知道去哪里找,需要用 -F 选项指定 要引入的 framework。
|
如果指定了 sdk,则不需要指定 iOS 内部 frameworks
```
之前在读 Apple 开源的 runtime 源码的时候,经常使用这个命令,就起了个简短的别名,方便使用:
alias deoc="xcrun -sdk iphonesimulator9.3 clang -rewrite-objc"。(请先使用
xcodebuild -showsdks` 查看自己电脑上的 sdk 做相应修改)source ~/.bashrc(for bash users)
或者 source ~/.zshrc (for zsh users)
deoc
来代替 xcrun -sdk iphonesimulator9.3 clang -rewrite-objc
,后面接 OC 源文件 (和 -F framework,如果需要引入第三方 sdk)。关于clang
的更多使用方法,请参考:
Refrences:
Managed Object Model - It describs the schema that you use in the app. In Xcode, the Managed Object Model is defined in a file with the extension .xcdatamodeld. You can use the visual editor to define the entities and their attributes, as well as, relationships.
Persistant Store Coordinator - SQLite is the default persistant store in iOS. However Core Data allows developers to setup multiple stores containing different entities. The Persistant Store Coordinator is the party responsible to manage different persistant object stores and save th objects to the stores. Forget about it you don’t understand what it is. You’ll not interact with Persistant Store Coordinator directly when using Core Data.
Managed Object Context - Think of it as a “scratch pad” containing objects that interacts with data in persistent store. Its job is to manage objects created and returned using Core Data. Among the components in the Core Data Stack, the Managed Object Context is the one you’ll work with for most of the time. In general, whenever you need to fetch and save objects in persistent store, the context is the first component you’ll talk to.
The below illustration can probably give you a better idea about the Core Data Stack
为什么要这么做?
Windows下
使用系统自带的clip命令。
示例:
|
Linux下
使用xsel命令。
参见笔记:How do I pipe terminal standard output (stdout) to the clipboard?
示例:
|
Mac下
使用 pbcopy 命令。 # 对应有个pbpaste命令。
示例:
|