在HealthKit工作,我有一系列的HealthKit锻炼,我需要组织到月份和年份(这样我就可以显示2018年1月,2018年2月等的锻炼).让我感到困难的是我首先需要检查一个月和一年是否有锻炼,如果不是我需要为它创建阵列,如果我需要附加到现有阵列.我也不确定最好的数据模型,我正在考虑使用[[Month:Year]]但是看起来不是很Swifty?
guard let workoutsUnwrapped = workouts else { return }
for workout in workoutsUnwrapped {
let calendar = Calendar.current
let year = calendar.component(.year, from: workout.startDate)
let month = calendar.component(.month, from: workout.startDate)
}
Run Code Online (Sandbox Code Playgroud) 这个问题以前曾被问过,但没有一个解决方案有效。我不敢相信,在 SwiftUI 中,@Environment(\.sizeCategory) var sizeCategory没有类似的环境变量可供我们观察和打开吗?
该链接讨论了如何在iPhone上获取崩溃报告,但是我一经获得Analytics(分析)数据就不清楚(1)我正在查看的内容,(2)我正试图追查最近的原因。 Apple Watch应用程序崩溃时,如何找到此信息?
我正在尝试向UIView用作 a 的背景(backgroundRect)的 a添加渐变UITableViewCell。我希望渐变在与 backgroundRect 相同的 Z 位置绘制,但是在设备上构建时,它会遮挡(在顶部)我的标签和其他视图。但令人困惑的是,当我使用 ViewDebugger 时,它显示我的视图,好像它们应该出现在它们后面的渐变层?
class NewWorkoutTableViewCell: UITableViewCell {
@IBOutlet weak var backgroundRect: UIView!
@IBOutlet weak var dayOfTheWeekLabel: UILabel!
@IBOutlet weak var sessionTypeLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var sessionTypeImage: UIImageView!
@IBOutlet weak var scoreLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
backgroundRect.layer.cornerRadius = 8.0
backgroundRect.layer.shadowColor = UIColor.black.cgColor
backgroundRect.layer.shadowOpacity = 0.5
backgroundRect.layer.shadowOffset = CGSize(width: 5, height: 5)
backgroundRect.layer.shadowRadius = 5
// this is making a CoreAnimation gradient layer
let …Run Code Online (Sandbox Code Playgroud) 我dyld: Symbol not found: _OBJC_CLASS_$_CLKFullColorImageProvider在 watchOS 4 中遇到这个错误,但在 watchOS 5 中没有,我相信它与我下面的复杂代码有关,但不知道为什么......据我所知编译器不应该CLKFullColorImageProvider像我一样寻找已经阻止了if #available(watchOSApplicationExtension 5.0, *)
class Complication: NSObject, CLKComplicationDataSource {
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
if #available(watchOSApplicationExtension 5.0, *) {
if complication.family == .circularSmall {
let template = CLKComplicationTemplateCircularSmallRingImage()
guard let image = UIImage(named: "Circular") else { handler(nil); return}
template.imageProvider = CLKImageProvider(onePieceImage: image)
let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
handler(timelineEntry)
} else if complication.family == .utilitarianSmall {
let template …Run Code Online (Sandbox Code Playgroud) 如果有人有任何使用Swift使用Parse的经验,特别是子类化PFObject .....我无法弄清楚为什么下面的saveinbackground调用会抛出上述错误?
谢谢!
func saveNewPerson(name: String) {
var myPeeps = [Person]()
if let currentUser = PFUser.currentUser() {
if currentUser.valueForKey("myPeeps")?.count < 1 {
myPeeps = []
} else {
myPeeps = currentUser.valueForKey("myPeeps") as! [Person]
}
let newPerson = Person(name: name, stores: [:])
myPeeps.append(newPerson)
currentUser.setObject(myPeeps, forKey: "myPeeps")
println(currentUser.valueForKey("myPeeps")?.count)
//WHY DOES THIS SAVE THROW ERROR FOR NOT INITIALZING?
currentUser.saveInBackgroundWithBlock{ succeeded, error in
if succeeded {
//3
println("Saved")
} else {
//4
if let errorMessage = error?.userInfo?["error"] as? String {
self.showErrorView(error!)
}
}
} …Run Code Online (Sandbox Code Playgroud) 我刚刚看到它WKExtension.shared.EnableWaterLock现在已被弃用。我在我的锻炼应用程序中使用了这种方法来防止意外点击屏幕和结束锻炼等。它是否已被任何其他锁定屏幕的方法所取代?