Chuck's Blog

技术、读书与思考

1.编码 :

NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingGB_18030_2000);

//GB2312,GBK
NSISOLatin1StringEncoding
NSUTF8StringEncoding等

2.截取字符串

substringWithRange
substringToIndex:<#(NSUInteger)#>
substringFromIndex:<#(NSUInteger)#>

3.分割字符为NSArray数组

componentsSeparatedByString:<#(NSString *)#>

4.替换字符

stringByReplacingOccurrencesOfString

💬 评论

You want to use -[NSTask setStandardOutput:] to attach an NSPipe to the task before launching it. A pipe holds two file handles, the task will write to one end of the pipe, and you’ll read from the other. You can schedule the file handle to read all of the data from the background task and notify you when it’s complete.

It will look something like this:

- (void)launch {
    NSTask *task = [[[NSTaskalloc] init] autorelease];
    [task setLaunchPath:@"/path/to/command"];
    [task setArguments:[NSArray arrayWithObjects:..., nil]];
    NSPipe *outputPipe = [NSPipe pipe];
    [task setStandardOutput:outputPipe];
    [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(readCompleted:) name:NSFileHandleReadToEndOfFileCompletionNotificationobject:[outputPipe fileHandleForReading]];
    [[outputPipe fileHandleForReading] readToEndOfFileInBackgroundAndNotify];
    [task launch];
}
- (void)readCompleted:(NSNotification *)notification {
    NSLog(@"Read data: %@", [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem]);
    [[NSNotificationCenterdefaultCenter] removeObserver:selfname:NSFileHandleReadToEndOfFileCompletionNotificationobject:[notification object]];
}

If you also want to capture the output of standard error, you can use a second pipe and notification.

💬 评论

Today is a lucky day, I finally have my first sites on Internet.

We often lose many beautiful moments in our lives. So I decided to record my moments on the net, whether  you or me, witnessing my growth together.

💬 评论

assign就不用说了,因为基本上是为简单数据类型准备的,而不是NS对象们。

Retain vs. Copy

  • copy : 建立一个索引计数为1的对象,然后释放旧对象
  • retain :释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1
那上面的是什么该死的意思呢?

Copy其实是建立了一个相同的对象,而retain不是:

比如一个NSString 对象,地址为0×1111 ,内容为@”STR”

Copy 到另外一个NSString 之后,地址为0×2222 ,内容相同,新的对象retain为1 ,旧有对象没有变化

retain 到另外一个NSString 之后,地址相同(建立一个指针,指针拷贝),内容当然相同,这个对象的retain值+1

也就是说,retain 是指针拷贝,copy 是内容拷贝。哇,比想象的简单多了…

 

 

自己研究了一下,,上面文章的说法是对的,,但是遗漏了一点东西.

他说 copy是内容的拷贝  ,对于像NSString,的确是这样.

但是,如果是copy的是一个NSArray呢?比如,

 

NSArray *array = [NSArray arrayWithObjects:@"hello",@"world",@"baby"];
NSArray *array2 = [array copy];

 

这个时候,,系统的确是为array2开辟了一块内存空间,但是我们要认识到的是,array2中的每个元素,,只是copy了指向array中相对应元素的指针.这便是所谓的”浅复制”.了解到这一点非常重要….

常在声明一些成员变量时会看到如下声明方式:

@property (参数1,参数2) 类型 名字;

这里我们主要分析在括号中放入的参数,主要有以下三种:

setter/getter方法(assign/retain/copy)
读写属性(readwrite/readonly)
atomicity(nonatomic)

其中各参数说明如下:

assign
默认类型,setter方法直接赋值,而不进行retain操作
retain
setter方法对参数进行release旧值,再retain新值,如下代码:

-(void) setObj:(ClassX*) value

{
if (obj != value)
{
[obj release];
obj = [value retain];
}
}

setter方法进行Copy操作,与retain一样
nonatomic
禁止多线程,变量保护,提高性能
readwrite
产生setter\getter方法
readonly
只产生简单的getter,没有setter。

💬 评论

个人感觉设置神马的东西最好就是以下图的形式实现了,简洁明了。

b_large_mZHU_67430000022e1263

如何才能实现咧?

调用它吧~~~~

 

[NSAppbeginSheet:userSheetmodalForWindow:[mainViewwindow]modalDelegate:nildidEndSelector:NULLcontextInfo:NULL];

userSheet是我的设置窗口,[mainView window] 是主窗口的View类,后面的参数nil和NULL即可。

💬 评论

不知道算不算合格,懒得写opengl啥的了,直接用现成的。。。

b_large_Mrqi_725d000003831262 b_large_m1jb_599e000007361263 b_large_E5rP_2247000000921263 b_large_5mr1_71080000040e1263

b_large_QTNa_0cb8000001d11262

💬 评论

NSString *js1 = [NSStringstringWithFormat:@"alert('a'); ""];
[[selfexWebViewer] stringByEvaluatingJavaScriptFromString: js1];

太简单了哇

💬 评论

0%