小编Eri*_*ric的帖子

如何在Xcode中使用LLVM进行调试时更改变量值?

在Xcode中,GDB允许您在调试时更改局部变量(请参阅在XCode中调试时如何更改NSString值?).LLDB是否提供类似的功能?如果是这样,我们如何使用它?

debugging xcode lldb

165
推荐指数
3
解决办法
6万
查看次数

"./docker-compose.yml"中的版本不受支持.您可能会看到此错误,因为您使用的是错误的Compose文件版本

这是我的docker-compose.yml文件:

version: '3.1'

services:
  a:
    image: tutum/hello-world
  b:
    image: tutum/hello-world

secrets:
  id: my_password
Run Code Online (Sandbox Code Playgroud)

如果我跑,$ docker-compose-up我得到这个:

"./docker-compose.yml"中的版本不受支持.您可能会看到此错误,因为您使用的是错误的Compose文件版本.

我的docker-compose版本:

$ docker-compose --version
docker-compose version 1.11.0, build 6de1806
Run Code Online (Sandbox Code Playgroud)

这有什么不对?我的docker-compose版本不应该支持docker-compose.yml规范的v3.1(根据发行说明,它确实如此)?

docker-compose

75
推荐指数
5
解决办法
7万
查看次数

你如何使用docker-compose v3.1管理秘密值?

docker-compose.yml规范的3.1版引入了对秘密的支持.

我试过这个:

version: '3.1'

services:
  a: 
    image: tutum/hello-world
  secret: 
    password: the_password
  b:
    image: tutum/hello-world
Run Code Online (Sandbox Code Playgroud)

$ docker-compose up 收益:

Unsupported config option for services.secret: 'password'

我们如何在实践中使用秘密功能?

docker docker-compose docker-secrets

49
推荐指数
3
解决办法
5万
查看次数

iOS Parse Facebook登录错误308 FBSDKLoginBadChallengeString

我正在尝试使用Parse在我的iOS应用程序中实现Facebook登录.

let permissionsArray = ["public_profile", "email"]

PFFacebookUtils.logInInBackgroundWithReadPermissions(permissionsArray)
    { (user: PFUser?, error: NSError?) in

    if let user = user {
        //we logged in!
    }
    else {
        //login error!
    }
}
Run Code Online (Sandbox Code Playgroud)

这在模拟器中很有效,但在设备上却不行.在设备上,我收到此错误:

Error Domain = com.facebook.sdk.login Code = 308"无法完成操作.(com.facebook.sdk.login错误308.)

错误代码308用于FBSDKLoginBadChallengeString"登录响应缺少有效的质询字符串".

在我在Facebook上授权我的应用程序之后,这会被调用:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
Run Code Online (Sandbox Code Playgroud)

网址是:

fb1640722449492705://authorize/#state=%7B%22challenge%22%3A%225OKWv3wN%2BEH%2BeQu48Xv6ty%2BRuek%3D%22%2C%22com.facebook.sdk_client_state%22%3Atrue%2C%223_method%22%3A1%2C%220_auth_logger_id%22%3A%22564CD915-2CFC-4989-9AF6-CEA389908D51%22%7D&granted_scopes=user_birthday%2Cpublic_profile&denied_scopes=&signed_request=c8SBBDeaNpF-R_XTYx4LRA0BWm5p9IwXDr8M4nL3YXI.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiJBUURhTXJibGw4Q3dITkd5M0xnQmNkVTNuYWRkeEVoTU5mMmx3eFpZU2IwZl9SU284YXhZdXZaRS02RnA2bU5Cdy1CWkVoRmt2Zk1xX1AxSHltUG00aWhkWE9hYmlvWFBiMnpCYkVnR1RRX3lzZVFIZXdHU19OcmpkNUF6WGtob1dfVE4wTmRrSGk5MzY0V2hFWUJDV0dfcE16RXpQVExHWE13X1dzb0QzZGtITm5fM0tHNjFxUjJyM3RDWVlNQTE4WENpS1dXTHUyM2dIRVhmTXc3ZTQ0M2xDQUtGRl9KSXcyVk1sS01FOTQ4dHQ2U1Fqb0tlVkp4RmJNSEFsWDZFYWxlUnQ2aGRrTGZlU2xuVTV5VjZ1bFhldHkxeEV5RmRDZVFHb2RXQ0dULVVCd3QyM0haY0dxNk8zbnE1cDRNWjNFZ012U2JhSGZyMmF6Wm8xUXk2X2xSQVNWcFlMVDZUdU5wZnMwVkJqNEdSaFEiLCJpc3N1ZWRfYXQiOjE0MzM0MTg2MDksInVzZXJfaWQiOiIxNDM3MzM0ODk5OTIwNDA5In0&access_token=CAAXUOnbG6uEBANtAd9DzWBSu4LLOEcPsu86Ny0Ir

