Giter Club home page Giter Club logo

blog's Introduction

blog's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blog's Issues

KeyValueCoding

  1. 键值编码在什么情况适用?
  2. 键值编码的弊端
    • 属性路径的拼写:不能依赖智能提示,容易出现拼写错误
    • 不能依赖编译器的检查,运行时才报错崩溃
  3. 所有的键必须以小写字母开头

解决pod search出来的仓库版本低于github仓库版本的方法

问题描述

我们在用 Cocoapods 做第三方开源库管理的时候,有时候发现

$ pod search XXX

版本低于github上仓库的最新release版本 (注:XXX为仓库名称)

解决方法-->升级Cocoapods版本

查看当前系统Cocoapods版本命令:pod --version

升级方法

$ sudo gem update --system
$ gem sources --remove https://rubygems.org/ 
$ gem sources -a https://ruby.taobao.org/ 
$ sudo gem install cocoapods
$ pod setup

其中

$ gem sources --remove https://rubygems.org/ 
$ gem sources -a https://ruby.taobao.org/ 

这两句话可以省略,但我们在天朝,还是加上的好。国内网络原因(你懂的),如果使用原来的https://rubygems.org/,那么在sudo gem install cocoapods的时候,存放在 Amazon S3 上面的资源文件间歇性连接失败。

升级结束后再次pod --version,会发现 Cocoapods 版本号高于之前的版本,升级成功了。

再次

$ pod search XXX

OK,github仓库的最新版已经有了。

