This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSDate *)beginningOfDay:(NSDate *)date; | |
{ | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDateComponents *components = [cal components:( NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ) fromDate:date]; | |
[components setHour:0]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSUInteger)countLengthOfString:(NSString *)textString { | |
NSUInteger strlength = 0; | |
char *p = (char *)[textString cStringUsingEncoding:NSUnicodeStringEncoding]; | |
for (int i = 0; i < [textString lengthOfBytesUsingEncoding:NSUnicodeStringEncoding]; i++) { | |
if (*p) { | |
p++; | |
strlength++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <objc/objc-runtime.h> | |
// from objc_runtime_new.h with some simplifications | |
#if __LP64__ | |
typedef uint32_t mask_t; | |
#define FAST_DATA_MASK 0x00007ffffffffff8UL | |
#else | |
typedef uint64_t mask_t; | |
#define FAST_DATA_MASK 0xfffffffcUL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//计算NSString中英文字符串的字符长度。ios 中一个汉字算2字符数 | |
- (int)charNumber:(NSString*)strtemp | |
{ | |
int strlength = 0; | |
char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding]; | |
for (int i = 0; i < [strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding]; i++) { | |
if (*p) { | |
p++; | |
strlength++; | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from the commercial iOS PDF framework http://pspdfkit.com. | |
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved. | |
// Licensed under MIT (http://opensource.org/licenses/MIT) | |
// | |
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it. | |
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit. | |
#import <objc/runtime.h> | |
#import <objc/message.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; A minimal Mach-o x64 executable for OS X (also see below Mountain Lion version) | |
; | |
; $ nasm -f bin -o tiny_hello tiny_hello.s | |
; $ chmod +x tiny_hello | |
; $ ./tiny_hello | |
; Hello World! | |
; $ | |
; c.f. | |
; http://osxbook.com/blog/2009/03/15/crafting-a-tiny-mach-o-executable/ ( the original tiny mach-o executable ) |