我在传递一个数字作为方法的参数时遇到了一些麻烦:
- (void)meth2:(int)next_int;
Run Code Online (Sandbox Code Playgroud)
要调用该方法,我需要这个:
int next_int = 1;
[self performSelectorOnMainThread:@selector(meth2:) withObject:next_int waitUntilDone:NO];
//update next_int and call meth2 again
Run Code Online (Sandbox Code Playgroud)
在这一点上,我得到一个"没有强制转换的整数指针"错误,并且会发生相同的情况NSInteger.一个NSNumber没用,因为它是不可变的,我需要不断更改值.知道我该怎么办?
谢谢.
我有这个对stringwithcontentsofurl的调用:
[NSString stringWithContentsOfURL:url usedEncoding:nil error:nil];
Run Code Online (Sandbox Code Playgroud)
我怎么能给出一个简单的超时?我不想使用线程或操作队列(url的内容大约是100个字符),我只是不想在连接缓慢时等待太久.
我有这段代码给我带来了麻烦.我知道所有线程都在读取相同的结构.但我不知道如何解决这个问题.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int a,b;
} s_param;
void *
threadfunc(void *parm)
{
s_param *param2 = parm;
printf("ID:%d and v:%d\n",param2->a,param2->b);
pthread_exit(NULL);
}
int main(int argc, char **argv)
{
pthread_t thread[3];
int rc=0,i;
void * status;
for(i=0; i<3 ; ++i){
s_param param;
param.b=10;
param.a=i;
rc = pthread_create(&thread[i], NULL, threadfunc, ¶m ); // !!!!
if(rc){
exit(1);
}
}
for(i=0; i<3 ; ++i){
pthread_join(thread[i],&status);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
ID:2 and v:10
ID:2 and v:10
ID:2 and …Run Code Online (Sandbox Code Playgroud)