GVKun编程网logo

Swift UI MacOS @已发布nil或Int(swiftui2.0)

2

如果您对SwiftUIMacOS@已发布nil或Int感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于SwiftUIMacOS@已发布nil或Int的详细内容,我们还将为您解

如果您对Swift UI MacOS @已发布nil或Int感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于Swift UI MacOS @已发布nil或Int的详细内容,我们还将为您解答swiftui2.0的相关问题,并且为您提供关于1. docker 在 macOS 中的架构 2. 在 macOS 系统中,docker pull 下来的镜像存储在哪里?、==> 修复 /usr/local/opt/macos-updater/bin/macos-updater 权限从 755 到 444、Appium Inspector 在 macOS 上加载整个屏幕而不是指定的 macOS 应用程序、iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts的有价值信息。

本文目录一览:

Swift UI MacOS @已发布nil或Int(swiftui2.0)

Swift UI MacOS @已发布nil或Int(swiftui2.0)

如何解决Swift UI MacOS @已发布nil或Int

我有以下变量,我希望它以nil作为初始值,然后是Int值。

@Published var status: Int = 0

为了更好地理解,请放置所有参考代码:

struct ServerMessage: Decodable {
    let token: String
}

class Http: ObservableObject {
    @Published var status: Int = 0
    @Published var authenticated = false
    func req(url: String,httpMethod: String,body: [String: String]?) {
        guard let url = URL(string: url) else { return }
        let httpBody = try! JSONSerialization.data(withJSONObject: body ?? [])
        var request = URLRequest(url: url)
        request.httpMethod = httpMethod
        request.httpBody = httpBody
        request.setValue("application/json",forHTTPHeaderField: "Content-Type")
        URLSession.shared.dataTask(with: request) { data,response,error in
            if error != nil {
                print("Error: \\(String(describing: error))")
                return
            }
            
            if let httpResponse = response as? HTTPURLResponse {
                switch httpResponse.statusCode {
                case 400: do {
                    print("Error: 400")
                    dispatchQueue.main.async {
                        self.status = 400
                    }
                    return
                    }
                case 401: do {
                    print("Error: 401")
                    dispatchQueue.main.async {
                        self.status = 401
                    }
                    return
                    }
                default: do {}
                }
            }
            
            do {
                if let data = data {
                    let results = try JSONDecoder().decode(ServerMessage.self,from: data)
                    dispatchQueue.main.async {
                        self.authenticated = true
                    }
                    print("Ok.",results)
                } else {
                    print("No data.")
                }
            } catch {
                print("Error:",error)
            }
        }.resume()
    }
}

使用:

self.http.req(
            url: "",httpMethod: "POST",body: ["email": "","password": ""]
        )

解决方法

将其设为可选(以下所有更正代替了用法)

@Published var status: Int? = nil     // << I like explicit initialising 

更新:View中用法的可能变体

Text("\\(http.status ?? 0)")    // << it is Int,so ?? "" is not valid

但可能更合适(由于没有任何意义显示未知状态字段)

if http.status != nil {
   Text("\\(http.status!)")
}

1. docker 在 macOS 中的架构 2. 在 macOS 系统中,docker pull 下来的镜像存储在哪里?

1. docker 在 macOS 中的架构 2. 在 macOS 系统中,docker pull 下来的镜像存储在哪里?

docker 在 macOS 中的架构:

在 macOS 中,docker 的实现跟在其它 Linux 系统中略有不同,在其它 Linux 系统中,操作系统本身就是 docker 容器的宿主机,docker 镜像都是直接存储在宿主机本身的文件系统中,比如我们通过 docker info 命令可以看到 docker 的根目录是:

$ docker info|grep "Docker Root Dir"
Docker Root Dir: /var/lib/docker

但是在 macOS 下,我们直接查看这个目录,其实是根本不存在的。

$ ls /var/lib/docker
ls: /var/lib/docker: No such file or directory

Docker 宿主机是谁

