Skip to content

Instantly share code, notes, and snippets.

View acalism's full-sized avatar
🏠
Working from home

Dawn Song acalism

🏠
Working from home
  • Tencent, Alibaba
  • Shenzhen City, Guangdong Province, China
View GitHub Profile
@acalism
acalism / inverse Color
Last active December 25, 2015 14:09
inverse color
// UIColor+InverseColor.h
@interface UIColor(InverseColor)
- (UIColor*)inverseColor;
@end
// UIColor+InverseColor.m
@implement UIColor(InverseColor)
- (UIColor*)inverseColor {
CGColorRef oldCGColor = self.CGColor;
NSInteger numOfComponents = CGColorGetNumberOfComponents(oldCGColor);
@acalism
acalism / filename
Created December 18, 2013 06:24
desc
file content.
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { // iPad
if ([UIPopoverPresentationController class]) { // iOS8
avc.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *ppc = avc.popoverPresentationController;
//ppc.permittedArrowDirections = UIPopoverArrowDirectionAny;
ppc.barButtonItem = self.shareButtonItem; // self.toolbarItems.lastObject;
//ppc.sourceRect = self.navigationController.toolbar.frame;
//ppc.sourceView = self.navigationController.toolbar;
} else {
self.myPopoverController = [[UIPopoverController alloc] initWithContentViewController:avc];
// You'll also need the QuartzCore framework added to the project
#import <QuartzCore/QuartzCore.h>
int x = 0; int y = 0;
int toX = 30; int toY = 40;
CGMutablePathRef linePath = CGPathCreateMutable();
CGPathMoveToPoint(linePath, NULL, x, y);
CGPathAddLineToPoint(linePath, NULL, toX, toY);
CAShapeLayer *lineShape = [CAShapeLayer layer];
@acalism
acalism / text_file_encoding_conversion_to_UTF16.m
Last active September 15, 2015 07:52
打开文本文件前,你需要知道其编码。如果用QuickLook打开(UIDocumentInteractionController封装了QLPreviewController),需要先将其编码转为UTF16(即NSUnicodeStringEncoding)。下面的方法将url对应的本地文件转化为可以查看的编码(UTF16)))
- (void)reEncodingTextFileAtUrl:(NSURL*)url{
NSString * str = nil;
NSStringEncoding fileEncoding = 0;
NSError * __autoreleasing error;
if (![url checkResourceIsReachableAndReturnError:&error]) { // 非必须
NSLog(@"not reachable: %@", error.localizedDescription);
return;
}
// 自动获取编码,但探测的编码范围公限于CFString.h头文件里提到的编码
@acalism
acalism / _endCellAnimationsWithContext.md
Last active January 11, 2016 19:30
Exception at -[UITableView _endCellAnimationsWithContext:]

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3347.44.2/UITableView.m:1222

if continue to run, get this message, CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. attempt to delete and reload the same index path (<NSIndexPath: 0xc000000000018016> {length = 2, path = 0 - 3}) with userInfo (null)

Related code, as follows,

- (void)controllerWillChangeContent:(NSFetchedResultsController*)controller {
@acalism
acalism / gist:6da1618d979d410135ee
Created December 12, 2015 05:55
BlocksKit 的缺陷
BlocksKit对原有代码有影响,会导致不用block而用delegate的实现出问题。已经发现不止一次这个缺陷引起的崩溃了。
1. 比如textview点某个词出现系统预置菜单后,点“添加”,会导致“添加”界面的textField意外无限递归而崩溃。
这个问题很恶心啊。设计blocks的时候,似乎没考虑到这点。
2. UIImagePickerViewController的delegate方法必须全实现,否则未选照片时就不能退回。
个人怀疑根源跟method swizzling有关。考虑到method swizzling不被苹果允许,我考虑将项目里的blocksKit相关的代码全删掉。这是无奈之举。毕竟blocksKit确实很优秀。
@acalism
acalism / certificate
Created December 22, 2015 13:56
证书和签名问题
$ security find-identity -p codesigning
@acalism
acalism / arch
Created December 23, 2015 07:31
$(ARCHS_STANDARD) 从Xcode6之后,armv7s被弃,后者用于iPhone5和5c,而从5s之后就全面转向arm64
查看库或可执行文件支持的arch,file $fileName, 或lipo -info $fileName,例如,
$ lipo -info ESecure
Architectures in the fat file: ESecure are: armv7 arm64
$ file ESecure
ESecure: Mach-O universal binary with 2 architectures
@acalism
acalism / how to verify or read mobile provisioning profile
Created January 19, 2016 03:28
verify or read .mobileprovision file
1. Use openssl
openssl smime -in /path/to/your.mobileprovision -inform der -verify
2. Use security command
security cms -Di /path/to/your.mobileprovision