小编Jay*_*mar的帖子

Enumerating dictionary in Swift

I guess I noticed a bug in the Swift Dictionary enumeration implementation.

The output of this code snippet:

var someDict:[Int:String] = [1:"One", 2:"Two", 3:"Three"]
for (key, value) in someDict.enumerated() {
   print("Dictionary key \(key) - Dictionary value \(value)")
}
Run Code Online (Sandbox Code Playgroud)

should be:

Dictionary key 2 - Dictionary value Two
Dictionary key 3 - Dictionary value Three
Dictionary key 1 - Dictionary value One
Run Code Online (Sandbox Code Playgroud)

instead of:

Dictionary key 0 - Dictionary value (key: 2, value: "Two")
Dictionary key 1 - Dictionary value (key: …
Run Code Online (Sandbox Code Playgroud)

dictionary enumeration swift

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

console.log如何将javascript日期对象转换为人类可读的格式

的输出console.log({a:new Date()}){ a: 2019-05-19T11:30:57.514Z }

JSON.stringify({a:new Date()})的值为{"a":"2019-05-19T11:33:12.591Z"}

覆盖此后:Date.prototype.toJSON = function(){ return this.toLocaleString(); }

JSON.stringify({a:new Date()})的值为{"a":"5/19/2019, 5:09:31 PM"}

但输出console.log({a:new Date()})仍然是{ a: 2019-05-19T11:41:31.256Z }

尝试重写其他Date.prototype方法,如toISOString()toSourcetoStringtoUTCStringvalueOf许多其他方法。但没有任何帮助。

无法理解v8 js引擎的原生源代码。

有什么方法可以覆盖行为以获得所需的结果吗?

javascript overriding v8 date

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

错误:调用中无关的参数标签'no1:'

考虑下面给出的代码

class division {
    var count: Int = 0
    func incrementBy(no1: Int, no2: Int) {
        count = no1 / no2
        println(count)
    }
}

let counter = division()
counter.incrementBy(no1:1800, no2: 3)
Run Code Online (Sandbox Code Playgroud)

它给出以下错误:

error: extraneous argument label 'no1:' in call
counter.incrementBy(no1:1800, no2: 3)
                   ^~~~~
Run Code Online (Sandbox Code Playgroud)

当我删除标签时no1,编译器不会抱怨标签no2.

当我删除这两个水平no1no2,它提供了以下错误:

error: missing argument label 'no2:' in call
counter.incrementBy(1800,  3)
                   ^
                           no2: 
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释这种行为.提前致谢.

swift

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

RabbitMQ Exchange 和 Queue 不是自动创建的

我创建了一个新的 spring 应用程序,它将消息推送到 rabbitmq 服务器。我的 rabbitMQConfig java 文件如下所示:

@Configuration
public class RabbitMQConfig {

    private static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQConfig.class);

    @Value("${spring.rabbitmq.host}")
    private String SPRING_RABBITMQ_HOST;

    @Value("${spring.rabbitmq.port}")
    private int SPRING_RABBITMQ_PORT;

    @Value("${spring.rabbitmq.username}")
    private String SPRING_RABBITMQ_USERNAME;

    @Value("${spring.rabbitmq.password}")
    private String SPRING_RABBITMQ_PASSWORD;

    @Bean
    public RabbitTemplate rabbitTemplate(){
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(SPRING_RABBITMQ_HOST,SPRING_RABBITMQ_PORT);
        connectionFactory.setUsername(SPRING_RABBITMQ_USERNAME);
        connectionFactory.setPassword(SPRING_RABBITMQ_PASSWORD);
        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
        rabbitTemplate.setExchange("my.controller.exchange");
        rabbitTemplate.setRoutingKey("my.controller.key");
        return rabbitTemplate;
    }

    @Bean
    DirectExchange exchange() {
            return new DirectExchange("my.controller.exchange", true, false);
    }

    @Bean
    public Queue queue() {
            return new Queue("my.controller", true);
    }

    @Bean
    Binding exchangeBinding(DirectExchange …
Run Code Online (Sandbox Code Playgroud)

java rabbitmq spring-rabbit spring-amqp

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