问题经过:[https://github.com/HeshamMegid/HMSegmentedControl/issues/77)(https://github.com/HeshamMegid/HMSegmentedControl/issues/77)

iOS9检测微信、百度地图等三方安装

在iOS9以前,检测微信是否安装,用微信SDK中的[WXApi isWXAppInstalled]来检测就可以了,但在iOS9之后,需要在Info.plist中将要使用的URL Schemes列为白名单,才可正常检查应用是否安装。

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>wechat</string>
        <string>weixin</string>
        <string>baidumap</string>
        <string>iosamap</string>
                <string>mqq</string>
                <string>weibo</string>
                <string>tencentweibo</string>
                <string>sinaweibo</string>
    </array>
<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

常用App URL Scheme

Bash颜色

echo -e "\033[31m 红色字 \033[0m" 
echo -e "\033[34m 黄色字 \033[0m" 
echo -e "\033[41;33m 红底黄字 \033[0m" 
echo -e "\033[41;37m 红底白字 \033[0m" 

echo -e "\033[30m 黑色字 \033[0m" 
echo -e "\033[31m 红色字 \033[0m" 
echo -e "\033[32m 绿色字 \033[0m" 
echo -e "\033[33m 黄色字 \033[0m" 
echo -e "\033[34m 蓝色字 \033[0m" 
echo -e "\033[35m 紫色字 \033[0m" 
echo -e "\033[36m 天蓝字 \033[0m" 
echo -e "\033[37m 白色字 \033[0m" 

echo -e "\033[40;37m 黑底白字 \033[0m" 
echo -e "\033[41;37m 红底白字 \033[0m" 
echo -e "\033[42;37m 绿底白字 \033[0m" 
echo -e "\033[43;37m 黄底白字 \033[0m" 
echo -e "\033[44;37m 蓝底白字 \033[0m" 
echo -e "\033[45;37m 紫底白字 \033[0m" 
echo -e "\033[46;37m 天蓝底白字 \033[0m" 
echo -e "\033[47;30m 白底黑字 \033[0m" 

"performSelector may cause a leak because its selector is unknown"警告原因及其解决办法

问题描述

项目中使用到了从字符串创建选择器,编译时发现警告:"performSelector may cause a leak because its selector is unknown"(因为performSelector的选择器未知可能会引起泄漏),为什么在ARC模式下会出现这个警告?

经过搜索后,在Stackoverflow上发现了一个令人满意的答案。见http://stackoverflow.com/questions/7017281/performselector-may-cause-a-leak-because-its-selector-is-unknown

原因

在ARC模式下,运行时需要知道如何处理你正在调用的方法的返回值。这个返回值可以是任意值,如void,int,char,NSString,id等等。ARC通过头文件的函数定义来得到这些信息。所以平时我们用到的静态选择器就不会出现这个警告。因为在编译期间,这些信息都已经确定。

如:

...
[someController performSelector:@selector(someMethod)];
...
- (void)someMethod
{
  //bla bla...
}

而使用[someController performSelector: NSSelectorFromString(@"someMethod")];时ARC并不知道该方法的返回值是什么,以及该如何处理?该忽略?还是标记为ns_returns_retained还是ns_returns_autoreleased?

解决办法

1.使用函数指针方式

SEL selector = NSSelectorFromString(@"someMethod");
IMP imp = [_controller methodForSelector:selector];
void (*func)(id, SEL) = (void *)imp;
func(_controller, selector);

当有额外参数时,如

SEL selector = NSSelectorFromString(@"processRegion:ofView:");
IMP imp = [_controller methodForSelector:selector];
CGRect (*func)(id, SEL, CGRect, UIView *) = (void *)imp;
CGRect result = func(_controller, selector, someRect, someView);

2.使用宏忽略警告

#pragma clang diagnostic push 
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" 
   [someController performSelector: NSSelectorFromString(@"someMethod")]
#pragma clang diagnostic pop

通过使用#pragma clang diagnostic push/pop,你可以告诉Clang编译器仅仅为某一特定部分的代码来忽视特定警告。

如果需要忽视的警告有多处,可以定义一个宏

#define SuppressPerformSelectorLeakWarning(Stuff) \
    do { \
        _Pragma("clang diagnostic push") \
        _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
        Stuff; \
        _Pragma("clang diagnostic pop") \
    } while (0)

在产生警告也就是performSelector的地方用使用该宏,如

SuppressPerformSelectorLeakWarning(
    [_target performSelector:_action withObject:self]
);

如果需要performSelector返回值的话,

id result;
SuppressPerformSelectorLeakWarning(
    result = [_target performSelector:_action withObject:self]
);

3.使用afterDelay

[self performSelector:aSelector withObject:nil afterDelay:0.0];

如果在接受范围内,允许在下一个runloop执行,可以这么做。Xcode5没问题,但据反映,Xcode6的话这个不能消除警告。

近期编程反思

博客半年没有更新了,自己在嘀嗒拼车的这半年里,更多的是对自己写的代码的一些反思,特此书写记录下来。

  • 代码如何写的优雅?
  • 这段代码是否写的很罗嗦?
  • 是否可以换一种写法或者是否能够应用某个设计模式很好的解决这个问题?
  • ···

谈代码的坏味道

有味道的代码永远都存在的,每个人都或多或少不定期的产生一些垃圾代码,而产生此类代码的原因一般都有哪些原因?我曾经问过自己这样的问题。常见的几个原因有以下几个:

  1. 临近上线日期了,先用这段代码工作着吧。先不改了。(这样的解决方案根据实际情况并不是不可以,但当下版本时间充足了,还是花时间重新改写下为上策)
  2. 破窗理论:代码里到处充斥者不良的代码,改动需要花很大的精力,在时间不太允许的情况下,被动的在不良代码上进行输出代码。
  3. 知识或者经验上的短板:如果在某个知识上存在认知不足,很容易用自己仅有的可怜的不良方案来解决问题,殊不知,当你了解了它,换个思路,换个写法,代码能简洁很多。
  4. 待补充···

前两个跟开发项目时的心理有很大关系。而第三条,知识方面的问题,则需要我们不能停止学习,多反思。

而你,而我,中枪了吗?三个我都中了。我在输出着垃圾代码。

以上原因都是引起软件腐烂的原因,它们会增大软件的熵。我从我们的移动总监(后文简称周)身上也学到了不少东西。周来公司的第一件事,就是干掉项目架构中不合理的地方,重新编写,并且每个版本持续重构。周做的就是变化的催化剂,虽然一开始重构丢掉了一些东西,但某种意义上,他重新定义了一部分产品,包括交互和设计中不合理的东西。

代码的坏味道都有哪些?你能闻的到吗?

  1. 简单的逻辑写的异常罗嗦与复杂,容易引起错误就不说了,即便能够正确工作也要花半天理解,难以阅读;
  2. 充斥着重复的代码:
    • 似乎没得选,只能重复?
    • 根本没意识到重复
    • 知道重复还copy & paste,偷懒一时爽
    • 开发者之间同时开发,交流不到位,重复造轮子的情况,无论是业务轮子还是复用组件的轮子
  3. 难以修改,难以扩展;
  4. 类过于庞大,承担了很多其他本应该拆分开来的工作;
  5. 函数过长,可以通过提炼新函数来缩短函数,提炼的新函数的命名是否恰当直接决定了理解的难度;
  6. 其他···

什么是优雅的代码?或者说优雅的代码有哪些特征?

  1. 代码格式整洁,能让阅读的人在最短的时间理解,那么它优雅的可能性非常的大。我们这里不谈短码编程,短码编程是另外一种意义上的优雅,某方面而言;
  2. 简单的逻辑,简单的编写,复杂的逻辑,还是简单的编写,做到这一步需要长时间的磨练;
  3. 无需注释,清晰易读;
  4. 程序的鲁棒性好,易于修改和扩展,修改引入的bug相对少;
  5. 良好的模块性,低耦合;
  6. 算法方面,简洁、高效;
  7. 其他

程序员对算法和数据结构的掌握是必不可少的,但软件工程的相关理论也十分有必要了解和熟练掌握。优雅的代码不是一朝一夕炼成的,它需要非常多的代码输出量以及对既有代码的反思。我们输出垃圾代码并不可怕,可怕的是从来不对垃圾代码进行改进或者重构。作为一个注重实效的程序猿,我容忍不了项目的的杂乱。但凡有时间,我都会对代码进行轻微的整理和改进,而整理的力度和改进同时也会受限于自己对项目的认知以及经验。而我们也要批判地思考所有代码,包括自己的。

如何写出优雅的代码?又或者说如何进行重构?

有很多关于此类话题的书。推荐三本:

  • 《重构-改善既有代码的设计》
  • 《修改代码的艺术》
  • 《编写可读代码的艺术》

在《重构-改善既有代码的设计》一书中提到了重构的一些方法,很实用,也强烈推荐读者理解每一条重构方法,结合自己的项目,进行实践。

我摘取了一部分记录了下来:

重新组织函数

  • 提炼函数
  • 内联函数
  • 内联临时变量
  • 以查询取代临时变量
  • 引入解释性变量
  • 分解临时变量
  • 移除对参数的赋值
  • 以函数对象取代函数
  • 替换算法

简化函数调用

  • 函数重命名
  • 添加、移除参数
  • 将查询函数、修改函数分离
  • 引入参数对象
  • 以工厂函数取代构造函数

处理概括关系

  • 字段上移、下移
  • 函数上移、下移
  • 构造函数本体上移、下移
  • 提炼子类、提炼超类、提炼接口
  • 塑造模板函数
  • 折叠继承体系
  • 委托、继承的取代

撸得了坏代码,翻得了好书籍,反的一脑袋好思,方可撸得了好代码。无他,仅此而已。

说了半天,坏代码能工作为什么要重构?

引用《重构-改善既有代码的设计》

  1. 重构改进软件设计
  2. 重构使软件更容易理解
  3. 重构帮助找到bug
  4. 重构提高编程速度

那我要在什么时候重构?

原则:三次法则--事不过三,三则重构

添加功能时重构

修补错误时重构

复审代码时重构

避免不清楚项目上线日期,而进行大规模重构,因为时间以及风险不可控。

多阅读同事的代码

阅读同事的代码,好处是不言而喻的。我强烈建议你在有时间的情况下,多阅读下同事的代码。无论好与坏。

在阅读他人代码的时候,觉得他们的代码写的不是很好,OK,提出你认为更好的解决办法或者提出代码中存在的bug漏洞。这何尝不是一种进步。记住,跟进代码,理解代码的函数设计、调用跳转从而分析出代码的设计思路也是一种锻炼。时间久了,会锻炼我们阅读源码的能力,同时也教会我们分辨出好与坏的代码。

阅读他人代码,如果发现竟然还可以这么设计、这么写,你就赚了!

所以,多阅读同事的代码。

学会知识的分享

公司有一个良好的分享氛围很重要,嘀嗒在朝着这方面努力。每周都会有分享会,我们移动内部也不定期会有分享。周的第一期是分享是关于Realm的,第二期我分享了LLDB调试以及UI调试,第三期是呆萌的敏捷开发相关分享,整体下来,有不少收获。而其他朋友在后面都会有分享,蛮期待的。

分享的好处:为了能够讲明白,需要自己在下面做好功课,这本身就是加强学习的过程。能讲出来,让别人学习到,本身也是快乐的。

谈责任

在这半年里,或多或少自己写的代码,由于QA部门没有测试出来,而出现在线上的情况。我常常愧疚于自己产生的代码bug出现在线上而引起用户抱怨,降低了使用体验。

然而,愧疚没用!

拿起你的担当!

第一件事,Fix the bug。

第二件事,为什么会引起这个bug。

第三件事,总结,以后如何避免?同样的事情不要在犯。

这也是我在嘀嗒学到的很重要的一课。

最后

这篇文章偏向感悟多点,也作为我重视代码质量的一个转折点。

而这条路,没有尽头···

Xcode插件Alcatraz

安装

卸载

  • rm -rf ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin

Xcode插件目录

  • ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins

Xcode UUID

  • defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID
  • defaults read /Applications/Xcode-beta.app/Contents/Info DVTPlugInCompatibilityUUID

Unity3D Notes

1.Look towards player
using UnityEngine;
using System.Collections;

public class LookTowardMouse : MonoBehaviour {

     void Update () 
     {
         //Mouse Position in the world. It's important to give it some distance from the camera. 
         //If the screen point is calculated right from the exact position of the camera, then it will
         //just return the exact same position as the camera, which is no good.
         Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * 10f);

         //Angle between mouse and this object
         float angle = AngleBetweenPoints(transform.position, mouseWorldPosition);

         //Ta daa
         transform.rotation =  Quaternion.Euler (new Vector3(0f,0f,angle));
     }

     float AngleBetweenPoints(Vector2 a, Vector2 b) {
         return Mathf.Atan2(a.y - b.y, a.x - b.x) * Mathf.Rad2Deg;
     }  
 }

