小编And*_*ino的帖子

用户默认值不随Swift 3一起保存

我正在尝试使用UserDefaults持久保存一个布尔值.这是我的代码:

public static var isOffline = UserDefaults.standard.bool(forKey: "isOffline") {
        didSet {
            print("Saving isOffline flag which is now \(isOffline)")
            UserDefaults.standard.set(isOffline, forKey: "isOffline")
            UserDefaults.standard.synchronize()
        }
    }
Run Code Online (Sandbox Code Playgroud)

为什么不起作用?这段代码有什么问题?

编辑:问题是,当我尝试从中检索"isOffline"密钥时,UserDefaults我总是得到一个false.

编辑2:我在行的.onChange方法中设置了isOffline(我使用Eureka作为框架来创建表单).该标志在应用程序的生命周期中保持正确的值,但是当我关闭它时,该值可能会以某种方式被删除.

save nsuserdefaults ios swift

12
推荐指数
3
解决办法
8853
查看次数

今天扩展通用应用程序

如何创建一个适用于今日扩展的适用于iPad和iPhone的故事板?我可以使用大小类吗?还有其他方法吗?提前致谢

iphone ipad ios ios-app-extension today-extension

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

Swift - 任意数组字符串的数组

如何将最初声明为Any对象的容器的数组转换为字符串数组(或任何其他对象)?示例:

var array: [Any] = []
.
.
.
array = strings // strings is an array of Strings
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:"无法指定字符串类型的值以键入任何"

我能怎么做?

arrays casting ios swift

7
推荐指数
2
解决办法
5257
查看次数

该命令取决于目标“MyApp”(项目“MyApp”)中的命令:脚本阶段“[CP] Copy Pods Resources”

我尝试删除、更新并重新安装 Pod。查找它,复制捆绑资源中没有重复的文件,但我收到此错误,我似乎不明白为什么?

\n
\n

多个命令生成\n'MY_PATH/Library/Developer/Xcode/DerivedData/MyApp-fniucmthwofzlhdqjqjmozyhxhgt/Build/Products/Debug-iphoneos/MyApp.app/Assets.car':

\n
    \n
  1. 目标“MyApp”(项目“MyApp”)具有带有\ninput\n“MY_PROJECT_PATH/Assets.xcassets”的编译命令
  2. \n
  3. 该命令取决于目标“MyApp”(项目\n“MyApp”)中的命令:脚本阶段 \xe2\x80\x9c[CP] Copy Pods Resources\xe2\x80\x9d
  4. \n
\n
\n

我还尝试使用rm -rf ~/Library/Developer/Xcode/DerivedData命令清除派生数据文件夹,但此错误仍然没有消失。

\n

xcode cocoapods swift

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

目标C - 如何编写宏

我需要编写一个多行宏.我需要这个,因为我必须将部分代码"粘贴"到我的代码中的特定点.我怎样才能做到这一点?

macros multiline c-preprocessor

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

iOS - 后台进程和UI更新

问题很简单:我的应用程序控制每次启动时是否有更新.如果有更新,弹出窗口将显示是或否选择.当用户点击是4方法开始.这些方法下载xml文件并上传CoreData.这是警报的代码:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex==1) {
        [self showActivityViewer];
        [self downloadControlAndUpdatePoi];
        [self downloadControlAndUpdateItinerari];
        [self downloadControlAndUpdateArtisti];
        [self downloadControlAndUpdateEventi];
        [self hideActivityViewer];
        NSLog(@"AGGIORNA");
    } else {
        NSLog(@"NON AGGIORNARE");
        return;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是有一个问题:当用户点击是时,警报不会消失并保留在屏幕上,直到所有方法都完成.所以我尝试这个其他代码:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex==1) {
        [self showActivityViewer];
        [NSThread detachNewThreadSelector:@selector(startDownloads) toTarget:self withObject:nil];
        [self hideActivityViewer];
        NSLog(@"AGGIORNA");
    } else {
        NSLog(@"NON AGGIORNARE");
        return;
    }
}

-(void)startDownloads {
    NSInvocationOperation *opPoi=[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(downloadControlAndUpdatePoi) object:nil];
    NSInvocationOperation *opItinerari=[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(downloadControlAndUpdateItinerari) object:nil];
    NSInvocationOperation *opArtisti=[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(downloadControlAndUpdateArtisti) object:nil];
    NSInvocationOperation *opEventi=[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(downloadControlAndUpdateEventi) object:nil]; …
Run Code Online (Sandbox Code Playgroud)

background nsoperation nsthread nsoperationqueue ios

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

iPhone Objective C - wait_fences:未能收到回复:10004003

我有这个奇怪的错误:wait_fences:在此代码中未能收到回复:10004003:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex==0) {
        [self showActivityViewer];
        [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(hideActivityViewer) userInfo:nil repeats:NO];
        [self downloadControlAndUpdatePoi];
        [self downloadControlAndUpdateItinerari];
        [self downloadControlAndUpdateEventi];
        [self downloadControlAndUpdateArtisti];
        NSLog(@"AGGIORNA");
    } else {
        NSLog(@"NON AGGIORNARE");
        return;
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么??哪里可能是错误或问题?

iphone alert objective-c reply ios

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

iOS - CALayer和Gesture/Swipe识别器

我在视图中添加了一个图层来创建渐变背景颜色,但我需要在视图中使用UISwipeGestureRecognizer.问题是,现在,使用图层,滑动识别器不起作用!我能怎么做??我可以在图层中添加滑动识别器吗?谢谢

calayer uiview uigesturerecognizer ios

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

iOS - UITextView成为FirstResponder

这就是问题:当MessageComposeViewController被解除时,我的textView不会成为第一个响应者,键盘也不会出现.为什么?我把[textView becomeFirstResponder]代码放进去了viewWillAppear.我能怎么做??

uitextview becomefirstresponder ios

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

我如何等待方法或函数完成运行其代码?

我需要找到一个等待方法或函数完成来运行其代码的解决方案.我怎样才能做到这一点?示例:方法a,方法b.完成后我必须运行b!谢谢.

objective-c

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