随笔分类 - OC
IOS-OC
摘要:方法//Resize image- (UIImage *)resizeImage:(UIImage *)image withQuality:(CGInterpolationQuality)quality rate:(CGFloat)rate{ UIImage *resized = nil; CGFloat width = image.size.width * rate; CGFloat height = image.size.height * rate; UIGraphicsBeginImageContext(CGSizeMake...
阅读全文
摘要:f your project doesn't use ARC: you must add the-fobjc-arccompiler flag toSVHTTPRequest.mandSVHTTPClient.min Target Settings > Build Phases > Compile Sources.
阅读全文
摘要:一般如果只是 alloc init 那么 用new 是一样的SomeObject*myObject =[[SomeObject alloc] init];SomeObject*myObject =[SomeObjectnew];即上述两种情况是一样的!#import "InitAllocNewTest.h"@implementation InitAllocNewTest+(id)alloc{ NSLog(@"Allocating..."); return [super alloc];}-(id)init{ NSLog(@"Initializin
阅读全文
摘要:方法一: 选择Product > Clean 然后重新编译--运行;方法二:找到-Prefix.pch文件,把中间的#ifdef __OBJC__ #import #import#endif把上面 宏 全部注掉---运行 去年注释----再运行
阅读全文
摘要:static BlockBackground *_sharedInstance = nil;+ (BlockBackground*)sharedInstance{ if (_sharedInstance != nil) { return _sharedInstance; } @synchronized(self) { if (_sharedInstance == nil) { _sharedInstance = [[self alloc] init]; } } return _sharedIn...
阅读全文
摘要:通常网络请求的数据,如果不做处理在输出时显示是 \U 之类的编码的;不需要导入别的类库解决方法- (NSString *)replaceUnicode:(NSString *)unicodeStr { NSString *tempStr1 = [unicodeStr stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"]; NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\"
阅读全文
摘要:- (void)showTaped{ /* dispatch_get_global_queue dispatch_get_main_queue dispatch_queue_create dispatch_get_current_queue dispatch_queue_get_label dispatch_set_target_queue dispatch_main */ //卡UI// dispatch_async(dispatch_get_main_queue(), ^{// [sel...
阅读全文
摘要:一:std:编译器错误解决二:错误提示"std::string::find_first_of(char const*, unsigned long, unsigned long) const", referenced from: split_string(std::string const&, std::string const&) in libopencv_core.a(cmdparser.o) "std::string::find_first_of(char, unsigned long) const", referenced fro
阅读全文
摘要:+ (KKTextHUB *)sharedTextHUB{ static KKTextHUB *sharedHub = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedHub = [[self alloc]initWithFrame:CGRectMake(0, 0, 0, 0)]; }); return sharedHub;}
阅读全文
摘要:SEL selAction =NSSelectorFromString([actionArrayobjectAtIndex:indexArray]);[item addTarget:self action:selAction];Objective-C在编译的时候,会根据方法的名字(包括参数序列),生成一个用 来区分这个方法的唯一的一个ID,这个ID就是SEL类型的。我们需要注意的是,只要方法的名字(包括参数序列)相同,那么它们的ID都是相同的。就是 说,不管是超类还是子类,不管是有没有超类和子类的关系,只要名字相同那么ID就是一样的。我们可以方便的通过方法的名字,获取到方法的ID也就是我们所说
阅读全文
摘要:/* CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.calculationMode = kCAAnimationPaced; pathAnimation.fillMode = kCAFillModeForwards; pathAnimation.removedOnCompletion = NO; pathAnimation.duration = 15.0; p...
阅读全文
摘要:/* %@ 对象 %d, %i 整数 %u 无符整形 %f 浮点/双字 %x, %X 二进制整数 %o 八进制整数 %zu size_t %p 指针 %e 浮点/双字 (科学计算) %g 浮点/双字 %s C 字符串 %.*s Pascal字符串 %c 字符 %C unichar %lld 64位长整数(long long) %llu 无符64位长整数 %Lf 64位双字 */
阅读全文
摘要:一:创建 宏 文件SynthesizeSingleton.hSynthesizeSingleton.h#if __has_feature(objc_arc) // ARC Version#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \\+ (classname *)shared##classname\{\ static classname *shared##classname = nil;\ static dispatch_once_t onceToken;\ dispatch_once(&onceToken, ^{\...
阅读全文
摘要:iOS 5 中对属性的设置新增了strong 和weak关键字来修饰属性(iOS 5 之前不支持ARC)strong 用来修饰强引用的属性;@property (strong) SomeClass * aObject;对应原来的@property (retain) SomeClass * aObject; 和 @property (copy) SomeClass * aObject;weak 用来修饰弱引用的属性;@property (weak) SomeClass * aObject;对应原来的@property (assign) SomeClass * aObject;__weak, __
阅读全文
摘要://适用于调试代码,当程序执行出错时,程序立即停止,并抛出异常; //这是一个宏 --称之为 断言; int x = 1; NSAssert(x!=0, @"**********************不能为0"); /* 1: 如上代码,当 !=0时,不会打印上述 不能为0; 2:当 x=0 时,就会打印上述信息,并程序立即抛出异常; */内部实现--------- #define NSAssert(condition, desc, ...) \ do { \ __PRAGMA_PUSH_NO_EXTRA_ARG_W...
阅读全文
摘要:1. iOS APP Project or Mac APP Project编译错误提示:“The run destination My Mac 64-bit is not valid for Running the scheme '***'.The scheme '***' contains no buildables that can be built for the SDKs supported by the run destination My Mac 64-bit. Make sure your targets all specify SDKs that
阅读全文
摘要:#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)-(void)viewDidAppear:(BOOL)animated{ if (iPhone5) { NSLog(@"555555"); } else { NSLog(@"noooooo"); }}方法二...
阅读全文
摘要:/* libxml/tree.h file not found 设置libxml2文件路径 并添加 libxml.2.2.dylib库文件; 1:Project-->Build Settings --> Header Search Paths --->添加 /usr/include/libxml2 2:Project ---> Build Phases ---> Link Binary With Libraries ---> 添加 libxml.2.2.dylib 库文件 ; */
阅读全文
摘要:1.实例变量命名规范:_name下划线起始。国内编程无此习惯,要知道下划线起始的是实例变量2.protected继承类的时候可以用,即子类可用其父类的protected型实例变量3.getter方法名称不能是 -(int)getAge这样,应写为-(int)age;4.带形参的函数中“:”是函数名的一部分5.设置器、访问器,即getter、setter方法6.只读,就是没有setter方法,实例变量可以在getter方法中返回一个默认值,如果用@property属性,则自定义一个getter方法,且最好不要与默认getter方法名重名,例如:@property(retain,nonatomic
阅读全文
摘要:@property和@synthesize总是配对使用的,功能是让编译器自动生成一个与数据成员相关的读写方法,类似与Java的setter/getter方法。@property的参数有三种类型:读写属性: (readwrite/readonly)setter语意:(assign/retain/copy)原子性: (atomicity/nonatomic)读写属性即设置数据成员是可写还是只读,默认是readwrite,如果是readonly则相当于不生成setter方法。原子性即设置数据成员是否可以多线程访问,默认nonatomic,这样性能更好。关于setter语意,举个例子:NSString
阅读全文