如何在Objective-C中实现链式语法?

在接触到开源项目 Masonry 后,里面的布局约束的链式写法让我颇感兴趣,就像下面这样

UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);

[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(superview.mas_top).with.offset(padding.top); //with is an optional semantic filler
    make.left.equalTo(superview.mas_left).with.offset(padding.left);
    make.bottom.equalTo(superview.mas_bottom).with.offset(-padding.bottom);
    make.right.equalTo(superview.mas_right).with.offset(-padding.right);
}];

其他语言比如 Lua, 实现链式语法很容易。但在 Objective-C 中,如何实现链式语法呢?

注:这里讨论的链式语法特指的是点链式语法,不同于中括号链式语法,如[[[[someObj method1] method2] method3] method4:someParam]。中括号链式语法相对而言更简单些,每个方法的返回值是下一个方法的发送者即可。

查看 Masonry 源码,起初没看明白,于是搜索了下 Stackoverflow,没有发现类似的问题,便将这个问题发布在了 Stackoverflow 上。这里是地址。

总结了下,贴下代码,做个说明。

//------------------------------------------
@interface ClassB : NSObject
@property(nonatomic, readonly) ClassB *(^ddd)(BOOL enable);

- (id)initWithString:(NSString *)str;

@end

@implementation ClassB

