下载Mapbox示例,运行pod install,报错:403 Forbidden,为什么?请帮忙,谢谢!
\npod \'Mapbox-iOS-SDK\', \'~> 6.3.0\'
\n\n\n\xe2\x9e\x9c ios-sdk-examples-298e050be7352eb28cee6f03e02945593140c1f3 pod\ninstall 分析依赖项 下载依赖项 安装\nMapbox-iOS-SDK 6.3.0
\n[!] 安装 Mapbox-iOS-SDK 时出错 [!] /usr/bin/curl -f -L -o\n/var/folders/84/rnxy4n6d32g03yxywry6hlnx0l2qqr/T/d20210316-90167-1gkenam/file.zip\n https ://api.mapbox.com/downloads/v2/mobile-maps/releases/ios/packages/6.3.0/mapbox-ios-sdk-dynamic.zip \n--create-dirs --netrc-可选 --重试2 -A \'CocoaPods/1.10.0 cocoapods-downloader/1.4.0\'
\n% 总计 % 已接收 % Xferd 平均速度 时间 时间 时间\n当前\nDload 上传总花费左速度 0 0 0 0 0 0 0 0 --:--:-- --:--:--\n--:- -:-- 0 curl: (22) 请求的 URL 返回错误:403 Forbidden
\n
machine api.mapbox.com\n login xxx\n password xxx <sk.eyJ1IjoiY2hpYnVkb25nIiwiYSI6ImNrbWJlN2RhNzIwcTEyb210ZTRtbXM2MDAifQ.DkqGccMXylJmAG9G6OSfYg>\nRun Code Online (Sandbox Code Playgroud)\n 我有一个 Swift 图表,可以在线条标记和条形标记之间切换。我已在每个标记的顶部添加注释以显示每个数据点的值。在条形图上,注释显示正确。但是,折线图上仅显示第一个注释。这是一个错误还是设计使然?
这是我用来在条形标记上显示注释的代码:
BarMark (
x: PlottableValue.value("Date", "\(day.name) \(day.date)") ,
y: PlottableValue.value("Miles", lookupDict[day] ?? 0)
)
.annotation {
if let miles = lookupDict[day] {
Text(verbatim: "\(miles)")
.font(.caption)
} else {
EmptyView()
}
}
Run Code Online (Sandbox Code Playgroud)
我在线条标记上使用了相同的注释修饰符块,但无法理解为什么它不能以相同的方式工作。
chartForegroundStyleScale在 Swift Charts 中,为每个数据系列设置 ShapeStyle 的签名是:
func chartForegroundStyleScale<DataValue, S>(_ mapping: KeyValuePairs<DataValue, S>) -> some View where DataValue : Plottable, S : ShapeStyle
Run Code Online (Sandbox Code Playgroud)
初始化程序KeyValuePairs( init(dictionaryLiteral: (Key, Value)...)) 仅采用可变参数,因此任何从数组初始化前景样式的尝试(在我的例子中<String, Color>)都会导致错误:
Cannot pass array of type '[(String, Color)]' as variadic arguments of type '(String, Color)'
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,图表系列的名称是根据数据动态设置的,因此尽管我可以生成[String : Color]字典或元组数组,(String, Color)但我看不到可以将其中任何一个传递到chartForegroundStyleScale? 除非我遗漏了一些东西,否则这似乎是 Swift 图表中的一个奇怪的限制,即系列名称需要为此修饰符进行硬编码?
我觉得这是一个已经在某个地方被问过的问题,但我找不到太多相关内容。
当使用变量来更新 UI 时,我们何时/为什么要@State在视图中使用而不是使用@Published在 ViewModel 中使用?
这是我试图掌握 MVVM 架构的背景。我总体上理解这种差异,只是当涉及到两者都可以轻松以相同方式完成的事情时。
下面,我有 2 个示例执行相同的操作,但其中一个使用ViewModel,而@State另一个则使用@PublishedViewModel。一种方法是否比另一种更好(用于更新 UI 目的?)
@State例子:
struct MyView: View {
@State var backgroundIsRed = false
var body: some View {
ZStack {
if backgroundIsRed {
Color.red
} else {
Color.green
}
}
.onTapGesture { backgroundIsRed.toggle() }
}
}
Run Code Online (Sandbox Code Playgroud)
@Published例子:
class ViewModel: ObservableObject {
@Published var backgroundIsRed = false
}
struct MyView: View {
@StateObject var viewModel = ViewModel()
var body: some …Run Code Online (Sandbox Code Playgroud) 我正在尝试禁用 swiftUI 中的 Picker 选项。根据下面的文档,代码应该可以工作:
struct ContentView: View {
let options = ["All", "Men", "Women", ]
@State private var selectedOption = "All"
var body: some View {
Picker("Options", selection: $selectedOption) {
ForEach(options, id: \.self) { option in
Text(option)
.disabled(option == "All")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,它在我出错的地方不起作用。有人可以帮忙吗!?
我按照本教程向我的 SwiftUI 应用程序添加了一个简单的共享表。它在 iPhone 上运行正常,但在 iPad 上崩溃并出现以下错误:
由于未捕获的异常“NSGenericException”而终止应用程序,原因:“UIPopoverPresentationController(<UIPopoverPresentationController:0x107d95ee0>)应该在演示发生之前设置非零的sourceView或barButtonItem。”
有什么办法可以解决这个错误吗?不太确定这里发生了什么。
我正在使用新的快速图表框架来显示一些数据。为了手动控制 x 轴 AxisValueLabels 的频率以及调整颜色,我实现了以下内容:
.chartXAxis {
AxisMarks(values: .automatic(desiredCount: 11, roundLowerBound: true, roundUpperBound: true)) { _ in
AxisGridLine(stroke: .init(lineWidth: 1)).foregroundStyle(Color.orange)
AxisValueLabel().foregroundStyle(Color.orange).font(.subheadline).offset(x: -10)
}
}
Run Code Online (Sandbox Code Playgroud)
我想显示每个 x 轴值的值(有 11 个点,但仅显示 10 个)。我已经尝试了无数的方法,但无法通过调整desiredCount参数来显示它应该显示的内容。将不胜感激在这件事上的任何帮助..
import Charts
import Foundation
import SwiftUI
struct FakeData: Codable {
var questionAndAnswers: [Int: Int]
var timePerQuestion: [Double]
var date: Date = .now
}
extension FakeData {
static let oneFakeInstance = FakeData(questionAndAnswers: [1875: 1875,
1890: 1890,
1980: 1980,
2112: 2112,
2726: 2726,
4088: 4088,
4284: 4284,
4784: 4784,
4800: 4800, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码获取用户运营商名称:
CTTelephonyNetworkInfo* info = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier* carrier = info.subscriberCellularProvider;
NSString *mobileCountryCode = carrier.mobileCountryCode;
NSString *carrierName = carrier.carrierName;
NSString *isoCountryCode = carrier.isoCountryCode;
NSString *mobileNetworkCode = carrier.mobileNetworkCode;
Run Code Online (Sandbox Code Playgroud)
但是当我尝试记录时,结果是这样的:
2023-05-22 16:47:39.831078+0700 MotionTrade[7686:985518] carrier name = --
2023-05-22 16:47:39.831260+0700 MotionTrade[7686:985518] mobileCountryCode = 65535
2023-05-22 16:47:39.831342+0700 MotionTrade[7686:985518] mobileNetworkCode = 65535
Run Code Online (Sandbox Code Playgroud)
基本上我已经尝试了每个堆栈溢出答案,但我仍然得到相同的结果,
我在我的iPhone上调试这个,没有使用WiFi,而且我只使用物理SIM卡,而不是电子SIM卡。
谁能告诉我为什么我总是收到“--”?
在我浏览了一下之后,国家代码“65535”这可能表明 SIM 卡已被移除,或者通常目前无法拨打电话。
谁能帮我?为什么会发生这种情况以及如何获得正确的蜂窝提供商名称?
我什至尝试使用以下代码在我的新空白项目中执行此操作:
override func viewDidLoad() {
super.viewDidLoad()
let networkInfo = CTTelephonyNetworkInfo()
let carrierName = networkInfo.serviceSubscriberCellularProviders
dump(carrierName)
}
Run Code Online (Sandbox Code Playgroud)
但我的日志中仍然得到相同的结果:
Optional(["0000000100000001": CTCarrier (0x281275d10) {
Carrier name: [--]
Mobile Country …Run Code Online (Sandbox Code Playgroud) 我正在尝试在基于 SwiftData 的 SwiftUI 项目中使用多个视图。但是,当我在另一个视图中为 SwiftData @Model 对象创建参数时,当我在 #Preview 中创建该对象的示例时,编译器开始抱怨未在 @Model 对象中实现协议。
Xcode 15 测试版 2
我从一个新的 iOS SwiftData 项目开始。我像这样更新了 ContentView:
import SwiftUI
import SwiftData
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Query private var items: [Item]
@State private var selection: Item?
var body: some View {
NavigationSplitView {
List(selection: $selection) {
ForEach(items) { item in
Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
}
.onDelete(perform: deleteItems)
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(action: addItem) {
Label("Add …Run Code Online (Sandbox Code Playgroud) swiftui ×7
swift ×4
ios ×2
cocoapods ×1
mapbox-ios ×1
mvvm ×1
objective-c ×1
sprite-kit ×1
swift-data ×1
xcasset ×1
xcode ×1