
IOS
LUOCHENLONG
这个作者很懒,什么都没留下…
展开
-
File's Owner和NSBundle
File's Owner:当NIB文件被载入一个已经运行了一段时间的程序中时,现存的对象需要与NIB文件中读取出来的对象建立一些连接。File's Owner提供了连接功能。在NIB文件中,File's Owner其实就是在NIB文件载入前就已经存在于对象中的占位符。载入NIB文件的对象需要提供所有者对象,所有者就取代File's Owner的位置。NSBundle:是用于程序中的资源目录。资原创 2017-11-30 15:53:37 · 246 阅读 · 0 评论 -
OC NSString和char*互相转换
constchar * foo="Blah blah"; NSString * bar; bar = [NSString stringWithUTF8String:foo];//char*转NSString foo = [bar UTF8String];//NSString转char*原创 2017-11-27 10:46:28 · 6699 阅读 · 0 评论 -
OC 中的比较
x==y 比较的是指针[x isEqual:y]比较的是字符串中的字符原创 2017-11-27 11:09:19 · 805 阅读 · 0 评论 -
OC 断言NSAssert
-(id)initWithEntryDate:(NSDate *)theDate{ NSAssert(theDate!=nil,@"Argument must be non -nil");//当theDate=nil抛出异常 self = [superinit]; if (self) { entryDate = theDate原创 2017-11-27 14:07:53 · 1137 阅读 · 0 评论 -
OC NSSpeechSynthesizer朗读
//创建NSSpeechSynthesizer的一个新实例,该实例使用默认声音 NSSpeechSynthesizer _sppeechSynth = [[NSSpeechSynthesizeralloc]initWithVoice:nil];//开始读[_sppeechSynthstartSpeakingString:内容];//停止原创 2017-11-27 16:54:19 · 630 阅读 · 0 评论 -
__bridges、__block、typedef
__brigges:将对象应用转换到不受ARC机制控制的类型。void的字面意思是“无类型”,void *则为“无类型指针”,void *可以指向任何类型的数据__block:一个变量被标记为__block后,编译器将它变成一个全局变量,使用__block指定的变量并不被块retain,这可以有效避免强引用的循环调用。typedef:为复杂的声明定义简单的别名原创 2017-12-06 16:41:07 · 252 阅读 · 0 评论 -
block和del
AppDelegate.h#import #import "MyProtocol.h"@interface AppDelegate : NSObject NSApplicationDelegate,NSTableViewDataSource,NSTabViewDelegate,MyProtocol>{ IBOutlet NSTableView *tab原创 2017-12-06 16:50:14 · 280 阅读 · 0 评论 -
Delegate简单案例
MyProtocol.h#import @protocol MyProtocol NSObject>@required-(NSString*)returnValue;-(void)weiZhu:(NSString*)string;@optional-(void)zhuFan:(NSString*)string;@end@end原创 2017-12-06 17:00:32 · 210 阅读 · 0 评论 -
OC线程
AppDelegate.h#import @interface AppDelegate : NSObject NSApplicationDelegate>{ NSOperationQueue *processingQueue;}@property (weak) IBOutletNSTextField *titleLabel;原创 2017-12-08 08:09:29 · 227 阅读 · 0 评论 -
Xcode在调试时查看到变量都是nil的问题
在release状态下默认看不到变量的值下面是解决办法:在Project的Build Settings中把 Optimization Level 设置成 None 即可。原创 2018-12-21 08:39:55 · 499 阅读 · 0 评论 -
Xcode 查找调用方法的地方
按住Cmmand键,鼠标选择相应的方法或对象,在弹出菜单中选择 Callers...原创 2018-12-21 09:19:01 · 1317 阅读 · 0 评论 -
OC 产生某个范围的随机数
int intValue; intValue = (int)(random()%100)+1;//1-100内原创 2017-11-27 09:50:27 · 2001 阅读 · 0 评论 -
OC 协议和委托
//委托者#import #import "MyProtocol.h"@interface Me : NSObject{ id MyProtocol> delegate1; id MyProtocol> delegate2;}@property(strong,nonatomic)idMyProtocol> delegate1;@prope原创 2017-12-06 10:36:05 · 464 阅读 · 0 评论 -
OC 字符串
unichar data[6] = {97,98,99,100,101,102}; //使用Unicode数值数组初始化字符串 NSString* str = [[NSStringalloc]initWithCharacters:data length:6]; NSLog(@"%@",str); //将C风格的字符串转原创 2017-12-14 15:10:55 · 415 阅读 · 0 评论 -
OC全局宏配置路径
在TARGETS->Build Settings->Apple LLVM 7.0 - Language 项目 Prefix Header $(SRCROOT)/项目明细/文件名.pch当Precompile Prefix Header为YES,那么pch会被预编译,预编译后的pch文件会被缓存起来,从而提高编译速度。当 Precompile Prefix Header 为N原创 2017-12-08 15:49:39 · 475 阅读 · 0 评论 -
OC NSLog
//NSLog()函数支持的格式字符 int d = -100; NSLog(@"以带符号的十进制形式输出整数(正数不输出符号)%d",d); char c= 'c'; NSLog(@"以字符形式输出,只输出一个字符 %c",c); char *cString = "cString";原创 2017-12-09 11:11:16 · 669 阅读 · 0 评论 -
OC 位运算
#import int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); //&参加运算的两个数制,按二进制进行 与运算。如果两个相应的二进位数为1,刚该位的结原创 2017-12-11 09:48:30 · 779 阅读 · 0 评论 -
OC 递归
#import int fn(int n){ if(n==0){ return 1; }else if(n==1){ return 4; }else{ return 2*fn(n-1)+fn(n-2); }}int main(int argc, const char * arg原创 2017-12-11 10:40:20 · 834 阅读 · 0 评论 -
OC 宏和预编译
#import #define PI 3.1415926#define TOW_PI PI*2#define NO_CHESS "+"#define GIRTH(r) (PI*2*(r))#define AREA(r) (PI*(r)*(r))//宏的参数一定要括号起来#define iPad#define AGE 20//#undef PI//结束宏的范围转载 2017-12-11 15:09:04 · 291 阅读 · 0 评论 -
OC KVC
KVC使用==================User===================#import @interface User : NSObject@property (nonatomic,copy)NSString* name;@property (nonatomic,copy)NSString* pass;@property (nonatom原创 2017-12-12 17:17:44 · 267 阅读 · 0 评论 -
OC KVO
===============Item==================#import @interface Item : NSObject@property (nonatomic,strong)NSString*name;@property (nonatomic,assign)double price;@end#import "Item.h"原创 2017-12-12 17:22:28 · 214 阅读 · 0 评论 -
在字符串中搜索子字符串
//在字符串中搜索子字符串 NSRange aRange; NSString *big =@"abbakachakazazzz"; NSString *small = @"KA"; // NSCaseInsensitiveSearch = 1,// NSLiteralSearch =原创 2017-12-04 14:12:41 · 427 阅读 · 0 评论 -
类别和扩展
类别通过类别可以动态的现有的类添加新方法,不需要创建子类,不需要访问原有类的源代码。类别说明1.通过类别为指定类添加新方法之后,这个方法不仅会影响该类,还会影响该类所有的子类。每个子类都会获取类别的扩展方法。2.可以根据需要对一个类添加多个类别,不同的类别都可以对原有类增加方法定义。案例:#import @interface NSNumber (Ca原创 2017-12-13 16:56:05 · 251 阅读 · 0 评论 -
协议
协议是用于定义类或多个类应该遵守的规范案例:#import @protocol Output@required//必须实现-(void)output;@optional//可选择实现-(void)addData:(NSString*)msg;@end#import @protocol Productable-(NSDate*)原创 2017-12-13 17:02:13 · 194 阅读 · 0 评论 -
OC 类型转换
NSData-> NSStringNSString *aString = [[NSString alloc] initWithData:adataencoding:NSUTF8StringEncoding];NSString->NSDataNSString *aString = @"1234abcd";NSData *aData = [aString dataUs...原创 2019-08-11 19:15:38 · 527 阅读 · 0 评论