小编ser*_*buj的帖子

Int或NSInteger作为方法参数的对象.Objective-C的

我在传递一个数字作为方法的参数时遇到了一些麻烦:

- (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没用,因为它是不可变的,我需要不断更改值.知道我该怎么办?

谢谢.

iphone objective-c nsinteger

13
推荐指数
2
解决办法
4万
查看次数

timeout stringwithcontentsofurl

我有这个对stringwithcontentsofurl的调用:

[NSString stringWithContentsOfURL:url usedEncoding:nil  error:nil];
Run Code Online (Sandbox Code Playgroud)

我怎么能给出一个简单的超时?我不想使用线程或操作队列(url的内容大约是100个字符),我只是不想在连接缓慢时等待太久.

nsstring

10
推荐指数
2
解决办法
6184
查看次数

使用唯一结构作为参数C的pthread

我有这段代码给我带来了麻烦.我知道所有线程都在读取相同的结构.但我不知道如何解决这个问题.

#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, &param ); // !!!!
    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)

c parameters struct pthreads

1
推荐指数
1
解决办法
7642
查看次数

标签 统计

c ×1

iphone ×1

nsinteger ×1

nsstring ×1

objective-c ×1

parameters ×1

pthreads ×1

struct ×1