多年来,这个问题已经被问过很多次了,但它在 Swift 5 中再次发生了变化,尤其是在最近的两个测试版中。
读取 JSON 文件似乎很简单:
func readJSONFileData(_ fileName: String) -> Array<Dictionary<String, Any>> {
var resultArr: Array<Dictionary<String, Any>> = []
if let url = Bundle.main.url(forResource: "file", withExtension: "json") {
if let data = try? Data(contentsOf: url) {
print("Data raw: ", data)
if let json = try? (JSONSerialization.jsonObject(with: data, options: []) as! NSArray) {
print("JSON: ", json)
if let arr = json as? Array<Any> {
print("Array: ", arr)
resultArr = arr.map { $0 as! Dictionary<String, Any> …Run Code Online (Sandbox Code Playgroud) 在 Xcode 11 beta 5 或 6 中,我现有的依赖于URLSession.DataTaskPublisher停止工作的代码。似乎DataTaskPublisher永远不会发布任何值,但我不知道为什么。
我已经尝试过.sink并.handleEvents作为订阅者。我已经与Just发布者一起测试了 .sink并确认它在那里收到了一个值。
我也试过给DataTaskPublisheraURL和给它 a URLRequest。我尝试了对 API 的请求,包括授权标头,以及对 google.com 和 apple.com 的基本请求。我尝试使用URLSession.shared和创建URLSession. 我也试过使用和不使用mapanddecode运算符。
我已经使用XCTest期望来确认测试每次都会超时,即使我给它 4 分钟的超时。
我刚刚创建了一个新的示例项目,并在根视图控制器中使用以下代码复制了问题:
override func viewDidLoad() {
super.viewDidLoad()
print("view did load")
URLSession.shared.dataTaskPublisher(for: URL(string: "http://apple.com")!)
.handleEvents(receiveSubscription: { (sub) in
print(sub)
}, receiveOutput: { (response) in
print(response)
}, receiveCompletion: { (completion) in
print(completion)
}, receiveCancel: { …Run Code Online (Sandbox Code Playgroud) 19A536g(6?)在我的 SwiftUI 应用程序中,我有一个带有列表的简单视图。在列表下方,我有一个按钮可以将项目添加到列表中。
添加一些项目后,新添加的项目不可见,因为它们超出了列表的内容大小。
var body: some View {
NavigationView {
VStack {
List(self.accounts) { account in
Text("\(account.name)")
}
Button("Add new account") {
self.addNewAccount()
}
}.navigationBarTitle("Select account")
}
}
Run Code Online (Sandbox Code Playgroud)
我想我想要一些绑定列表的内容偏移量,传递给我的方法addNewAccount并触发列表的滚动。
创建 Xcode Playground 时,受支持的 playgroundSharedDataDirectory 无法正确显示我的预期目录。
预期:~/Documents/Shared Playground Data
实际:file:///var/folders/46/zg_mg07d5h5_9t6q_4vr9_2w0000gn/T/com.apple.dt.Xcode.pg/containers/com.apple.dt.playground.stub.iOS_Simulator.MyPlayground-BEF6F13E-9994E- -7DE953069D69/Documents/Shared%20Playground%20Data/
import UIKit
import PlaygroundSupport
print(playgroundSharedDataDirectory)
Run Code Online (Sandbox Code Playgroud)
这也不会链接到目录。如果我将文件放在正确的目录中,则无法读取它。如果我将它放在目录中,它确实可以工作,但是每次加载 Playground 时它都会改变。
Xcode 10.3,也出现在 Xcode 11 中。这在 10.2 中有效
最近更新到 Xcode 11 GM 种子 2 ( 11A420a) 并且我在模拟器上运行我的应用程序时(iPhone Xs Max(可能不相关))弹出一个对话框,询问访问我的 iCloud 的权限。
为什么?苹果没有提供任何理由说明为什么感觉奇怪?
“SimulatorTrampoline.xpc”想要访问“iCloud Drive”管理的文件。
我实际上接受了......因为我不希望我的模拟器出现任何奇怪的错误行为。
但是有点讽刺的是,Apple 强迫我们,开发人员,提供理由(向我们的应用程序的用户显示)为什么我们想要访问用户的相机,但在这里 Apple 没有提供任何理由文本......
升级xcode11后,发现应用加载器被取消了。现在如何将ipa包上传到appstore,有没有替代的应用加载器工具?
去年我们从 Pixate 迁移到了 StylingKit
https://github.com/StylingKit/StylingKit是 Pixate 的一个分支,据我所知仍在开发中。
然而,随着 XCode 11 的发布,我们现在遇到了问题,在 pior 版本中它运行良好,但现在无法编译。
void* callSuper0(id self, Class superClass, SEL _cmd)
{
struct objc_super super;
super.receiver = (__bridge void *)self;
super.class = superClass != NULL ? superClass : class_getSuperclass(object_getClass(self));
return objc_msgSendSuper(&super, preprocessSEL(_cmd));
}
Run Code Online (Sandbox Code Playgroud)
return objc_msgSendSuper(&super, preprocessSEL(_cmd));
Run Code Online (Sandbox Code Playgroud)
抛出错误“函数调用的参数太多,预期为 0,有 2”
我尝试更改一些构建设置,如函数调用的参数过多,预期为 0,有 3 个特别是“启用对 objc_msgSend 调用的严格检查为 NO”,但它没有帮助。
任何帮助,将不胜感激。
我一直在尝试将 SwiftUI 应用程序中的状态栏设置为浅色文本,因为它具有深色背景。
我在几个网站上找到了这个解决方案,但无法让它工作。
HostingController.swift
import Foundation
import UIKit
import SwiftUI
class HostingController : UIHostingController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
Run Code Online (Sandbox Code Playgroud)
这将在类声明行返回错误,Reference to generic type 'UIHostingController' requires arguments in <...>并建议修复Insert '<<#Content: View#>>'. 应用所述修复会导致错误Use of undeclared type '<#Content: View#>'
然后,您是为了改变window.rootViewController中SceneDelegate.swift的文件。
SceneDelegate.swift
...
// Create the SwiftUI view that provides the window contents.
let contentView = Login()
// Use a UIHostingController as window root view controller.
if let windowScene …Run Code Online (Sandbox Code Playgroud) 如何List使用 Swift UI删除空行这是我的代码。
struct LandMarkList: View {
var body: some View {
NavigationView {
List(LandMarkListData) { landmark in
LandMarkRow(landmark: landmark)
}
.navigationBarTitle("List")
}
}
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个奇怪的视觉错误,它仅适用于从 Xcode 11 版本运行的 iOS 13。我有一个嵌入在导航控制器中的表格视图,默认色调颜色设置为我的应用程序的主要橙色。在 iOS12 上,当您取消搜索操作时,您会看到一个后退按钮,该按钮遵循主要橙色的全局导航控制器色调。这是预期的行为。如下图所示:
但是,同样的代码在iOS13中产生了一个系统默认的蓝色后退箭头,如下图:
我已经尝试了一切来尝试覆盖那个蓝色的后退按钮,包括使用自定义操作创建一个自定义的 Bar Button Item,但这太混乱了,我只想简单地覆盖色调颜色。我已经尝试了很明显的searchController.searchBar.tintColor = UIColor(named:"Primary")searchController 是我的 UISearchController,并且我试图覆盖 self.navigationController 色调颜色。我试过本机访问 SearchBar,如下所示:UISearchBar.appearance().tintColor = UIColor(named:"Primary"),但仍然没有运气。我已经在 IB 中尝试了我能想到的所有其他方法,但我无法弄清楚如何达到这个后退按钮的色调。有人可以帮忙吗?