标签: xcode

从真实设备下载 watchOS 应用程序容器

有没有办法为在真实设备上运行的 watchOS 应用程序下载应用程序容器?

PS:对于iOS应用程序,可以使用Xcode设备和模拟器窗口,但仅列出iOS应用程序,无法检查Apple Watch上安装的应用程序。

xcode ios watchkit watchos

7
推荐指数
0
解决办法
165
查看次数

SwiftUI ForEach 未更新 ObservableObject 类数组的更改

背景

在我的应用程序中,我有一系列可以从另一个视图添加的朋友。我已将这组朋友存储在一个类中,该类是ObservableObject. 在我的主视图中FriendListView,我使用ForEach为用户添加的每个朋友显示自定义视图。

我无法添加到数组并让列表显示新项目。根据我能够理解和组合的内容,我尝试了两种不同的尝试。如果有人能够提供任何帮助,我们将不胜感激。我目前有显示第二个视图的方法,我将在其中添加注释掉的新朋友,并且有一种自动保存新朋友的方法作为导航栏项目存在。

尝试

尝试#1

如果在类初始值设定项期间将朋友列表附加到数组中,我就成功地显示了朋友列表。调用类方法从另一个视图添加到数组似乎是可行的,因为我能够打印数组的内容,但 UI 不会更新。

这是通过使用一种ForEach(0..<Array.count)方法完成的,但在添加新项目后我收到以下控制台错误。

错误

ForEach<Range<Int>, Int, HStack<TupleView<(Spacer, FriendView, Spacer)>>> count (4) != its initial count (3).
`ForEach(_:content:)` should only be used for *constant* data.
Instead conform data to `Identifiable` or use `ForEach(_:id:content:)` and provide an explicit `id`!
Run Code Online (Sandbox Code Playgroud)

型号代码

ForEach<Range<Int>, Int, HStack<TupleView<(Spacer, FriendView, Spacer)>>> count (4) != its initial count (3).
`ForEach(_:content:)` should only be used for *constant* data.
Instead conform data to `Identifiable` or use …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift swiftui observableobject

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

如何防止 Xcode 的重新缩进(Control + i)功能滚动到底部?

编写一些代码后,我通常选择所有行,然后点击Control+ i

这会重新缩进代码,但会令人烦恼地一直滚动到底部。

有没有办法阻止 Xcode 向下滚动,以便我可以保留滚动位置?

xcode xcode11

7
推荐指数
0
解决办法
77
查看次数

如何使用 SwiftUI 消除嵌套 NavigationView 中的空间

我目前正在开发一个使用 SwiftUI 的 iOS 项目。我有 3 个页面(MainMenu、CalendarList 和 DateDetails。)

在第二页(CalenderList)上,屏幕顶部和实际的 NavigationBarTitle 之间有一个空白区域。

第二页的图像 - 日历列表

在第三页上,您可以看到后退按钮(返回主菜单),并且顶部有两个空白区域。

第 3 页的图片 - 日期详细信息

我见过人们使用 .navigationBarHidden 来解决这个问题,但我无法以解决问题的方式实现它。

我是否错误地使用了 NavigationView() ?或者有什么特殊的技巧吗?

这是主菜单的代码:

import SwiftUI