那么这个目录到底在哪里?实际上是在一个 QEMU 虚拟机中,当我们在 macOS 中安装完 docker 并启动,就是启动了一个虚拟机,这个虚拟机的整个内容全部都在一个文件里,可以在 docker 程序属性界面中看到这个文件的路径,比如在我的机器上,路径就是(<YourUserName> 替换为你的 mac 电脑的用户名)/Users/<YourUserName>/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2,该文件通常比较大,特别是安装了多个 docker 镜像之后,会轻易占用到数十 GB 的空间。 那么,我们是否可以登录这个虚拟机来确认这点呢?使用 macOS 自带的 screen 命令可以登录该台虚拟机。如下,可以看到这是一个拥有非常新的 Linux 4.9.38 版本内核的虚拟机,在这个虚拟机中才有 /var/lib/docker 目录,只有 2 颗 CPU,总共有 2GB 内存。

$ screen /Users/Kamus/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

/ # uname -a
Linux moby 4.9.38-moby #1 SMP Wed Jul 26 10:02:46 UTC 2017 x86_64 Linux
/ # hostname
moby

/ # ls /var/lib/docker
aufs        containers  network     swarm       tmp-old     volumes
builder     image       plugins     tmp         trust

/ # cat /proc/cpuinfo|grep "processor"
processor       : 0
processor       : 1
/ # cat /proc/meminfo |grep "MemTotal"
MemTotal:        2047040 kB

在 screen 的窗口按组合键 control+a d(先按 control+a,再按 d)可以暂时 dettach 出这个 screen,screen -r 可以重新打开窗口。更多的 screen 命令,可以自行 man screen 来查看。 所以现在我们可以明确一个概念,macOS 本身并不是以后将运行的 docker 容器的宿主机,而这个 Linux 虚拟机才是真正的宿主机。这台机器的主机名是 moby,这正是 docker 项目社区版的名称。

Docker 宿主机与 macOS 操作系统的目录共享

由于如下共享文件夹功能的存在,在这个虚拟机中可以访问并更新 macOS 操作系统本地的目录。 我们还是在 screen 中看一下这些共享目录的情况。

/ # df -h|grep osxfs
osxfs                   465.1G    324.1G    140.7G  70% /private
osxfs                   465.1G    324.1G    140.7G  70% /tmp
osxfs                   465.1G    324.1G    140.7G  70% /Volumes
osxfs                   465.1G    324.1G    140.7G  70% /Users
/ # cd /Users
/Users # ls
Guest   Kamus   Shared

可以看到,确实 macOS 操作系统中的目录在虚拟机中是可以直接访问的,而且更方便的地方是,在虚拟机中自动挂载的目录路径跟 macOS 中的路径是完全相同的,比如我的个人主目录无论是在 macOS 中还是在这个虚拟机中,都是 / Users/Kamus。

在 macOS 系统中,docker pull 下来的镜像存储在哪里?

综上所述: 存储在文件 Docker.qcow2 中,该文件在 macOS 系统中位置: /Users/<YourUserName>/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

  • 出处:http://www.dbform.com/html/2017/3705.html

==> 修复 /usr/local/opt/macos-updater/bin/macos-updater 权限从 755 到 444

==> 修复 /usr/local/opt/macos-updater/bin/macos-updater 权限从 755 到 444

如何解决==> 修复 /usr/local/opt/macos-updater/bin/macos-updater 权限从 755 到 444

我创建了一个水龙头 (dindin-glitch/dindin-nibnib-formulae),但是当我安装我制作的公式时,它会输出:

