刚刚升级到 Xcode 13.3 beta 3(从 Xcode 13.2.1)并运行swift package init. 它生成了一个弃用警告,我以前没有见过这个:
warning: Usage of /Users/sajjon/Library/org.swift.swiftpm/collections.json has been deprecated. Please delete it and use the new /Users/sajjon/Library/org.swift.swiftpm/configuration/collections.json instead.\nRun Code Online (Sandbox Code Playgroud)\n但我不知道如何“使用新的......代替”?事实上我什至不知道它是如何或何时org.swift.swiftpm/collections.json创建的。
该怎么办?
\n完整打印:
\n~/Developer/DeleteMe \xe2\x8c\x9a 13:57:37\n$ swift package init\n2022-02-25 13:57:42.211 xcodebuild[54679:13318505] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore\n2022-02-25 13:57:42.212 xcodebuild[54679:13318505] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of …Run Code Online (Sandbox Code Playgroud) 我正在运行OS X El Capitan并使用Xcode 8 GM种子(8A218a),我正在尝试使用iOS 10 GM种子10.01(14A403)在我的iPhone 6上运行我的应用程序,它与运行watchOS 3的Apple Watch配对转基因种子(14S326).
我使用Match来处理配置文件和证书,到目前为止它一直工作得非常好.
我最近更改了包标识符,因此在成员中心创建了一个新的App Id并重新配置了匹配等.我在Mac上安装了开发证书和配置文件.我删除了旧证书和旧配置文件.
一切都在模拟器上运行良好.但是当我尝试在我的iPhone Xcode 8上运行它时显示错误:
供应配置文件"匹配开发com.XXX.YYY"不包括当前选定的设备"ZZZ的Apple Watch".
它还显示了另一个错误:
SDK"iOS 10.0"中的产品类型"应用"需要代码签名
我没有此应用程序的Apple Watch扩展程序.那么为什么Xcode 8会给我带来与Apple Watch有关的错误?
另外第二个错误是什么意思?SDK"iOS 10.0"中的产品类型"应用"需要代码签名吗?
谢谢!!
当我在 NavigationView 中按“后退”按钮时使用Xcode 12 beta (12A6159)on macOS Catalina 10.15.5 (19F101),从推送的视图中导航回来,我在控制台中看到了这个警告。
[UIContextMenuInteraction] 未处于活动状态时,正在尝试 -[UIContextMenuInteraction expireMenu]。这是一个客户端错误,最常见的原因是在给定的生命周期内多次调用解除。(<_UIVariableGestureContextMenuInteraction: 0x6000037689a0>)
我在 Xcode 11.5 上没有收到此警告。
代码非常简单:
var body: some View {
NavigationView {
NavigationLink(destination: gameScreen) {
Text("Start game")
}
}
}
Run Code Online (Sandbox Code Playgroud)
在导航到gameScreen然后按导航栏中的“返回”按钮后,我在控制台中看到了记录的警告。
我还没有升级到任何新SwiftUI东西像App或SceneBuilder等...
使用Xcode 11 beta 6,我试图为具有使用属性的类型声明一个协议@Published(但我猜这个问题可以推广到任何PropertyWrapper)。
final class DefaultWelcomeViewModel: WelcomeViewModel & ObservableObject {
@Published var hasAgreedToTermsAndConditions = false
}
Run Code Online (Sandbox Code Playgroud)
我试图声明:
protocol WelcomeViewModel {
@Published var hasAgreedToTermsAndConditions: Bool { get }
}
Run Code Online (Sandbox Code Playgroud)
这导致编译错误: Property 'hasAgreedToTermsAndConditions' declared inside a protocol cannot have a wrapper
所以我试着把它改成:
protocol WelcomeViewModel {
var hasAgreedToTermsAndConditions: Published<Bool> { get }
}
Run Code Online (Sandbox Code Playgroud)
并尝试
哪个不编译,DefaultWelcomeViewModel does not conform to protocol好吧,嗯,那我用不了,Published<Bool>试试吧!
struct WelcomeScreen<ViewModel> where ViewModel: WelcomeViewModel & ObservableObject {
@EnvironmentObject private var viewModel: …Run Code Online (Sandbox Code Playgroud) 我想知道什么是最好的做法,当我想要一些功能公开,一些内部使用协议时我.
我写的AudioManager在斯威夫特3包装AVPlayer作为一个框架.
我想要一些方法是公共的,所以例如使用AudioManager的ViewController可以访问一些方法,但是一些方法不会暴露在框架之外
- >即使用访问修饰符internal而不是public.
我正在用协议驱动设计编写框架,几乎每个部分都应该有一个协议.
因此协议正在与框架内的协议进行通信.
例如,主类 - AudioManager有一个AudioPlayer,并且应该能够internal在其上调用一些函数,
例如,pause(reason:)但该方法应该internal在框架之外暴露.
这是一个例子.
internal enum PauseReason {
case byUser
case routeChange
}
// Compilation error: `Public protocol cannot refine an internal protocol`
public protocol AudioPlayerProtocol: InternalAudioPlayerProtocol {
func pause() // I want
}
internal protocol InternalAudioPlayerProtocol {
func pause(reason: PauseReason) // Should only be accessible within the framework
}
public class AudioPlayer: …Run Code Online (Sandbox Code Playgroud) 使用 Xcode beta 6 和 SwiftUI,Text使用>localized<字符串创建视图,如何在不必将本地化字符串值大写的情况下将其大写?我想我想要一个ViewModifier改变案例,但它似乎不存在?
Text("SignIn.Body.Instruction".uppercased())将大写本地化键,因此将不起作用,如有关大写非本地化字符串的SO问题中所述。
我希望能够使用数组文字实例化一个子类,这里MyLabel是一个子类,它是一个子类UILabel.我在我的框架ViewComposer中使用它,它允许使用枚举视图的数组来创建UIViews,如下所示:
let label: UILabel = [.text("Hello World"), .textColor(.red)]
Run Code Online (Sandbox Code Playgroud)
在这个问题中,我大大简化了用例,而是允许编写:
let vanilla: UILabel = [1, 2, 3, 4] // works!
print(vanilla.text!) // prints: "Sum: 10"
Run Code Online (Sandbox Code Playgroud)
我想要做的是使用相同的ExpressibleByArrayLiteral语法,但使用的是被UILabel调用的子类MyLabel.但是当我尝试时,编译器会阻止我:
let custom: MyLabel = [1, 2, 3, 4] // Compilation error: "Could not cast value of type 'UILabel' to 'MyLabel'"
Run Code Online (Sandbox Code Playgroud)
UILabel由于符合Makeable以下自定义协议,使用数组文字的实例化可行.
是否有可能使编译器理解我指的是子类的数组文字初始值设定项MyLabel而不是它的超类UILabel?
以下代码可能没有任何逻辑意义,但它是一个最小的例子,隐藏了我真正想要的东西:
// This protocol has been REALLY simplified, in fact …Run Code Online (Sandbox Code Playgroud) 使用 Xcode 11 beta 6,在 SwiftUI 应用程序项目中,使用 Swift Package Manager (SPM),如何更改“包产品”的选择,而不删除包并重新添加它?是否可以
我包含了Kingfisher包,它具有 SPM 支持。确认了 git 分支后xcode11,SPM/Xcode 发现 Kingfisher 包含两个“Package Product”,起初我只选择了第一个,但没有选择“KingfisherSwiftUI”。然后我意识到我也需要它。
我搜索再次提示此对话框的任何方法,但没有找到。因此,我删除了该包并重新添加了它。而且似乎没有缓存,Xcode 必须重新下载并构建项目,这需要一些时间。
是否可以从父项目继承自定义配置?不,不要求继承一些目标设置.
在Xcode每个项目都被初始化为两种标准配置叫Debug和Release.DEBUG使用Preprocessor Macros目标的构建设置中的显示名称下的设置(在.pbxproj此称为GCC_PREPROCESSOR_DEFINITIONS)中设置标志是一种非常常见的模式,可以从这样的Objective-C代码中读取.
#ifdef DEBUG
print("DEBUG flag set")
#else
print("No debug flag!")
#endif
Run Code Online (Sandbox Code Playgroud)
这也适用于Swift,但是我们必须使用OTHER_SWIFT_FLAGS并声明它:
-D DEBUG
并且像我们在上面的Objective C代码中那样读取变量值.
我的应用程序包含一个带有主项目的xcworkspace和几个依赖项目.让我们调用我的应用依赖于框架的项目.由于我有几个框架,我不想多次设置构建设置.
因此我正在使用xcconfig文件.我有一个主配置,即主项目的配置文件,我们称之为Main.xcconfig.我有另一个配置文件Framework.xcconfig,从行开始#include "Main.xcconfig",从而继承设置Main.当然,我设置每个框架来使用所述Framework.xcconfig文件.
DEBUG在我们有这些配置文件时声明标志非常方便,Main.xcconfig我们添加:
OTHER_SWIFT_FLAGS[config=Debug] = -D DEBUG
GCC_PREPROCESSOR_DEFINITIONS[config=Debug] = DEBUG
Run Code Online (Sandbox Code Playgroud)
因此声明主项目和框架项目DEBUG的配置 标志Debug(因为Framework.xcconfig继承自Main.xcconfig …
这个简单的TextField可能是聊天功能的一部分,我希望能够在按下键盘按钮“发送”时发送聊天消息。
(想象一下,在此聊天中,我不需要通过覆盖返回键来允许用户输入换行符,以使用视图修饰符发送submitLabel(.send)。)
TextField(
"Chat...",
text: $draft
)
.submitLabel(.send)
.onSubmit {
if !draft.isEmpty {
sendMessage(draft: draft)
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这会隐藏键盘,我想知道:
有什么办法可以防止按下时键盘隐藏send?
我知道如何重新聚焦该字段,我可以做到这一点,@FocusState但这仍然会导致隐藏键盘动画开始,然后中止,所以看起来很光滑。