小编Jan*_*ner的帖子

检查空/未定义的打字稿函数

我正在使用VS Code它,它在使用时很有帮助Typescript,因为它会告诉您当前存在的问题,而无需进行转译。我正在使用TypescriptnodeJS效果非常好。

我遇到的唯一问题是所谓的“空/未定义检查函数”。

看这个例子:

class User {
   public someProperty: string | undefined;
   // ...

   public get canDoSomething() {
      return this.someProperty != undefined;
   }
}
Run Code Online (Sandbox Code Playgroud)
let myUser: User = ...
Run Code Online (Sandbox Code Playgroud)

这很好用:

if (myUser.someProperty != undefined) {
   // at this point myUser.someProperty is type string only (as it cannot be undefined anymore
}
Run Code Online (Sandbox Code Playgroud)

然而这失败了

if (myUser.canDoSomething) {
   // because typescript still thinks that myUser.someProperty is string | undefined and not just string, even though …
Run Code Online (Sandbox Code Playgroud)

typescript

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

Objective C Type作为参数

好吧,我不是在调用方法或其他东西时问如何获取参数.

我想要这样的东西:

-(void)doSomethingWithType:(TYPE)type {

//do something

}
Run Code Online (Sandbox Code Playgroud)

并执行如下:

[self doSomethingWithType:int];
Run Code Online (Sandbox Code Playgroud)

要么

[self doSomethingWithType:BOOL];
Run Code Online (Sandbox Code Playgroud)

如何创建具有类型作为参数的方法/函数的参数?我的意思是任何类型.. :)

我不想创建一个int参数,我想创建一个int类型参数,在这里您将目标c类型作为参数而不是值或变量:)

谢谢!

objective-c

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

多个 Node JS Express 应用程序的 Nginx 多个位置

我有以下配置:

location / {
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-NginX-Proxy true;
  proxy_pass http://localhost:3000; # this is where our node js app runs at
  proxy_set_header Host $http_host;
  proxy_cache_bypass $http_upgrade;
  proxy_redirect off;
}
Run Code Online (Sandbox Code Playgroud)

哪个代理[SERVER_IP]/localhost:3000以便它基本上将所有内容路由到 node js 应用程序。

然后我继续编写了另一个 nodejs 应用程序,它在 port 上运行5000,而不是3000

location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://localhost:3000; # this is where our node js app runs at
      proxy_set_header Host $http_host;
      proxy_cache_bypass $http_upgrade;
      proxy_redirect …
Run Code Online (Sandbox Code Playgroud)

proxy nginx node.js nginx-location

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

mach_header 64bit 和 __PAGEZERO 段 64bit

const struct mach_header *mach = _dyld_get_image_header(0);
struct load_command *lc;
struct segment_command_64 *sc64;
struct segment_command *sc;

if (mach->magic == MH_MAGIC_64) {
    lc = (struct load_command *)((unsigned char *)mach + sizeof(struct mach_header_64));
    printf("[+] detected 64bit ARM binary in memory.\n");
} else {
    lc = (struct load_command *)((unsigned char *)mach + sizeof(struct mach_header));
    printf("[+] detected 32bit ARM binary in memory.\n");
}

for (int i = 0; i < mach->ncmds; i++) {

    if (lc->cmd == LC_SEGMENT) {
        sc = (struct segment_command *)lc;
        NSLog(@"32Bit: %s …
Run Code Online (Sandbox Code Playgroud)

c c++ objective-c ios

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

UIStackView 等间距包括边缘

我有一个带有 3 个按钮的水平堆栈视图:音乐应用程序的后退、播放、前进。这是我当前的代码:

self.controlStackView.axis = .horizontal
self.controlStackView.distribution = .equalSpacing
self.controlStackView.alignment = .center
self.controlStackView.spacing = 10.0
self.controlStackView.translatesAutoresizingMaskIntoConstraints = false
self.contentView.addSubview(self.controlStackView)

self.controlStackView.topAnchor.constraint(equalTo: self.artworkImageView.bottomAnchor, constant: 10.0).isActive = true
self.controlStackView.centerXAnchor.constraint(equalTo: self.contentView.centerXAnchor).isActive = true
Run Code Online (Sandbox Code Playgroud)

这是做什么的,它按如下方式分布按钮(由于对齐而从中心开始):

[backward] - 10 spacing - [play] - 10 spacing - [forward]

我可以增加间距,但它仍然是固定的。因此,我设置前导和尾随锚点来定义堆栈视图的最大宽度:

self.controlStackView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
self.controlStackView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
Run Code Online (Sandbox Code Playgroud)

这对布局有何影响:

[left edge backward] - lots of spaaaaaaace - [centered play] - lots of spaaaaaaace - [right edge forward]

它分布在整个宽度上(并且中心到左侧和右侧之间有一个 .equalSpacing)。但这也没有帮助。本质上我的目标是拥有真正的相等间距,包括边缘。

假设我的可用宽度为 100,我的 3 个按钮分别为 10、20、10 - 这意味着还有 60 个剩余空间是空的。 …

swift uistackview

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

标签 统计

objective-c ×2

c ×1

c++ ×1

ios ×1

nginx ×1

nginx-location ×1

node.js ×1

proxy ×1

swift ×1

typescript ×1

uistackview ×1