- (ClassB *(^)(BOOL))ddd
{
    return ^(BOOL enable) {
        //code
        if (enable) {
            NSLog(@"ClassB yes");
        } else {
            NSLog(@"ClassB no");
        }
        return self;
    };
}

@end



@class ClassB;
@interface ClassA : NSObject

// 1. 定义一些 block 属性
@property(nonatomic, readonly) ClassA *(^aaa)(BOOL enable);
@property(nonatomic, readonly) ClassA *(^bbb)(NSString* str);
@property(nonatomic, readonly) ClassB *(^ccc)(NSString* str);

@end

@implementation ClassA

// 2. 实现这些 block 方法,block 返回值类型很关键,影响着下一个链式
- (ClassA *(^)(BOOL))aaa
{
    return ^(BOOL enable) {
        //code
        if (enable) {
            NSLog(@"ClassA yes");
        } else {
            NSLog(@"ClassA no");
        }
        return self;
    };
}

- (ClassA *(^)(NSString *))bbb
{
    return ^(NSString *str) {
        //code
        NSLog(@"%@", str);
        return self;
    };
}


// 这里返回了ClassB的一个实例,于是后面就可以继续链式 ClassB 的 block 方法
// 见下面例子 .ccc(@"Objective-C").ddd(NO)
- (ClassB * (^)(NSString *))ccc
{
    return ^(NSString *str) {
        //code
        NSLog(@"%@", str);
        ClassB* b = [[ClassB alloc] initWithString:str];
        return b;
    };
}

@end


// 最后我们可以这样做
id a = [ClassA new];
a.aaa(YES).bbb(@"HelloWorld!").ccc(@"Objective-C").ddd(NO);

git 提交规范

feat:新功能(feature)

fix:修补bug

docs:文档(documentation)

style: 格式(不影响代码运行的变动)

refactor:重构(即不是新增功能,也不是修改bug的代码变动)

