0x1 安装 CocoaPods
sudo gem sources -a https://ruby.taobao.org/
sudo gem sources -r https://rubygems.org/
sudo gem sources -l
sudo gem update
sudo gem install -n /usr/local/bin cocoapods -v 0.39
pod setup
pod --version
执行 pod setup
特别耗时间,而且看不到进度,可以选择下面方式初始化:
cd ~/.cocoapods/repos
git clone https://github.com/CocoaPods/Specs.git
下载完成把这个Specs
改名为master
就可以了。
然后执行 pod repo
可以看到如下信息就说明安装成功啦:
master
-Type: git (master)
-URL: https://github.com/CocoaPods/Specs.git
-Path: /Users/baidu/.cocoapods/repos/master
1 repo
项目根目录下创建 Podfile文件,在文件中添加如下配置:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, "8.0"
target "iOSStartDemo" do
pod 'SVProgressHUD', '1.1.3'
pod 'Masonry', '0.6.3'
end
然后通过如下命令,安装第三方依赖库:
pod install
如果成功执行,将会为你生成一个 iOSStartDemo.xcworkspace 文件,这样项目就变成 workspace 模式了。需要关闭项目,双击xcworkspace 打开,或者通过命令open iOSStartDemo.xcworkspace
0x2 Blocks 应用
@implementation Test {
}
-(NSString *) testBlock:(NSString *) name andHandler: (NSString *(^)(NSInteger code, NSString *msg)) handler {
return handler(10, @"xxxx");
}
+(void) main {
Test *test = [[Test alloc] init];
[test testBlock:@"test" andHandler:^(NSInteger code, NSString * msg) {
return [NSString stringWithFormat:@"%i + %@", code, msg];
}];
}
@end
0x3 iOS 模拟器没有 Home 键解决方案
- 单击Home Command-Shift-H
- 双击Home键 Command-Shift-H 按两次。