小编s_k*_*les的帖子

Swift错误:对泛型类型Dictionary的引用需要<...>中的参数

错误Reference to generic type Dictionary requires arguments in <...>出现在函数的第一行.我试图让函数返回从api检索到的NSDictionary.有谁知道这里会发生什么?

class func getCurrentWeather(longitude: Float, latitude: Float)->Dictionary?{

let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apikey)/")
let forecastURL = NSURL(string: "\(longitude),\(latitude)", relativeToURL:baseURL)

let sharedSession = NSURLSession.sharedSession()
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in

    if(error == nil) {
        println(location)
        let dataObject = NSData(contentsOfURL:location!)
        let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary
        return weatherDictionary
    }else{
        println("error!")
        return nil

    }
})
}
Run Code Online (Sandbox Code Playgroud)

编辑:

第二期:

    class …
Run Code Online (Sandbox Code Playgroud)

iphone xcode dictionary ios swift

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

在 Mocha 单元测试 Node.js 期间找不到环境变量

我正在尝试运行 mocha 单元测试,但我正在测试的模块使用的模块之一需要环境变量,例如 process.env.CLIENT_ID 到 dotenv。当我运行 Mocha 测试时,找不到这些环境变量。如何在我的 mocha 单元测试中包含 .env 文件中的环境变量?

测试.js:

    var messenger = require(__dirname + "/../routes/messenger.js");
var assert = require("assert") 


describe("Return Hello", function(){
    it('Should return hello',function(done){
        messenger.testFunction(function(value){
            assert(value === "Hello", 'Should return Hello')
            done()
        })
    })
})
Run Code Online (Sandbox Code Playgroud)

包含通过单元测试的问题的文件部分:

    var express = require("express")
var router = express.Router();

require('dotenv').config()

var plaid = require('plaid');
var mysql = require('mysql');

var fs = require("fs");


const plaidClient = new plaid.Client(
    process.env.PLAID_CLIENT_ID, // these are all not found
    process.env.PLAID_SECRET,
    process.env.PLAID_PUBLIC_KEY,
    plaid.environments.sandbox);
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing mocha.js node.js

9
推荐指数
2
解决办法
6497
查看次数

无法连接到EC2-ssh:连接到主机端口22:连接被拒绝

我目前在国外,我正在尝试通过ssh连接到我的EC2实例,但出现错误 ssh: connect to host ec2-34-207-64-42.compute-1.amazonaws.com port 22: Connection refused

我打开了前往纽约的VPN,但仍然没有任何变化。无法连接到该实例的原因可能是什么?

该实例仍在运行并为网站提供服务,但是我无法通过ssh连接。这是我所住的wifi或实例本身的问题吗?

ssh amazon-ec2 amazon-web-services

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

如何检查Angular是否在生产服务器与本地主机上运行

我希望Angular 4使用的一些变量是不同的,具体取决于我是在生产服务器上还是在本地主机上运行应用程序进行开发。我怎样才能做到这一点?对于node.js,我使用环境变量,但是我不确定是否可以对Angular Web应用程序使用类似的环境变量。在没有明确设置然后部署的情况下将Angular设置为生产的最佳方法是什么?

typescript angular

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

AWS Codedeploy 错误:scripts/applicationstart.sh 不可执行。试图使其可执行

我正在 EC2 实例上运行 Ubuntu,并尝试设置代码部署来运行脚本以在 appspec.yml 中配置部署。然而,这些钩子脚本似乎没有运行。当我检查代码部署错误日志时,我看到错误消息InstanceAgent::Plugins::CodeDeployPlugin::HookExecutor: Script at specified location: scripts/applicationstart.sh is not executable. Trying to make it executable.

这非常令人困惑,因为我的脚本非常简单,我不确定为什么它们不被接受。这是在 appspec.yml 文件中调用它们的位置:

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/teller-install
hooks:
  BeforeInstall:
    - location: scripts/beforeinstall.sh
      timeout: 300
      runas: root
  ApplicationStart:
    - location: scripts/applicationstart.sh
      timeout: 300
      runas: root
Run Code Online (Sandbox Code Playgroud)

这是我调用的两个脚本:

#!/bin/bash

cd /home/ubuntu/teller-install/Server && npm install
exit 0
Run Code Online (Sandbox Code Playgroud)

第二个:

    #!/bin/bash

pm2 start /home/ubuntu/teller-install/Server/app.js
exit 0
Run Code Online (Sandbox Code Playgroud)

部署成功,但脚本未运行。

这是我在 codedeploy-agent 日志文件中收到的错误消息:

    2017-06-01 23:59:01 WARN  [codedeploy-agent(3504)]: InstanceAgent::Plugins::CodeDeployPlugin::HookExecutor: Script at specified location: scripts/applicationstart.sh …
Run Code Online (Sandbox Code Playgroud)

bash amazon-web-services node.js aws-code-deploy

5
推荐指数
2
解决办法
6132
查看次数

当 pm2 从脚本启动时,Node.js 应用程序无法访问任何环境变量,但从 ssh 启动时可以

我正在尝试使用 pm2 进程管理器在生产 EC2 服务器上启动 node.js 应用程序。

当我 ssh 进入实例并运行时pm2 start app.js,PM2 启动得很好并且可以访问所有环境变量。一切安好。

但是,我想pm2 start app.js从名为 的 Codedeploy 挂钩脚本运行applicationstart.sh,该应用程序失败并显示errored状态,因为它缺少所有环境变量。 在此输入图像描述