是的,我遵循了Parse的Facebook登录指南中的所有内容(确保所有捆绑ID都匹配,实现了所有必需的AppDelegate方法等).

这个错误究竟是什么意思,你如何解决它?

facebook ios parse-platform

43
推荐指数
8
解决办法
3万
查看次数

在UIAlertAction的处理程序中,自我应该被捕获为强者吗?

当写一个handler关闭的时候UIAlertAction,应该引用self强(默认)weak,还是unowned

已经有相关与这个主题(帖子1,2,3,4),但老实说,我不认为他们在这种情况下如何帮助.

让我们关注这个典型的代码:

func tappedQuitButton() {
    let alert = UIAlertController(title: "Confirm quit", message: nil, preferredStyle: .ActionSheet)

    let quitAction = UIAlertAction(title: "Quit", style: .Default) { (action) in
        self.dismissViewControllerAnimated(true, completion: nil)
    }
    alert.addAction(quitAction)

    let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (action) in
        self.dismissViewControllerAnimated(true, completion: nil)
    }
    alert.addAction(cancelAction)

    presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

这是UIViewController子类内部的一个函数,self视图控制器也会显示警报.

文件说:

只要该引用可能在其生命中的某个点上具有"无值",就使用弱引用来避免引用循环.如果引用始终具有值,请改用无主引用.

我可能会失明,但我仍然没有看到这有助于回答我的问题 …

ios swift uialertcontroller uialertaction

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

当用作函数中的参数时,swift闭包是否可以设置为默认值?

Swift函数的一个非常方便的功能是函数参数可以具有默认值:

func someFunction(parameterWithDefault: Int = 42) {
    //if no arguments are passed to the function call,
    //value of parameterWithDefault is 42
}
Run Code Online (Sandbox Code Playgroud)

如果参数是闭包,有没有办法让它有一个默认值?请参阅以下示例:

func sendBody(
    body: NSData? = nil,
    success: (data: NSData) -> Void,
    failure: (data: NSData?) -> Void) {
}
Run Code Online (Sandbox Code Playgroud)

有没有办法不强制开发人员为调用successfailure调用时传递值sendBody

macos ios swift

38
推荐指数
3
解决办法
7565
查看次数

制作NSURLSessionTasks队列的最佳实践

制作串行队列的最佳做法是NSURLSessionTasks什么?

就我而言,我需要:

  1. 获取JSON文件中的URL(NSURLSessionDataTask)
  2. 在该URL下载文件(NSURLSessionDownloadTask)

这是我到目前为止所拥有的:

session = [NSURLSession sharedSession];

//Download the JSON:
NSURLRequest *dataRequest = [NSURLRequest requestWithURL:url];

