在Xcode中,GDB允许您在调试时更改局部变量(请参阅在XCode中调试时如何更改NSString值?).LLDB是否提供类似的功能?如果是这样,我们如何使用它?
这是我的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.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'
我们如何在实践中使用秘密功能?
我正在尝试使用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方法等).
这个错误究竟是什么意思,你如何解决它?
当写一个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视图控制器也会显示警报.
该文件说:
只要该引用可能在其生命中的某个点上具有"无值",就使用弱引用来避免引用循环.如果引用始终具有值,请改用无主引用.
我可能会失明,但我仍然没有看到这有助于回答我的问题 …
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)
有没有办法不强制开发人员为调用success或failure调用时传递值sendBody?
制作串行队列的最佳做法是NSURLSessionTasks什么?
就我而言,我需要:
NSURLSessionDataTask)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错误 …
一个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) 我正在使用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];到success块UIImageView来设置图像.
我正在使用iOS 6.0
有任何想法吗?
到目前为止,我已经看到了这些问题的答案(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) ios ×6
swift ×3
cocoa-touch ×2
macos ×2
nsurlsession ×2
afnetworking ×1
cocoa ×1
debugging ×1
docker ×1
facebook ×1
lldb ×1
uiimageview ×1
xcode ×1