这是添加脚本的位置,以便每次部署时都会启动该脚本并调用 pm2 start:appspec.yml

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/teller-install
hooks:
  AfterInstall:
    - location: scripts/afterinstall.sh
      timeout: 1000
      runas: root
  ApplicationStart:
    - location: scripts/applicationstart.sh
      timeout: 300
      runas: ubuntu
Run Code Online (Sandbox Code Playgroud)

这是应用程序启动脚本:

#!/bin/bash

echo "Running Hook: applicationstart.sh"
cd /home/ubuntu/teller-install/Server/
pm2 start app.js
exit 0
Run Code Online (Sandbox Code Playgroud)

当我从 ssh 运行脚本时,我以 ubuntu 身份登录,并将 appconfig.yml 中的脚本设置为也以 ubuntu 身份运行。

为什么从终端启动 …

bash amazon-web-services node.js pm2

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

其次,对promise的.then()方法将使用未定义的数据进行调用

我在一个名为accountManager的服务中有一个函数,该函数返回如下所示的promise:

该承诺上的.then()会触发并打印出预期的响应。

  signIn(email:String,password:String):Promise<any>{
    return this.http.post('http://localhost:3000/api/signin',JSON.stringify({
      "email": email,
      "password": password
    }),{headers: this.headers})
      .toPromise()
      .then(res => {
      //**This is defined**
        console.log(res);
      })
  }
Run Code Online (Sandbox Code Playgroud)

当我在另一个使用此signIn方法的类中时,就会出现问题。承诺内的响应现在为空。当我从函数本身省略承诺时,返回的承诺的.then()具有响应值。

if (this.loginForm.valid === true){
  this.accountManager.signIn(this.email,this.password)
    .then(response =>{

    //**This .then has an undefined response when added on to the promise returned from the signIn function.**

      let body = JSON.parse(response._body)

      if (body.payload.success === true){
        this.router.navigate(['/']);
      }else{
        this.signInError = true;
      }
  })
    .catch(error=>{
      this.signInError = true;
    })
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么在返回诺言但诺言给定的诺言中没有值的情况下,诺言.then()为何包含一个值?我很高兴澄清是否有任何令人困惑的地方。谢谢 :)

javascript promise rxjs typescript angular

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

此类不是键标签的键值编码兼容

我正在使用一个自定义UITableViewCell,它已经有一些完全有效的UI元素.但是,我只是尝试为它们添加两个标签,当我连接插座并调用时cell.label.text = @"text";,程序崩溃并出现错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FeedTableViewCell 0x7aa53d00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key likesLabel.'

我检查了是否有任何没有元素的连接,但没有.当除了新UI元素之外的所有内容都添加到单元格时,该应用程序完全有效 就在我添加应用程序崩溃的新UI元素时.这是什么问题?

自定义单元类.h

#import <UIKit/UIKit.h>

@interface FeedTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *profileImage;
@property (weak, nonatomic) IBOutlet UITextView *questionTextView;
@property (weak, nonatomic) IBOutlet UIButton *usernameButton;
@property (weak,nonatomic) IBOutlet UILabel * likesLabel;
@end
Run Code Online (Sandbox Code Playgroud)

喜欢的标签是问题的出路

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{

    FeedTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) { …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios nsunknownkeyexception

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

Xcode 8 beta 4:在物理设备上运行时"无法附加到pid:1110"

我做了一个消息扩展,当我在iOS模拟器上运行时,一切都没有问题.当我尝试在手机上运行它时,它会编译并说在崩溃之前运行大约5秒并在Xcode中给我一个弹出消息说Could not attach to pid这是一个截图:

我得到的错误

我在iOS 10中使用Xcode 8 beta 4.一切都在模拟器中运行良好,这是在物理设备上.我重新启动并重新启动了一切.我甚至试过两部手机.谁知道解决方案?

谢谢

xcode swift ios10 xcode8-beta4

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

Elastic Beanstalk CLI错误:此目录尚未使用EB CLI设置您必须先运行"eb init"

我正在尝试连接到我在WEB浏览器控制台中通过CLI创建的弹性beanstalk应用程序,但每次我尝试执行任何操作时都说我没有使用EB CLI设置目录,我必须首先运行'eb init'.但是,我不想创建一个新的应用程序,我只想通过终端/ cmd访问旧的应用程序,以便我可以将nodejs部署到它.如何在不使用'eb init'创建新应用程序的情况下通过CLI访问它?

谢谢

ssh command-line-interface amazon-web-services node.js amazon-elastic-beanstalk

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

我怎样才能将Angular 4 localhost提供给ngrok?

我想使用ngrok使我的本地开发可用于需要使用webhooks的外部api但是当我在端口4200上运行ngrok时,Invalid Host Header当我尝试从ngrok链接访问该站点时,Angular会给我.有谁知道我如何使用ngrok从localhost外部访问角度ng服务?

谢谢

typescript webpack ngrok angular

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

如何检测属性何时更改服务?

我希望组件能够订阅或通知服务中变量的更改.

我查看了Observables,但我认为这不会起作用,因为你需要完成流,我需要知道变量在整个组件处于活动状态时的变化.

有谁知道这个好策略?

typescript angular

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

如何从NSDate计算年龄

我正在开发一个应用程序,需要根据他们的生日找到某人的年龄.我有一个简单的NSDate但我怎么会发现这个NSDateFormatter

nsdate nsdateformatter nsdatecomponents ios

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