test:增加测试

chore:构建过程或辅助工具的变动

【GIT相关】解决终端命令行无效不存在的分支名称自动补全的问题

问题描述

远程分支已经将分支AAABBB删除,本地有个分支叫ABBB,当在终端中输入A,然后用Tab键自动补全的时候,老是把AAABBB给候选出来。很纳闷。远程分支AAABBB和本地分支AAABBB都已经被我删除,为什么还会补全提示呢?

例子

当前本地和所有的远程分支 以及 那些已经【死亡的无效的】分支

GitLab/Carpooling_iOS git:(F_Route) ▶ git br -a
* F_Route
  I_chat_module
  developer
  master
  remotes/origin/B_DIDA-8432
  remotes/origin/B_DIDA-8553
  remotes/origin/B_DIDA-8591
  remotes/origin/B_DIDA-8598
  remotes/origin/B_DIDA-8617/8504
  remotes/origin/B_DIDA-8691
  remotes/origin/B_DIDA-9156
  remotes/origin/B_DIDA_8504
  remotes/origin/B_DIDA_9156
  remotes/origin/B_Friend_Reddot
  remotes/origin/B_fix_booksetting
  remotes/origin/B_fix_chat_polling_timer
  remotes/origin/B_fix_hole_guide_position
  remotes/origin/B_fix_messageLeaving
  remotes/origin/B_fix_today_widget
  remotes/origin/B_fix_trip_cell
  remotes/origin/B_fix_trip_cell_related_error
  remotes/origin/B_smallfix
  remotes/origin/B_someFix
  remotes/origin/B_some_small_fix
  remotes/origin/F_Browser_Web_View
  remotes/origin/F_DIDA-8250
  remotes/origin/F_DIDA-8702
  remotes/origin/F_DIDA_8076
  remotes/origin/F_DIDA_8365
  remotes/origin/F_EZhiFu
  remotes/origin/F_LoginWaterMarkView
  remotes/origin/F_NewWelcomePages
  remotes/origin/F_New_Book_Passenger
  remotes/origin/F_Route
  remotes/origin/F_TmpChatPrivacyControl
  remotes/origin/F_cancel_hide_recent_chat_logic
  remotes/origin/F_delete_nearby_drivers
  remotes/origin/F_replace_welcome_page
  remotes/origin/F_text_modify
  remotes/origin/HEAD -> origin/master
  remotes/origin/I_chat_module
  remotes/origin/I_trip_waiting
  remotes/origin/developer
  remotes/origin/master
  remotes/origin/tmpChatPrivacyControl

解决方法

git fetch --prune --all

prune英文单词为“剪枝”的意思,这个命令会将远程已经不存在的分支删除掉

GitLab/Carpooling_iOS git:(F_Route) ▶ git fetch --prune --all
Fetching origin
From ssh://gitlab.didapinche.com:9122/mobile/Carpooling_iOS
 x [deleted]         (none)     -> origin/B_DIDA-8432
 x [deleted]         (none)     -> origin/B_DIDA-8553
 x [deleted]         (none)     -> origin/B_DIDA-8591
 x [deleted]         (none)     -> origin/B_DIDA-8598
 x [deleted]         (none)     -> origin/B_DIDA-8617/8504
 x [deleted]         (none)     -> origin/B_DIDA-8691
 x [deleted]         (none)     -> origin/B_DIDA-9156
 x [deleted]         (none)     -> origin/B_DIDA_8504
 x [deleted]         (none)     -> origin/B_Friend_Reddot
 x [deleted]         (none)     -> origin/B_fix_booksetting
 x [deleted]         (none)     -> origin/B_fix_chat_polling_timer
 x [deleted]         (none)     -> origin/B_fix_hole_guide_position
 x [deleted]         (none)     -> origin/B_fix_messageLeaving
 x [deleted]         (none)     -> origin/B_fix_today_widget
 x [deleted]         (none)     -> origin/B_fix_trip_cell
 x [deleted]         (none)     -> origin/B_fix_trip_cell_related_error
 x [deleted]         (none)     -> origin/B_smallfix
 x [deleted]         (none)     -> origin/B_someFix
 x [deleted]         (none)     -> origin/B_some_small_fix
 x [deleted]         (none)     -> origin/F_DIDA-8250
 x [deleted]         (none)     -> origin/F_DIDA-8702
 x [deleted]         (none)     -> origin/F_DIDA_8076
 x [deleted]         (none)     -> origin/F_DIDA_8365
 x [deleted]         (none)     -> origin/F_EZhiFu
 x [deleted]         (none)     -> origin/F_LoginWaterMarkView
 x [deleted]         (none)     -> origin/F_NewWelcomePages
 x [deleted]         (none)     -> origin/F_TmpChatPrivacyControl
 x [deleted]         (none)     -> origin/F_cancel_hide_recent_chat_logic
 x [deleted]         (none)     -> origin/F_delete_nearby_drivers
 x [deleted]         (none)     -> origin/F_replace_welcome_page
 x [deleted]         (none)     -> origin/F_text_modify
 x [deleted]         (none)     -> origin/I_trip_waiting
 x [deleted]         (none)     -> origin/tmpChatPrivacyControl