struct MainMenu: View {
    var body: some View {
        NavigationView {
            VStack {
                Text("Calendar")
                    .font(.largeTitle)
                    .fontWeight(.heavy)
                    .foregroundColor(Color(red: 0.055, green: 0.173, blue: 0.322))
                    .padding(.top, 55.0)
                Text("Main Menu")
                    .font(.headline)
                    .foregroundColor(Color(red: 0.635, green: 0.635, blue: 0.635, opacity: 1.0))
                
                /*Image("Logo")
                    .resizable()
                    .frame(width: 150.0, height: 150.0)*/

                Spacer()
                
                HStack {
                    NavigationLink(destination: CalendarList()) {
                        Image(systemName: "calendar")
                            .resizable()
                            .frame(width: 75.0, height: 75.0)
                            .padding()
                            
                            
                    } …
Run Code Online (Sandbox Code Playgroud)

xcode swiftui ios-navigationview

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

SwiftUI 日期格式

我从 Github 获取此内容:\n https://github.com/emilioschepis/techfeed \n当我启动应用程序时,我在控制台中遇到问题:\n无法转换“2011 年 8 月 3 日星期三 09:44:00 + 0200”至今。\n并且我有一个黑屏。

\n

我 \xc2\xb4m 使用最新的 xCode 版本并更新代码。\n感谢您的回答....\n截屏

\n

解析器:

\n
import Foundation\n\nclass ReleasesParser: NSObject {\ntypealias CompletionResult = ([Release]) -> Void\n\nprivate static var formatter: DateFormatter = {\n    let formatter = DateFormatter()\n    formatter.dateFormat = "E, dd MMM yyyy HH:mm:ss z"\n    return formatter\n}()\n\nprivate var releases = [Release]()\nprivate var currentElement = ""\nprivate var currentGuid = ""\nprivate var currentTitle = ""\nprivate var currentDescription = ""\nprivate var currentPubDate = ""\nprivate var completion: CompletionResult?\n\nfunc parse(data: …
Run Code Online (Sandbox Code Playgroud)

xcode date formatter ios swiftui

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

尝试重命名变量时,Xcode 11.5 重命名重构失败

当我尝试重命名任何变量时,Xcode 给出以下错误:

我尝试过重新启动 Xcode,但还是发生了同样的事情。有什么想法如何修复吗?

xcode swift xcode11 xcode11.5

7
推荐指数
2
解决办法
2425
查看次数

如何将颜色选择器值保存到 SwiftUI 中的 UserDefaults 中?

我分配了一组颜色,希望将其保存到 UserDefaults 中。我有默认的灰色、绿色、橙色和红色,但我想允许颜色选择器更改绿色、橙色和红色。默认值在我的模拟器中有效并显示,但是当我尝试更改数组中的颜色时,出现错误“尝试插入非属性列表对象(\n“50% 灰色”、\n 绿色、\n ” kCGColorSpaceModelRGB 0.647194 0.881984 0.980039 1 “,\n 红色\n) 用于关键 SavedColors。” 我相信这是因为颜色选择器试图插入不同类型的颜色?看起来它可能正在尝试插入 CGColor 或 CGColorSpace ?

这是我的项目代码:

import SwiftUI
import Foundation
import Combine

class UserSettings: ObservableObject {
    @Published var colors: [Color] {
        didSet {
            UserDefaults.standard.set(colors, forKey: "SavedColors")
        }
    }
    init() {
        self.colors = UserDefaults.standard.object(forKey: "SavedColors") as? [Color] ?? [Color.gray.opacity(0.5), Color.green, Color.orange, Color.red]
    }
}

struct CustomizeView: View {
    @ObservedObject var savedColors = UserSettings()
    var body: some View {
        NavigationView {
            Form {
                if #available(iOS 14.0, *) …
Run Code Online (Sandbox Code Playgroud)

xcode swift userdefaults swiftui observableobject

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

“BackgroundModes” - 系统功能未列在 iOS 项目的“project.pbxproj”文件中

我正在尝试Background fetch使用 Workmanager 插件将该功能集成到 Flutter 项目中。因此,我background fetch在 iOS 项目功能的“后台模式”下启用了该功能。但以下块未添加到project.pbxproj文件中。据我了解,它应该是由XCode自动添加的。

SystemCapabilities = {
                            com.apple.BackgroundModes = {
                                enabled = 1;
                            };
                        };
Run Code Online (Sandbox Code Playgroud)

目前,我正在使用 Xcode 11.3.1 和 Swift 5.0。那么如何将上面的代码片段引入到project.pbxproj 文件中呢?或者如果我的理解有误,请帮助我。

xcode ios flutter

7
推荐指数
0
解决办法
730
查看次数

使用未声明的标识符“FIRApp”

导入 Firebase.h 文件后,我在“- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions”上写了“[FIRApp configure]”。在模拟器上运行时,它显示“使用未声明的标识符‘FIRApp’”。但如果选择“通用 iOS 设备”选项进行构建,则不会出现错误。构建和存档工作正常。但在本地模拟器上问题即将到来。我必须首先在模拟器上运行该应用程序,以便与 Firebase 服务器进行崩溃通信。请给我解决方案。输入

xcode objective-c ios cocoapods firebase

7
推荐指数
2
解决办法
8601
查看次数

体系结构 x86_64 的未定义符号:“_OBJC_CLASS_$_GeneratePluginRegistrant”

我正在开发 Flutter 应用程序并收到此错误。我尝试过flutter clean删除rm podfilepodfile.lock pod deintegrate,但似乎没有修复。

Xcode中完整的错误信息如下:

体系结构 x86_64 的未定义符号:“ OBJC_CLASS $_GeneratePluginRegistrant”,引用自:AppDelegate.o ld 中的 objc-class-ref:未找到体系结构 x86_64 clang:错误:链接器命令失败,退出代码 1(使用 -v查看调用)

xcode flutter

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