I know this is a strange and easy question.
but JUST CANT FIND ANY REFERENCE aaaaaaaa
I'm using SwiftUI and wants to
export to PDF (best I can find Creating PDFs on MacOS without UIKit)
export to image
export to HTML
export to everything possible etc
BONUS print the page
I can only find UIKit support and they are all outdated. AND IF POSSIBLE how to integrate ShareLink to share these(PDF, Image, HTML, etc) and write them onto disk using NSSavePane?
even better
how to do this on a of the platforms
(I know I'm greedy😂)
Thanks for any help🙏
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have a structure TodoItem
struct TodoItem: Codable, Hashable, Identifiable {
var id: UUID = UUID()
var item: String
var done: Bool = false
}
And I have an array of them, and I’d like to find out a way to calculate(in a array) how many are done; that is, myArray.count / itemsDone
.count is easy, itemsDone can be achieved like this:
extension Array where Element == TodoItem {
var itemsDone: Double {
var done: Double = 0
for i in self {
if i.done { done += 1 }
}
return done
}
}
but it didn’t.
struct ContentView: View {
@State var todos: [TodoItem]
…
ProgressView(value: todos.itemsDone / todos.count) // Error
My Playground won’t let me copy the error(no idea why) and my family’s iPad is in Chinese so one is Chinese. I’ll try it on Xcode and see if I can find out more. will update with the error.
EDiT
nor will this work:
ProgressView(value: todos.itemsDone, total: todos.count)
⬆️
(for a bug fix on counting a array’s proportion of models that contains a certain value)
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")
}
}
}
}
How can I achieve a source code editor in SwiftUI like Xcode, highlighting all the keywords and things like that. I've tried Regex + AttributedString... To hard... Anyone has any idea?
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.
Because of some problems I turn again to Monterey
in this thread, @ekimo says that to use ad hoc you need to archive a iOS App
however:
what did I did wrong?
I had registered a seat in the online Shanghai App Accelerator lecture about Swift Charts, tomorrow in the morning
I just found out that I had a class at the same time... Can I cancel my registration?
I've restarted my ColorProposer app and renamed it Chroma and the app suggests a color for a string. My main function is here:
import Foundation
import NaturalLanguage
import CoreML
func predict(for string: String) -> SingleColor? {
var model: MLModel
var predictor: NLModel
do {
model = try ChromaClassifier(configuration: .init()).model
} catch {
print("NIL MDL")
return ni
}
do {
predictor = try NLModel(mlModel: model)
} catch {
print("NIL PREDICT")
return nil
}
let colorKeys = predictor.predictedLabelHypotheses(for: string, maximumCount: 1) // set the maximumCount to 1...7
print(colorKeys)
var color: SingleColor = .init(red: 0, green: 0, blue: 0)
for i in colorKeys {
coor.morphing((ColorKeys.init(rawValue: i.key) ?? .white).toColor().percentage(of: i.value))
print(color)
}
return color
}
extension SingleColor {
mutating func morphing(_ color: SingleColor) {
self.blue += color.blue
self.green += color.green
self.red += color.red
}
func percentage(of percentage: Double) -> SingleColor {
return .init(red: slf.red * percentage, green: self.green * percentage, blue: self.blue * percentage)
}
}
struct SingleColor: Codable, Hashable, Identifiable {
var id: UUID {
get {
return .init()
}
}
var red: Double
var green: Double
var blue: Double
var color: Color {
get {
return Color(red: red / 255, green: green / 255, blue: blue / 255)
}
}
}
enum ColorKeys: String, CaseIterable {
case red = "RED"
case orange = "ORG"
case yellow = "YLW"
case green = "GRN"
case mint = "MNT"
case blue = "BLU"
case violet = "VLT"
case white = "WHT"
}
extension ColorKeys {
func toColor() -> SingleColor {
print(self)
switch self {
case .red:
return .init(red: 255, green: 0, blue: 0)
case .orange:
return .init(red: 255, green: 125, blue: 0)
case .yellow:
return .init(red: 255, green: 255, blue: 0)
case .green:
return .init(red: 0, green: 255, blue: 0)
case .mint:
return .init(red: 0, green: 255, blue: 255)
case .blue:
return .init(red: 0, green: 0, blue: 255)
case .violet:
return .init(red: 255, green: 0, blue: 255)
case .white:
return .init(red: 255, green: 255, blue: 255)
}
}
}
here's my view, quite simple:
import SwiftUI
import Combine
struct ContentView: View {
@AppStorage("Text") var text: String = ""
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
@State var color: Color? = .white
var body: some View {
TextField("Text...", text: $text).padding().background(color).onReceive(timer) { _ in
color = predict(for: text)?.color
print(color)
}
}
}
But the problem of not updating the view still persists. In prints, I discovered a really strange issue: The line of
print(colorKeys)
is always the same.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Debugging
Machine Learning
Core ML
Create ML
OK I'm trying to make a sprite(model.Emmiter) that shoots balls(EnergyBalls) and the balls wont emit at the touch location:
import SpriteKit
import GameplayKit
class Sprites {
var Emmiter: SKSpriteNode = .init(imageNamed: "Emmiter")
}
class GameScene: SKScene {
var model: Sprites = .init()
var Emmiter = Sprites().Emmiter
var playableRect: CGRect = .zer
var lastTouch: CGPoint = .zero
override func didMove(to view: SKView) {
Emmiter.position = CGPoint(x: size.width / 2, y: size.width/* view.frame.minY + 100 */)
print(Emmiter.position)
self.addChild(Emmiter)
}
func touchDown(atPoint pos : CGPoint) {
lastTouch = pos
let rotation = -atan2(
lastTouch.x - Emmiter.position.x,
lastTouch.y - Emmiter.position.y
)
Emmiter.run(
.rotate(
toAngle: rotation,
duration: 0.25
)
)
fireEnergyBall(atPoint: lastTouch)
}
func touchMoved(toPoint pos : CGPoint) {
}
func touchUp(atPoint pos : CGPoint) {
}
func fireEnergyBall(atPoint location: CGPoint) {
let EnergyBall = SKSpriteNode(imageNamed: "Energy")
EnergyBall.position = Emmiter.position
print(EnergyBall.position)
let fly: SKAction = .run {
EnergyBall.run(.move(to: location, duration: 1))
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
EnergyBall.un(.sequence([.scale(to: 0, duration: 0.125), .removeFromParent()]))
}
}
EnergyBall.run(fly)
self.addChild(EnergyBall)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let rotation = -atan2(
touches.first!.location(
in: self
).x - Emmiter.position.x,
touches.first!.location(
in: self
).y - Emmiter.position.y
)
Emmiter.run(
.rotate(
toAngle: rotation,
duration: 0.25
)
)
fireEnergyBall(atPoint: touches.first!.location(in: self.view))
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func update(_ currentTime: TimeInterval) {
}
}
I'm trying to make an app that will let the user put their phone down for a moment. How can I keep the phone locked in the same interface for a certain amount of time, no matter what method the user uses? I've seen lots of apps doing that. (I'm using SwiftUI)
PS Sorry can't think of an appropriate tag