SwiftUI:自动预览更新始终暂停 [英] SwiftUI: Automatic preview updating paused, always

查看:97
本文介绍了SwiftUI:自动预览更新始终暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的应用程序,基本上是一个购物清单应用程序,我正在尝试添加一些甜蜜的 SwiftUI 爱好.

I have an existing App, basically a shopping list app, to which I'm trying to add some sweet sweet SwiftUI lovin.

我的问题是实时预览更新不起作用 - 警告自动预览更新暂停"不断显示.我点击了恢复按钮,它构建了应用程序,它显示了当前视图,然后立即再次显示该警告.如果不使用恢复按钮,我永远无法看到画布中反映的代码更改.

My issue is the real time preview updating doesn't work - the warning "Automatic preview updating paused" continually shows. I hit the resume button, it builds the app, it shows the current view, and that warning immediately shows again. I can never see changes to the code reflected in the canvas without using the resume button.

这发生在 Xcode 11.1 和 11.2 beta 2 中.我在 SO 上几乎找不到其他提及此事,并且在 Apple 的开发论坛上有一个帖子没有答案.

This is happening in Xcode 11.1, and 11.2 beta 2. I can find literally no other mention of this either here on SO, and there's one thread with no answers on Apple's Dev forums.

推荐答案

所有给定答案的问题是如果要使脚本在调试模式下选中或取消选中预览作品.

The problem with all the given answers is that you need to check or uncheck your script in debug mode if you want to make the preview work.

这是使用环境变量的一种方便的替代方法.

Here is a convenient alternative using the environment variables.

这真的很简单

将脚本的所有内容嵌入到 if 语句中,以检查我们是否正在使用预览.如果我们处于预览状态,则不要运行脚本的内容,否则,让我们运行它.而且您不必仅为发布版本而牺牲您的脚本.

Embed all the content of your script in an if statement that check if we're using the preview or not. If we're in preview, then don't run the content of your script, otherwise, let's run it. And you don't have to sacrifice your script for release versions only.

这是模板:

if [ $ENABLE_PREVIEWS == "NO" ]
then
  # your code to execute here
else
  echo "Skipping the script because of preview mode"
fi

下面是我用来修改构建版本号的完整示例

And below a full example that I use to bump my build version number

# xcode-build-bump.sh
# @desc Auto-increment the build number every time the project is run.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
if [ $ENABLE_PREVIEWS == "NO" ]
then
  buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
  buildNumber=$(($buildNumber + 1))
  /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
else
  echo "Skipping Bump of version"
  echo $ENABLE_PREVIEWS
fi

这篇关于SwiftUI:自动预览更新始终暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