NSURLSessionDataTask *task =
[session dataTaskWithRequest:dataRequest
           completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

               //Figure out the URL of the file I want to download:
               NSJSONSerialization *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
               NSURL *downloadURL = [NSURL urlWithString:[json objectForKey:@"download_url"]];

               NSURLSessionDownloadTask *fileDownloadTask =
               [session downloadTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:playlistURL]]
                              completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
                                  NSLog(@"completed!");
                              }];

               [fileDownloadTask resume];

           }
 ];
Run Code Online (Sandbox Code Playgroud)

除了在另一个完成中写一个完成块看起来很乱的事实,我打电话时得到一个EXC_BAD_ACCESS错误 …

cocoa-touch ios nsurlsession

22
推荐指数
3
解决办法
2万
查看次数

NSURLSession中所有NSURLSessionTasks的平均进度

一个NSURLSession允许你添加大量NSURLSessionTask的后台下载.

如果你想检查一个单一的进度NSURLSessionTask,它就像这样简单

double taskProgress = (double)task.countOfBytesReceived / (double)task.countOfBytesExpectedToReceive;

但是,检查所有平均进度NSURLSessionTasksNSURLSession的最佳方法什么?

我以为我会尝试平均所有任务的进度:

[[self backgroundSession] getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *allDownloadTasks) {

    double totalProgress = 0.0;

    for (NSURLSessionDownloadTask *task in allDownloadTasks) {

        double taskProgress = (double)task.countOfBytesReceived / (double)task.countOfBytesExpectedToReceive;

        if (task.countOfBytesExpectedToReceive > 0) {
            totalProgress = totalProgress + taskProgress;
        }
        NSLog(@"task %d: %.0f/%.0f - %.2f%%", task.taskIdentifier, (double)task.countOfBytesReceived, (double)task.countOfBytesExpectedToReceive, taskProgress*100);
    }

    double averageProgress = totalProgress / (double)allDownloadTasks.count;

    NSLog(@"total progress: %.2f, average progress: %f", …
Run Code Online (Sandbox Code Playgroud)

macos cocoa cocoa-touch ios nsurlsession

18
推荐指数
2
解决办法
6651
查看次数

AFNetworking setImageWithURLRequest未设置远程图像

我正在使用AFNetworking UIImageView+AFNetworking.h将在线图像异步加载到UIImageView.

我使用时远程图像加载得非常好setImageWithURLRequest:,但是当我尝试使用setImageWithURLRequest:placeholderImage:success:failure远程图像时,UIImageView不会将其设置为UIImage.

这是我的代码:

@property (strong) IBOutlet UIImageView *imageView;

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    [_imageView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://i.imgur.com/fVhhR.png"]]
                       placeholderImage:nil
                                success:^(NSURLRequest *request , NSHTTPURLResponse *response , UIImage *image ){
                                    NSLog(@"Loaded successfully: %d", [response statusCode]);
                                }
                                failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
                                    NSLog(@"failed loading: %@", error);
                                }
     ];
}
Run Code Online (Sandbox Code Playgroud)

图像始终成功加载,状态代码始终为200.但我必须添加[_imageView setImage:image];successUIImageView来设置图像.

我正在使用iOS 6.0

有任何想法吗?

uiimageview ios afnetworking

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

如何在Swift中执行一次代码只执行一次?

到目前为止,我已经看到了这些问题的答案(1,2,3)建议使用GCD是dispatch_once这样的:

var token: dispatch_once_t = 0
func test() {
    dispatch_once(&token) {
        print("This is printed only on the first call to test()")
    }
    print("This is printed for each call to test()")
}
test()
Run Code Online (Sandbox Code Playgroud)

输出:

This is printed only on the first call to test()
This is printed for each call to test()
Run Code Online (Sandbox Code Playgroud)

但是等一下.token是一个变量,所以我可以很容易地做到这一点:

var token: dispatch_once_t = 0
func test() {
    dispatch_once(&token) {
        print("This is printed only on the first call …
Run Code Online (Sandbox Code Playgroud)

grand-central-dispatch swift

15
推荐指数
3
解决办法
2万
查看次数