I have this:
struct TableRow: View {
@Binding var data: TodoItem
var body: some View {
...
}
}
and this:
List {
ForEach(data) { datum in
TableRow(data: ???) // <- what goes here?
.swipeActions {
Button(role: .destructive) {
data.delete(datum)
} label: {
Label("Delete", systemImage: "trash")
}
}
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I want to change a binding value to just a normal one. How?
Feedback is filed. Trying to look into the Core.swift.
diagnostics:
Unsupported: 'Consumer for unconverted(_StringProcessing.DSLTree._AST.Atom(ast:
----------------------------------------
CrashReportError: Fatal Error in Core.swift
UtilityScript crashed due to fatalError in Core.swift at line 77.
'try!' expression unexpectedly raised an error: Unsupported: 'Consumer for unconverted(_StringProcessing.DSLTree._AST.Atom(ast:
))'
Process: UtilityScript[3141]
Date/Time: 2022-07-02 03:56:17 +0000
Log File: <none>
Application Specific Information:
dyld [
dyld config: DYLD_LIBRARY_PATH=/Users/wangkeshijian/Library/Developer/Xcode/DerivedData/UtilityScript-frovasvohxblobefzbrrwtvqtyuu/Build/Intermediates.noindex/Previews/UtilityScript/Products/Debug DYLD_FRAMEWORK_PATH=/Users/wangkeshijian/Library/Developer/Xcode/DerivedData/UtilityScript-frovasvohxblobefzbrrwtvqtyuu/Build/Intermediates.noindex/Previews/UtilityScript/Products/Debug
]
libswiftCore.dylib [
_StringProcessing/Core.swift:77: Fatal error: 'try!' expression unexpectedly raised an error: Unsupported: 'Consumer for unconverted(_StringProcessing.DSLTree._AST.Atom(ast:
))'
/AppleInternal/Library/BuildRoots/0cc5e7ad-e86f-11ec-ac50-3e2aa58faa6a/Library/Caches/com.apple.xbs/Sources/swiftlang_overlay_Platform/swift-experimental-string-processing/Sources/_StringProcessing/ConsumerInterface.swift:200
]
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Debugging
Xcode Previews
wwdc2022-110357
wwdc2022-110358
macOS Ventura 13 beta 2
I'm coming over with a really strange issue with my cursor. It'd move toward the right-down by itself one pixel a time: right down right down
It really freaked me out *laugh*
I'll try attaching a video. FB submitted.
I've just bought a M2 MacBook Pro, and my Timer app is giving me strange crash logs.
Here's my code:
struct ContentView: View {
@State var process: Any? = nil
@AppStorage("time") var time = 0
@State var timePassed = 0
@State var timer: Timer.TimerPublisher = Timer.publish(every: 1, on: .main, in: .common)
@State var cacheSecondsString: String = String(UserDefaults.standard.integer(forKey: "time"))
@State var startTheTimer: Bool = false
var body: some View {
ZStack {
TimerView(time: $timePassed, total: $time).padding()
VStack {
TextField("Time...", text: $cacheSecondsString)
.font(.system(size: 35, weight: .light, design: .rounded))
.multilineTextAlignment(.center)
.onSubmit {
time = Int(cacheSecondsString) ?? time
cacheSecondsString = String(time)
}
.textFieldStyle(.plain)
.padding()
.fixedSize()
Button {
withAnimation {
startTheTimer.toggle()
}
} label: {
Label(startTheTimer ? "Stop" : "Start", systemImage: startTheTimer "stop.fill" : "clock").foregroundColor(.accentColor)
}.buttonStyle(.plain).padding()
}
}.onChange(of: startTheTimer) { start in
if start {
process = timer.connect()
} else {
(process! as! Cancellable).cancel()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewDevice("iPad Air (5th generation)")
}
}
When I sort of "run" the preview (pressing on the play.circle button on top of my preview and press the button the second to deactivate my timer, a crash dialog appear, the standard one macOS uses when any process crashed, but the preview didn't crash.
I tried to implement ExpressibleByIntegerLiteral to my code and it has been terrible.
At last, it asked me to implement this init
// Cannot find type 'Builtin' in scope
init(_builtinIntegerLiteral value: Builtin.IntLiteral) {
}
I have a M2, 13" MacBook Pro
import Cocoa
import IOKit
import Foundation
var blob = IOPSCopyPowerSourcesInfo() // cannot find 'IOPSCopyPowerSourcesInfo' in scope
I want to get battery level, estimated remaining time, battery health...etc via IOPSCopyPowerSourcesList
Not sure how
I'm not experienced with pointers...
func updateBatteryView() {
let battery = IOPSCopyPowerSourcesInfo().takeRetainedValue()
let info = IOPSCopyPowerSourcesList(battery).takeRetainedValue()
// Now what?
}
I'm trying to get the password of the current user's wifi. I'm trying the Security framework mentioned by @eskimo here, but it's not working. I'm trying the CLI command
public func getPassword(ssid: String) -> String? {
let command = "security find-generic-password -l \"\(ssid)\" -D 'AirPort network password' -w"
let result = shell(command)
return result
}
private func shell(_ command: String, lauchPath: String = "/bin/zsh") -> String? {
let task = Process()
let pipe = Pipe()
task.standardOutput = pipe
task.standardError = pipe
task.arguments = ["-c", command]
task.launchPath = "/bin/zsh"
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)?
.trimmingCharacters(in: .newlines)
return output
}
I'm now trying AppKit so I declared:
@IBOutlet var passwordLabel: NSTextField!
var password: String?
var wifi: String?
...
// applicationDidFinishLaunching(_ aNotification:)
wifi = CWWiFiClient.shared().interface()?.ssid()
....
password = getPassword(ssid: wifi ?? "Unknown")
passwordLabel.stringValue = password ?? "ERROR"
in applicationDidFinishLaunching(_ aNotification:)
it worked.
Note: on my dialog, there's only Deny and Allow, not Deny, Allow Once, Always Allow
I added a refresh button next to the password label and it won't work when I press the button:
@IBAction func RefreshPassword(_ sender: NSButton) {
wifi = CWWiFiClient.shared().interface()?.ssid()
password = getPassword(ssid: wifi)
print(password)
if let i = wifi {
DeviceWiFiLabel.stringValue = i
DeviceWiFiLabel.textColor = .systemGreen
passwordLabel.textColor = .textColor
} else {
DeviceWiFiLabel.stringValue = "None"
DeviceWiFiLabel.textColor = .systemOrange
passwordLabel.textColor = .red
}
passwordLabel.stringValue = password ?? "ERROR"
}
The dialog still pops open but I can't enter text when the textfield is focused, that is, no text appears when I hit a key when textfield focused. When I dismiss using the "Deny" button, sometimes a message like these appears in the console:
2022-08-24 05:21:24.034479+0800 MyApp[22457:564086] Detected potentially harmful notification post rate of <some sort of float-point number that always changes and about 300) notifications per second
I can't always reproduce the issue.
Any idea why?
I'm trying to get the memory usage of the entire system.
// referance: https://www.jb51.cc/iOS/590624.html
public func memsize() -> UInt64 {
var taskInfo = mach_task_basic_info()
var count = UInt32(MemoryLayout<mach_task_basic_info>.size)
let kerr: kern_return_t = withUnsafeMutablePointer(to: &taskInfo) {
$0.withMemoryRebound(to: integer_t.self,capacity: 1) {
task_info(mach_task_self_,task_flavor_t(MACH_TASK_BASIC_INFO),$0,&count)
}
}
if kerr == KERN_SUCCESS {
return taskInfo.resident_size
}
return 0
}
not working, apparently. When my system uses 15 GB it shows it's below 1 GB.
Do anyone have other ways to get memory usage of the device (better macOS)
// I have a object "CentralProcesser". I can get the user and system usage of the CPU. I want to get the total.
let system: Double = CentralProcesser.current.usage.system // 10.8746757975 or something like that
let user: Double = CentralProcesser.current.usage.user // 23.24123412424 or something like that
// And now I add them together, right?
let total: Double = system + user // nan
Why?
I wrote an app that users can create utilities using terminal commands
I'm experiencing a bug that's driving me crazy:
I have an array of utilities, and by extension, I made Array<Utility> and Utility RawRepresantable:
Part of the declaration for Utility
public init?(rawValue: String) {
guard let data = rawValue.data(using: .utf8),
let result = try? JSONDecoder().decode(Utility.self, from: data)
else { return nil }
self = result
}
public var rawValue: String {
var encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
guard let data = try? encoder.encode(self),
let result = String(data: data, encoding: .utf8)
else {
return ""
}
return result
}
extension for Array<Utility>
extension Array: RawRepresentable where Element: Codable {
public init?(rawValue: String) {
guard let data = rawValue.data(using: .utf8),
let result = try? JSONDecoder().decode([Element].self, from: data)
else { return nil }
self = result
}
public var rawValue: String {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
guard let data = try? encoder.encode(self),
let result = String(data: data, encoding: .utf8)
else {
return "[]"
}
return result
}
}
And now, because of some strange SwiftUI bug (FB11401294) When I pass a binding down a view hierarchy such as List or ForEach they update weirdly. I implement an "edit" feature for my utilities so I will not directly use binding but to call a function that takes an inout of Array<Utility>, the original item, and the item after being edited:
func replace(_ sequence: inout [Utility], item: Utility, with replace: Utility) {
var raw = sequence.rawValue
print(raw)
let rawReplaced = raw.replacingOccurrences(of: item.rawValue, with: replace.rawValue)
print(item.rawValue, replace.rawValue)
print(rawReplaced)
sequence = [Utility].init(rawValue: sequence.rawValue.replacingOccurrences(of: item.rawValue, with: replace.rawValue))!
print(sequence)
}
And the problem is it works
and after implementing another completely different feature it stopped working
from my debugging, the input of the function is correct and the problem is inside the function. But, as the error seems to be on this line:
sequence = [Utility].init(rawValue: sequence.rawValue.replacingOccurrences(of: item.rawValue, with: replace.rawValue))!
Now i have completely no idea why this works last time and won't now
This line of code works completely well in playgrounds and is now freaking me out
Help anyone?
I'm tired of opening up safari to open developer.apple.com so I'm trying to embed the website into an app, but sth is definitely wrong. It's been loading for ten mins and is still white. here's the code
import SwiftUI
import WebKit
import UIKit
struct WebViewPage : UIViewRepresentable {
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ uiView: WKWebView, context: Context) {
let req = URLRequest(url: URL(string:"developer.apple.com")!)
uiView.load(req)
}
}
#if DEBUG
struct WebViewPage_Previews : PreviewProvider {
static var previews: some View {
WebViewPage()
}
}
#endif
app delegate:
import SwiftUI
@main
struct Developer_WebpageApp: App {
var body: some Scene {
WindowGroup {
WebViewPage()
}
}
}