/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/dindin-glitch/homebrew-dindin-nibnib-formulae/Formula/macos-updater.rb
rm /usr/local/bin/macos-updater
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/mas.rb
==> Downloading https://github.com/dindin-glitch/macos-updater/archive/1.0.6.tar.gz
/usr/bin/curl --disable --globoff --show-error --user-agent Homebrew/3.1.8-11-g2e9d4ff\\ \\(Macintosh\\;\\ Intel\\ Mac\\ OS\\ X\\ 11.3.1\\)\\ curl/7.64.1 --header Accept-Language:\\ en --retry 3 --location --silent --head --request GET https://github.com/dindin-glitch/macos-updater/archive/1.0.6.tar.gz
Already downloaded: /Users/odinb/Library/Caches/Homebrew/downloads/445d31097754c50d3754b9e185668794bf954219d0e0026bd02f03b5668ac8ee--macos-updater-1.0.6.tar.gz
==> Verifying checksum for ''445d31097754c50d3754b9e185668794bf954219d0e0026bd02f03b5668ac8ee--macos-updater-1.0.6.tar.gz''
==> Reinstalling dindin-glitch/dindin-nibnib-formulae/macos-updater 
/usr/local/Homebrew/Library/Homebrew/shims/scm/git --version
git config --get homebrew.private
git config --get homebrew.analyticsdisabled
git config --get homebrew.analyticsdisabled
/usr/bin/sandBox-exec -f /private/tmp/homebrew20210519-64449-1pw99l4.sb nice ruby -W1 -- /usr/local/Homebrew/Library/Homebrew/build.rb /usr/local/Homebrew/Library/Taps/dindin-glitch/homebrew-dindin-nibnib-formulae/Formula/macos-updater.rb --verbose --debug
/usr/local/Homebrew/Library/Homebrew/build.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/mas.rb
tar --extract --no-same-owner --file /Users/odinb/Library/Caches/Homebrew/downloads/445d31097754c50d3754b9e185668794bf954219d0e0026bd02f03b5668ac8ee--macos-updater-1.0.6.tar.gz --directory /private/tmp/d20210519-64450-i3w83g
cp -pR /private/tmp/d20210519-64450-i3w83g/macos-updater-1.0.6/. /private/tmp/macos-updater-20210519-64450-77osgr/macos-updater-1.0.6
chmod -Rf +w /private/tmp/d20210519-64450-i3w83g
==> ./configure /usr/local/Cellar/macos-updater/1.0.6/bin
/usr/local/Homebrew/Library/Homebrew/shims/scm/git --version
==> Cleaning
==> Fixing /usr/local/opt/macos-updater/bin/macos-updater permissions from 755 to 444
==> Finishing up
ln -s ../Cellar/macos-updater/1.0.6/bin/macos-updater macos-updater
/usr/bin/sandBox-exec -f /private/tmp/homebrew20210519-64504-87j2fy.sb nice ruby -W1 -I $LOAD_PATH -- /usr/local/Homebrew/Library/Homebrew/postinstall.rb /usr/local/Homebrew/Library/Taps/dindin-glitch/homebrew-dindin-nibnib-formulae/Formula/macos-updater.rb

所以在这里,==> Fixing /usr/local/opt/macos-updater/bin/macos-updater permissions from 755 to 444 行打扰了我,因为当我执行上述公式时,

zsh: permission denied: macos-updater

但是,如果我手动

odinb@MacBook-Pro local % macos-updater
Password:
Password accepted
Starting Brew upgrade
==> Upgrading 1 outdated package:
imagemagick 7.0.11-12_1 -> 7.0.11-13
==> Upgrading imagemagick 7.0.11-12_1 -> 7.0.11-13 
==> Downloading https://ghcr.io/v2/homebrew/core/imagemagick/manifests/7.0.11-13
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/imagemagick/blobs/sha256:9efd64b226e06d71366b336b6fc29e53c3a664f83e697fecafd993f
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:9efd64b226e06d71366b336b6fc29e53c3a664f83e69
######################################################################## 100.0%
==> Pouring imagemagick--7.0.11-13.big_sur.bottle.tar.gz
…

这是我在安装过程中所做的(ruby 文件)

  def install
    bin.install "macos-updater"
    chmod "a+x","./configure"
    system "./configure",bin.to_s
  end

./configure 只是 chmod 755 $1/macos-updater 因为显然它在脚本中效果更好

我想删除 chmod 444 的东西,因为每次我重新安装或更新它时都让我手动 chmod 很烦

效果很好! 那么我怎样才能让它不回到444呢? (如果您想查看 the full ruby file 或 the formula,请点击链接)

Appium Inspector 在 macOS 上加载整个屏幕而不是指定的 macOS 应用程序

Appium Inspector 在 macOS 上加载整个屏幕而不是指定的 macOS 应用程序

如何解决Appium Inspector 在 macOS 上加载整个屏幕而不是指定的 macOS 应用程序

我正在尝试使用 Appium 自动化本机 macOS 应用程序。但是,当我尝试在 Appium Inspector 上加载应用程序时,不是加载指定的应用程序,而是加载了 macOS 的整个屏幕。

以下是我正在传递的功能:

  1. {
  2. "deviceName": "Mac","platformName": "Mac","platformVersion": "11.2","app": "/Applications/Sample.app"
  3. }

如何在 Appium Inspector 中仅加载 Sample.app?

iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>

iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts

如何解决iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>

