如何确保我的函数仅在主线程上运行?(它更新UI元素)
这样的函数被认为是"坏"吗?
-(void)updateSomethingOnMainThread {
if ( ![[NSThread currentThread] isEqual:[NSThread mainThread]] )
[self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
else {
// Do stuff on main thread
}
}
Run Code Online (Sandbox Code Playgroud)
我这样写它是为了避免有第二个功能,最初我有这样的:
-(void)updateSomethingOnMainThread_real {
// Do stuff on main thread
}
-(void)updateSomethingOnMainThread {
[self performSelectorOnMainThread:@selector(updateSomethingOnMainThread_real) withObject:nil waitUntilDone:NO];
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将GoogleSign-In for iOS与此处的文档集成:https://developers.google.com/identity/sign-in/ios/start-integrating
如何在不使用Cocoapods的情况下完成此操作?
我已经尝试过使用Cocoapods直接下载的库和标题,但这导致了很多问题.有没有人成功将Cocoapod转换为独立的库/框架?
typedef struct
{
int i;
}one;
typedef struct
{
one two;
}three;
void writing_a_value(three *);
int main()
{
three four;
writing_a_value(&four);
printf("%d",four.two.i);
}
void writing_a_value(three *four)
{
four->(two->i)=1; /* problem here */
}
Run Code Online (Sandbox Code Playgroud)
我已经试过戴上牙箍(four->(two->i))=1,但它仍然不起作用.我必须传递指针,因为我必须将数据输入嵌套结构.
error=expected ( bracket,在注释行中.
如何使用指针传递结构并在嵌套结构中输入数据?