GETs
(10250810)
1. push到分支
git push --set-upstream origin f_yuyuan_copy_to_pasteboard
2. diff比较某个文件commit前后差异
git log -p -1 proj/utility/categories/NSDictionary+MS/NSDictionary+MS.m
(20150811)
3. 保存命令行别名
alias goagent='python ~/Documents/goagent-3.0/local/proxy.py'
4. git, 从stage到unstage状态
git reset HEAD proj/utility/categories/NSDictionary+MS/NSDictionary+MS.m
5. @property(atomic, strong, readwrite) ->默认属性标签
(20150813)
6. 判断字符串中是否含有emoji:
====code begin====
+ (BOOL)textIsAllExpression:(NSString *)string
{
__block BOOL returnValue = NO;
[string enumerateSubstringsInRange:NSMakeRange(0, [string length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock:
^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
returnValue = [self isEmoj:substring];
*stop = !returnValue;
}];
return returnValue;
}
+ (BOOL)isEmoj:(NSString *)string
{
const unichar hs = [string characterAtIndex:0];
// surrogate pair
if (0xd800 <= hs && hs <= 0xdbff) {
if (string.length > 1) {
const unichar ls = [string characterAtIndex:1];
const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
if (0x1d000 <= uc && uc <= 0x1f77f) {
return YES;
}
}
} else if (string.length > 1) {
const unichar ls = [string characterAtIndex:1];
if (ls == 0x20e3) {
return YES;
} else if (hs == 0x263a && ls == 0xfe0f) {
return YES;
}
} else {
// non surrogate
if (0x2100 <= hs && hs <= 0x27ff) {
return YES;
} else if (0x2B05 <= hs && hs <= 0x2b07) {
return YES;
} else if (0x2934 <= hs && hs <= 0x2935) {
return YES;
} else if (0x3297 <= hs && hs <= 0x3299) {
return YES;
} else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {
return YES;
}
}
return NO;
}
====code end====
(20150814)
7. 注册TableCell的Nib
[self.tableView registerNib:[UINib nibWithNibName:@"MYTopicDetailCell" bundle:nil] forCellReuseIdentifier:DetailIdentifier];
8. git回滚到merge之前
git reset --hard [版本号]
(20150815)
9. UIScrollView/UITableView滚动到顶部.
[tableView setContentOffset:CGPointMake(0, -weakSelf.tableView.contentInset.top) animated:YES];
10. UIScrollView/UITableView, 设置点击statusBar滚动到顶部.
tableView.scrollsToTop = YES;
11. git合并.
git checkout [接受被合并分支的分支]
git fetch
git merge [被合并的分支, 可以是本地或远端分支]
(20150821)
12. error在函数的声明中的类型:(NSError * __autoreleasing *)outError
(20150822)
13. UITableView和UICollectionView记得设置dataSource和delegate.
14. 和白色配的底色 r, g, b
137, 116, 185
75, 185, 146
52, 153, 225
134, 158, 83
(20150824)
15. UITableView设置UITableCell的separator的inset:(适用iOS7&8)
(1)(这步可省略, 但是要设置的话一定要同时设置)在给tableView设置时需要同时设置layoutMargins和seperatorInsects.
if ([_menuTableView respondsToSelector:@selector(setLayoutMargins:)]) {
_menuTableView.layoutMargins = _separatorInsects;
}
_menuTableView.separatorInset = _separatorInsects;
(2) 在-tableView:willDisplayCell:forRowAtIndexPath:设置如下
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:_menuTableView.separatorInset];
if (indexPath.row == _menuItems.count - 1) {
// 隐藏最后一个separater
[cell setSeparatorInset:UIEdgeInsetsMake(0, cell.bounds.size.width, 0, 0)];
}
}
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:_menuTableView.layoutMargins];
}
}
(20150826)
16.
// 修复iOS9 TTTAttributedLabel中CTFramesetterCreateFrame因包含”\r”而陷入内存暴涨问题
// content是一个TTTAttributedLabel对象.
self.content.text = [self.content.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
(20150827)
17. 监听屏幕旋转事件
[defaultCenter addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];
(20150906)
18. UIViewController添加/删除child UIViewController
(1)Add
/*If you are implementing your own container view controller, it must call the didMoveToParentViewController: method of the child view controller after the transition to the new controller is complete or, if there is no transition, immediately after calling the addChildViewController: method.*/
[self addChildViewController:controller];
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:self];
(2)Remove
[controller willMoveToParentViewController:nil];
[controller.view removeFromSuperView];
[controller removeFromParentViewController:self];
19. 打开Xcode的搜索栏 Cmd+Shift+F
(20150908)
20. 定制状态栏
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) UIWindow *statusbarWindow;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 初始化一个状态条级别的window
CGRect frame = CGRectMake(0.0, 0.0, 320.0, 20.0);
_statusbarWindow = [[UIWindow alloc] initWithFrame:frame];
[_statusbarWindow setBackgroundColor:[UIColor blackColor]];
[_statusbarWindow setWindowLevel:UIWindowLevelStatusBar + 1.0];
}
@end
(20150911)
21. objc_setAssociatedObject
The behavior you assign determines how the memory is managed for the type. If you choose retain or copy the object will be released when the instance of the class you add the associated reference to is deallocated. That makes retain and copy behavior operations preferred for Objective-C classes. Assign is also useful to avoid retain cycles as long as you set the reference to nil when done with the object.
OBJC_ASSOCIATION_ASSIGN Specifies a weak reference to the associated object.
OBJC_ASSOCIATION_RETAIN_NONATOMIC Specifies a strong reference to the associated object, and that the association is not made atomically.
OBJC_ASSOCIATION_COPY_NONATOMIC Specifies that the associated object is copied, and that the association is not made atomically.
OBJC_ASSOCIATION_RETAIN Specifies a strong reference to the associated object, and that the association is made atomically.
OBJC_ASSOCIATION_COPY Specifies that the associated object is copied, and that the association is made atomically.
22. git 合并冲突标志(8个<)
<<<<<<< HEAD
...(执行git merge命令的branch的代码)
=======
...(git merge命令的参数中的分支对应的代码)
>>>>>>> proj_v2.6.0
(20150915)
23. UIImage.size
In iOS 4.0 and later, this value reflects the logical size of the image and is measured in points. In iOS 3.x and earlier, this value always reflects the dimensions of the image measured in pixels.
UIImage.scale
If you load an image from a file whose name includes the @2x modifier, the scale is set to 2.0. You can also specify an explicit scale factor when initializing an image from a Core Graphics image. All other images are assumed to have a scale factor of 1.0.
*notice*
If you multiply the logical size of the image (stored in the size property) by the value in this property, you get the dimensions of the image in pixels.
(20150919)
24. //@fix ios7 下 没设置 forState title 左右的数据会出错。
...
UIButton *_likeCountButton = ...;
if (likeCountButtonSelected) {
_likeCountButton.selected = YES;
[_likeCountButton setTitle:likeTitle forState:UIControlStateSelected];
} else {
_likeCountButton.selected = NO;
[_likeCountButton setTitle:likeTitle forState:UIControlStateNormal];
}
25. 刷新时button闪烁,把button类型改成custom就不会闪烁了.
(20150922)
26. UINavigationBar外观显示设置
// 设置导航栏背景不透明,且为白色.
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
// 隐藏导航栏底部1px的灰色边线
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
26. #define使用
#define STARTLOGTIME \
do{((AppDelegate *)[UIApplication sharedApplication].delegate).startTime = CFAbsoluteTimeGetCurrent();}while(0)
#define LOGTIME(x) \
do{int count = x; NSLog(@"<%d<<<: %lf", count, CFAbsoluteTimeGetCurrent() - ((AppDelegate *)[UIApplication sharedApplication].delegate).startTime);}while(0)
@property (nonatomic, assign) CFAbsoluteTime startTime;
(20150925)
27. 用UICollectionView的时候, 在xib中给UICollectionViewCell添加tap手势(可能)会导致以下错误:
*** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3505.16/UICollectionView.m:3589
28. 使用UIView的layoutIfNeed函数来更新布局, 只有在约束有更改的情况下才会更新布局哦.
(20150929)
29. 菜头曾说过,“性是网络第一生产力,无聊是网络第二生产力,免费是网络第三生产力。三力结合,基本上可以解释一切网络热点事件。”
(20150930)
30. 删除函数实现的时候, 注意查看是否在.h头文件中有函数声明, 如果有声明, 应该将声明一并删除, 以防调用未实现函数.
31. Xcode手动生成Warning,error,…
//Generate a warning
#pragma message "Warning 1"
--------
//Another way to generate a warning
#warning "Warning 2"
--------
//Generate an error to fail the build.
#error "Something wrong"
--------
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
int a;
#pragma clang diagnostic pop
(20151009)
32. Mantle中不必要的Transformer: 如果解析字段对应的值是字符串数组, 则不需要配置对应的JSONTransformer.
// 此段代码不需要
// 写上会导致解析异常, 奔溃.
/*
+ (NSValueTransformer *)tagsJSONTransformer {
return [NSValueTransformer mtl_JSONArrayTransformerWithModelClass:[NSString class]];
}
*/
(20151012)
33. Git修改branch的名称 If you’re currently on the branch you want to rename:
git branch -m new_name
(20151013)
34. 手势的响应方法格式
// Valid action method signatures:
// -(void)handleGesture;
// -(void)handleGesture:(UIGestureRecognizer*)gestureRecognizer;
- (instancetype)initWithTarget:(nullable id)target action:(nullable SEL)action NS_DESIGNATED_INITIALIZER; // designated initializer
(20151014)
35. 可以运行带有 –delete 选项的 git push 命令来删除一个远程分支。 如果想要从服务器上删除 serverfix 分支,运行下面的命令:
$ git push origin --delete serverfix
To https://github.com/schacon/simplegit
- [deleted] serverfix
(20151023)
36. iPhones设备型号
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G (A1203)";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G (A1241/A1324)";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS (A1303/A1325)";
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4 (A1332)";
if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4 (A1332)";
if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4 (A1349)";
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S (A1387/A1431)";
if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5 (A1428)";
if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (A1429/A1442)";
if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c (A1456/A1532)";
if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c (A1507/A1516/A1526/A1529)";
if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s (A1453/A1533)";
if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s (A1457/A1518/A1528/A1530)";
if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus (A1522/A1524)";
if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6 (A1549/A1586)";
(20151027)
37. NS_REQUIRES_NIL_TERMINATION
(20151104)
38. libc++abi.dylib: terminate_handler unexpectedly threw an exception
可能原因是有一些无用的IBOutlet未删除.
(20151104)
39. CGImageRef使用时,需要按实际情况使用CGImageRelease(imageRef)来释放内存!_!
(20151105)
40. 判断一个UIViewController是否内存泄露的方法: 看-dealloc是否执行!!!
所以, 以后每个UIViewController都要写-dealloc方法, 备用!
41. 传入Block的变量尽量设置为weak; Block执行完之后最好手动置为nil;
(20151110)
42. 更新插件的DVTPlugInCompatibilityUUID(后话:可能会导致Xcode不能启动, 或其他问题.)
find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add `defaults read /Applications/Xcode.app/Contents/Info.plist DVTPlugInCompatibilityUUID`
(20151119)
44. 人活着, 为了什么? 生命的意义在于什么? 活着, 第一, 就是意识到这个问题, 并去思考它. 第二步, 迷茫过后, 让生活与生命变得简单, 活着是最根本直接的目的. 在此基础上, 我们学会了思考第一点, 同时学会了想要去实现, 去获得许多事和许多物. 第二步就是给自己空白的生命定上一个目标(当然可以有很多目标), 并去实现它(们). 第三步, 瞄准我们定下的目标, 抛弃其他的杂念, 认认真真的去为完成这个目标而不断努力, 用汗水+思考去把空白空虚的生命丰富. 第三步会随着你的目标的不同, 过程也会变得长短不一, 或精彩或平淡. 当我们实现了第二步定下的目标后, 也许我们会重新回去思考, 即又回到第一步. 但是一般推荐直接回到第二步, 给自己在定下下一个目标. 只要活着, 我们的生命就会不停地以空白的状态出现在我们的生活中, 那就去继续用第三步的充实生活去书写你的生命!