I have a M2, 13" MacBook Pro
import Cocoa
import IOKit
import Foundation
var blob = IOPSCopyPowerSourcesInfo() // cannot find 'IOPSCopyPowerSourcesInfo' in scope
Post
Replies
Boosts
Views
Activity
Can I export a SwiftUI Color / UIKitUIColor / AppKit NSColor to a .clr file? How?
Bonus: Can I transfer them to each other?
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
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'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.
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?
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 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'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.
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.
just curious about it
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
]
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?