再来看看吧:)

GitLab/Carpooling_iOS git:(F_Route) ▶ git br -a
* F_Route
  I_chat_module
  developer
  master
  remotes/origin/B_DIDA_9156
  remotes/origin/F_Browser_Web_View
  remotes/origin/F_MyOrderList
  remotes/origin/F_New_Book_Passenger
  remotes/origin/F_Route
  remotes/origin/HEAD -> origin/master
  remotes/origin/I_chat_module
  remotes/origin/R_Order_Info
  remotes/origin/developer
  remotes/origin/master

一些僵尸分支已经被删除了,这下自动补全就不会再补全那些分支名称了 。

Xcode插件XVim

Copy multi-lines

比如我要复制从第1行到第5行的数据,复制到第9行

  1. 光标移到第5行任意位置,输入ma
  2. 光标移到第1行任意位置,输入y'a(这一定要打这个“'”单引号,否则就进入“INSERT”状态了
  3. 光标移到需要复制的行,输入p,行前复制输入大写P

或者

  1. 把光标移到第9行
  2. shift v
  3. 再把光标移到第15行
  4. y
    5.再再把光标移到第16行
  5. p

或者

Nyy命令复制从光标所在行开始的N行,一般在5行以内非常直观的数字时使用的比较多

ios音频录制"prepareToRecord"模拟器崩溃解决办法

问题描述

在心城的开发过程中,在处理音频部分时,有这么段代码

NSError* error;
self.audioRecorder = [[AVAudioRecorder alloc] initWithURL:[self getTempAudioPath] settings:settingDic error:&error];;
//...
if ([self.audioRecorder prepareToRecord]) {
    [self.audioRecorder record];
}

在模拟器上崩溃,始终停在了prepareToRecord这一行,但真机测试没问题。怀疑是模拟器的bug。
Stackoverflow问题讨论

解决办法(不是办法的办法)

在测试音频录制功能时,先暂时禁用掉Xcode的全局断点功能。之后,恢复正常开启全局断点。(默认快捷键:Command+Y)

Carthage build only one dependency

Apologies if this is already possible, I couldn't figure out a way.
To add a new dependency I would love to be able to do this:

  • Specify new dependency X/Y in Cartfile.
  • carthage update --no-build.
  • carthage build x/y.

Support CocoaPods

ProjectName:DemoTestProject

Steps

  1. cd DemoTestProject
  2. pod spec create DemoTestProject
  3. vim DemoTestProject.podspec
  4. modify podspec file
git add .
git commit -m `commit description`
git tag 0.0.1
git push --tags
git push origin master

6.pod spec lint DemoTestProject.podspec

if you have warnings and errors, please delete your tag and then retry.

git tag -d 0.0.1
git push origin :refs/tags/0.0.1

7.pod trunk push DemoTestProject.podspec

if this is your first time to commit to CocoaPods,please register first:

pod trunk register [email protected] 'write a name here' --description='write descrption here'

Xcode process launch failed: Security

Xcode版本:Xcode7.1 beta
iOS版本:iOS9 beta

运行应用,报错:Xcode process launch failed: Security,应用由于安全性问题无法启动,以前没有此情况。

解决办法:设置-》通用-》描述文件-》开发商应用里的开发者帐号-》信任

说真的,文章写在这里也挺不错。

说真的,文章写在这里也挺不错。测试下:)

ImageTest

64965070201304181125484061603230163_003

CodeHighlight

UIApplication *application = [UIApplication sharedApplication];

__block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
    [application endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}];

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
    //这里做存储操作
} completion:^(BOOL success, NSError *error) {
    [application endBackgroundTask:bgTask];
    bgTask = UIBackgroundTaskInvalid;
}];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.