[英]How to use Swift literal regex expressions in switch case pattern statements?
如何在 switch case 模式語句中使用 Swift 文字正則表達式? 基於 WWDC 2022 演示幻燈片中的示例,以下內容有望編譯並運行正常:import Foundation import RegexBuilder switch "abc" { case /\w+/: ...
[英]How to use Swift literal regex expressions in switch case pattern statements?
如何在 switch case 模式語句中使用 Swift 文字正則表達式? 基於 WWDC 2022 演示幻燈片中的示例,以下內容有望編譯並運行正常:import Foundation import RegexBuilder switch "abc" { case /\w+/: ...
[英]Type any Protocol cannot conform to Protocol
我在嘗試初始化 SwiftUI 中的視圖時遇到問題。讓我解釋一下: 我有一個名為 ExternalView 的視圖,該視圖具有一個名為 ToggleableProtocol 的協議的約束,然后,該視圖在內部使用一個名為 InternalView 的視圖,該視圖具有對 Hashable 協議的約束。 ...
[英]how to write a function that takes coordinate(lat - long) and take snapshot from desired location with lookaround.snapshotter in Swift?
我剛開始在 Swift 編程,我是一個完全的初學者。 我想寫一個 function 或 class,通過接收坐標,如果 MKLookAround.request 中有照片,使用 MKLookAround.Snapshotter 保存所需位置的照片,但我不知道如何使用 mapkit 就緒類. 我不想 ...
[英]read local text file content get Nil in swift
我想從 swift 中的一個文本文件中讀取內容,我所做的步驟是 go 到終端並讀取/創建文件 go 到 Xcode,文件 -> 添加文件到我的項目和 select 將 test_this 文件添加到項目中使用以下代碼讀取內容。 但是,在打印出文件、路徑和文本之后。 文本為零。 文件和路徑看起 ...
[英]SwiftUI with associated ViewModel Type can't be initialised from its hosting ViewController with Swift 5.7
我正在定義一個具有關聯 ViewModel 協議類型的 SwiftUI 視圖。 但是,在構建Type 'any MyViewModelType' cannot conform to 'MyViewModelType'時出現此錯誤。 這是我的完整代碼。 我不確定我做錯了什么? 另外,我不知道為什么 ...
[英]Compile error "Sendability of function types in instance method 'someMethod' does not match requirement in protocol 'SomeProtocol'" iOS 16 Swift 5.7
更新到 Xcode 14、iOS 16、Swift 5.7 后,在編譯項目時我得到: ...
[英]How to capture more than 10 things using Swift 5.7's RegexBuilder?
假設我有一個存儲有關人員信息的文件,其中一行如下所示: 從左到右依次為姓名、年齡、出生日期、出生國家、出生城市、子女數量、結婚日期(可選)、妻子姓名(可選)、前妻姓名(可選)、喜歡的食物、最不喜歡的食物。 我想使用 Swift 5.7 RegexBuilder 模塊從行中獲取所有信息,我嘗試過: ...
[英]any Identifiable can't conform to 'Identifiable'
更新:添加關於 Hashable 的相同錯誤我創建了一個可Identifiable的兼容協議和兼容結構。 然后,當我創建列表並在ForEach中引用它時,我收到錯誤Type 'any TestProtocol' cannot conform to 'Identifiable' (我收到關於Hash ...
[英]SwiftUI and Swift 5.7: Issue with View protocol and Opaque Types
當我嘗試從方法返回符合 View 協議的不同自定義視圖時出現編譯錯誤。 這是一個描述該問題的簡單示例。 我希望有一個方法可以根據枚舉情況返回不同的自定義視圖。 當我嘗試實現這一目標時,我得到不同的編譯錯誤: getSomeView方法拋出以下編譯錯誤: Function 聲明了一個不透明的返回類型 ...
[英]How do I pass data from a variable in a view to a view model class
我的數據包含在一個名為selectedFolderId的變量中,這樣做的目的是我想將此變量中的數據傳遞到 class 中,這樣我可以在ShoppingListItemsView加載的任何時候從 Firestore 中讀取我的數據庫內容。 如果他們能解釋並告訴我如何將這些數據從我的ShoppingL ...
[英]Type 'any View' cannot conform to 'View' when initiating UIHostingViewController with different View conformances
我真的很喜歡 Swift 類型系統。 但我無法理解為什么我不能這樣做: 很明顯,這兩個視圖都是 View 協議的正確一致性,所以let view: View應該滿足UIHostingController<Content>: UIViewController where Content: ...
[英]iOS16+ Present UIViewController in landscape only for single screen not working [Swift 5.7]
在 iOS 之前 16 橫向呈現單個屏幕適合縱向應用。 工作代碼如下。 備注:整個應用程序僅處於縱向模式。 我找到了解決方案,但它適用於UIWindowScene ,但我需要 UIWindow 中的解決方案。 我需要幫助在 iOS 16 中修復它。 Xcode - 14.0, iOS - 16. ...
[英]How to add custom value in charts for bottom label in swift iOS
我必須使用 swift iOS 在圖表中顯示帶有美元符號的 [0, 25, 50, 75, 100] 在視圖中添加了 didLoad 我想顯示 0 $25 $50 $75 $100 而不是 0 10 20 30 40 50 ...
[英]How to get character from Unicode in correct way when UnicodeScalars are not working?
過去幾天我搜索了答案,其中很多都非常舊(swift 2 和 1.2 左右)。 當從變量中獲取 unicode 代碼時,我想獲取字符。 因為由於某些未知原因,構造在 Swift 中不起作用: 人們建議使用 UnicodeScalars。 但是 Apple 必須在 Swift 5 中引入一些新的東西。 ...
[英]Cannot specialize protocol type
Swift5.7 帶有主要關聯類型。 我嘗試使用這些代碼,但出現錯誤:無法專門化協議類型'GenericDelegate' class BaseResponse {} class ConcreteResponse: BaseResponse {} protocol GenericDelegate ...
[英]Sheet wont dismiss if item changed while animating
我正在運行 XCode Beta 14.0 beta 3 盡管我認為這不是問題所在。 我有一個應用程序,它具有基於名為 Engine 的動態庫中的 AVCaptureSession 的自定義回調。 下面列出的枚舉/協議: 在我的前端,當我第一次初始化 AVCaptureSession 並且代表被調用 ...
[英]Protocol '...' as a type cannot conform to '...' - A generic protocol of a generic protocol issue
我一直在玩 Swift 和 SwiftUI。 我一直在嘗試為各種“數據實體”提出基於委托的數據存儲,目的是能夠在保持代碼接口穩定的同時替換底層數據存儲實現(這是一個實驗性代碼庫,所以我想隨着時間的推移使用不同的數據存儲) 經過幾次嘗試后,我得出的結論是,大部分頂層工作都在重復(我最終基本上會應付粘 ...