我不断收到来自随机用户的随机崩溃报告。不幸的是,我无法定期重现这一点。用户说崩溃是在 discussionViewController 中随机发生的。所有崩溃报告都有类似的内容:

0   libswiftCore.dylib              0x00000001a53face4 swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>,unsigned int) + 60 (atomic:1003)
1   libswiftCore.dylib              0x00000001a53c59e0 swift_retain + 124 (RefCount.h:813)
2   libswiftCore.dylib              0x00000001a5401d60 swift_bridgeObjectRetain + 56 (SwiftObject.mm:585)
3   APPNAME                             0x0000000102b59734 closure #1 in discussionViewController.fetchPostData() + 7916

这是完整的崩溃日志和崩溃的线程:

Hardware Model:      iphone11,6
Process:             APPNAME [11770]
Path:                /private/var/containers/Bundle/Application/.../APPNAME.app/APPNAME
Identifier:          ----
Version:             62 (62)
AppStoretools:       12E262
AppVariant:          1:iphone11,6:13
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           ---- [1824]


Date/Time:           2021-06-17 12:07:01.4346 +1000
Launch Time:         2021-06-17 12:06:56.4993 +1000
OS Version:          iPhone OS 14.6 (18F72)
Release Type:        User
Baseband Version:    3.04.01
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x8000000000000010 -> 0x0000000000000010 (possible pointer authentication failure)
VM Region Info: 0x10 is not in any region.  Bytes before following region: 4339515376
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                   102a7c000-102a94000 [   96K] r-x/r-x SM=COW  ...APPNAME.app/APPNAME

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL,Code 0xb
Terminating Process: exc handler [11770]
Triggered by Thread:  3


Thread 3 name:
Thread 3 Crashed:
0   libswiftCore.dylib              0x00000001a53face4 swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>,unsigned int) + 60 (atomic:1003)
1   libswiftCore.dylib              0x00000001a53c59e0 swift_retain + 124 (RefCount.h:813)
2   libswiftCore.dylib              0x00000001a5401d60 swift_bridgeObjectRetain + 56 (SwiftObject.mm:585)
3   APPNAME                             0x0000000102b59734 closure #1 in discussionViewController.fetchPostData() + 7916
4   APPNAME                             0x0000000102ad09d4 thunk for @escaping @callee_guaranteed (@guaranteed Data?,@guaranteed NSURLResponse?,@guaranteed Error?) -> () + 132 (<compiler-generated>:0)
5   CFNetwork                       0x00000001a1b0a3dc __40-[__NSURLSessionLocal taskForClassInfo:]_block_invoke + 540 (LocalSession.mm:687)
6   CFNetwork                       0x00000001a1b1c768 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 244 (LocalSessionTask.mm:584)
7   libdispatch.dylib               0x00000001a10d1a84 _dispatch_call_block_and_release + 32 (init.c:1466)
8   libdispatch.dylib               0x00000001a10d381c _dispatch_client_callout + 20 (object.m:559)
9   libdispatch.dylib               0x00000001a10db004 _dispatch_lane_serial_drain + 620 (inline_internal.h:2557)
10  libdispatch.dylib               0x00000001a10dbc34 _dispatch_lane_invoke + 456 (queue.c:3862)
11  libdispatch.dylib               0x00000001a10e64bc _dispatch_workloop_worker_thread + 764 (queue.c:6589)
12  libsystem_pthread.dylib         0x00000001ed04a7a4 0x1ed047000 + 14244
13  libsystem_pthread.dylib         0x00000001ed05174c 0x1ed047000 + 42828

我已验证 discussionViewController.fetchPostData() 不会强制解开任何可选选项,没有 try! 并且在任何地方都使用 [weak self]self?。该函数非常大,所以我很难缩小崩溃发生的范围。

今天的关于Swift UI MacOS @已发布nil或Intswiftui2.0的分享已经结束,谢谢您的关注,如果想了解更多关于1. docker 在 macOS 中的架构 2. 在 macOS 系统中,docker pull 下来的镜像存储在哪里?、==> 修复 /usr/local/opt/macos-updater/bin/macos-updater 权限从 755 到 444、Appium Inspector 在 macOS 上加载整个屏幕而不是指定的 macOS 应用程序、iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts的相关知识,请在本站进行查询。

本文标签: