Post

Replies

Boosts

Views

Activity

Reply to Missing Fundamental something
I understand about multiple issues. I'll try to keep them separate in the future. Thanks. You looked into this pretty deeply, and it reminds me of a mathematicians proof. They can be more litigious than lawyers, and necessarily so. I didn't submit my case well. I just find it curious that if you run the min/max code on ranges =[ 1...4 ,0...0 ,1...6 ,3...5 ,0...0 ,2...4 ,3...7 ] you get a min=1 and max=7, and that is what I expect when looking at the data. But now swap the first and second entries so that: ranges = [ 0...0 ,1...4 ,1...6 ,3...5 ,0...0 ,2...4 ,3...7 ] the result is min=0 and max=0 It is the same data, just rearranged. The results are dramatically different. The reason for it still eludes me. Filtering is a good way to go. Thanks.
Topic: Media Technologies SubTopic: Audio Tags:
Oct ’21
Reply to Delegation in Swift
Sorry, robnotyou, I should have posted the link: https://developer.apple.com/forums/thread/694710 to my previous post where Claude31 contributed heavily. In it Clause31 creates example program with a progressBar within the VC class and thus progressBar.doubleValue is recognized. But in my actual app "remote func" is not in the VC class nor any other class but is just in a separate file, alone, by itself at 800 lines of code. I don't want to fatten my already bloated VC file. The remote function runs many iterations thus the need for a progress indicator. A delegate (if I understand correctly) will update the progressBar.doubleValue even though the delegate itself is changed in the remote func. I hope that is clearer. I may be asking for something that can't be done. I have dabbled in SwiftUI and what I am asking for in Swift is something analogous to an EnvironmentVariable update scheme, i.e., when the other file changes a value it is reflected in the VC. wherever it is needed.
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to FYI: Playing a movie using AVPlayer in Big Sur
Belated follow-up to my own question. The following code works, and is not much different than that already posted. So my problem must have been in the storyboard. import AVKit // macOS & iOS class ViewController_myProduction: NSViewController { @IBOutlet var myMOV: AVPlayerView! override func viewDidLoad() { super.viewDidLoad() let playerView = AVPlayerView() playerView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(playerView) if #available(macOS 11.0, *) { playerView.leadingAnchor.constraint (equalTo: view.safeAreaLayoutGuide.leadingAnchor ).isActive = true playerView.trailingAnchor.constraint (equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true playerView.topAnchor.constraint (equalTo: view.safeAreaLayoutGuide.topAnchor ).isActive = true playerView.bottomAnchor.constraint (equalTo: view.safeAreaLayoutGuide.bottomAnchor ).isActive = true } else { // Fallback on earlier versions } playerView.controlsStyle = .floating playerView.showsFrameSteppingButtons = true playerView.showsFullScreenToggleButton = true guard let path = Bundle.main.url(forResource: "myProduction", withExtension: "mov") else { return } let player = AVPlayer(url: path) playerView.player = player playerView.player?.play() } } note to self: code-block + Edit:"Paste and Match Style"
Jan ’22
Reply to format printed SIMD3's
I am working a new tac. I use my existing Double extension I call EE() on each of the elements of a simd_double3, which obviously has three double elements. I've abandoned SIMD3 with its scalars. so: extension simd_double3 { func EE_simd_double3(_ sigDig: Int?,_ toSize: Int?,_ padChar: String?) -> String { return "(\((self.x).EE(sigDig,toSize,padChar)), \((self.y).EE(sigDig,toSize,padChar)), \((self.z).EE(sigDig,toSize,padChar)))" } } extension Double { func EE(_ sigDig: Int?,_ toSize: Int?,_ padChar: String?) -> String { let formatter = NumberFormatter() formatter.numberStyle = .scientific formatter.positivePrefix = "+" formatter.maximumIntegerDigits = 1 formatter.usesSignificantDigits = true formatter.minimumSignificantDigits = sigDig ?? 4 formatter.maximumSignificantDigits = sigDig ?? 5 return formatter.string(from: self as NSNumber)!.pad(padWithString: padChar ?? " ", toSize: toSize ?? 16, prefix: false) //.padding(toLength: padTo ?? 26, withPad: padChar ?? " ", startingAt: stringNum.count) } } My remaining problems are how to include the plus sign after the E in scientific nation, e.g., -4.516611095E1 -> -4.516611095E+1 and to specify the number of digits after E, e.g., -4.516611095E1 -> -4.516611095E+01
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to format printed SIMD3's
extension String { func pad(padWithString: String, toSize: Int, prefix: Bool) -> String { var padChar = " " if toSize >= self.count { for _ in 0..<(toSize - self.count) { padChar = padWithString + padChar } } if prefix { return padChar + self } else { return self + padChar } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to EnvironmentObject as progressValue in ProgressView()
Thought you might say that Claude31. The original is too large so I created this example code... import SwiftUI import Combine class model: ObservableObject { @Published var t_step : Double @Published var progressValue : Double init (progressValue: Double){ self.t_step = 0.0 self.progressValue = 0.0 } func stepThroughTime() { let start = 110.0 let end = 234.0 while t_step < end { progressValue = (end - t_step)/(end - start) t_step += 1 } } } struct ContentView: View { @EnvironmentObject var model: model var body: some View { VStack { Button( action: { model.stepThroughTime() } ) { Text("Search") } ProgressView(value: model.progressValue) // NOT A @STATE var... so doesn't work } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’22
Reply to Developing command line Metal compute apps?
FYI. Updated for Xcode 13.3.1 ... let bufferLength = N * MemoryLayout<Float>.size let devices = MTLCopyAllDevices() print("\(#file):\(#line) Possible devices: \(devices)") let device = devices[0] print("\(#file):\(#line) Running compute application on device \(device.name)") print("\(#file):\(#line) Adding vectorA and vectorB into vectorC. Each vector is \(N) floats") let commandQueue = device.makeCommandQueue() let defaultLibrary = device.makeDefaultLibrary() let commandBuffer = commandQueue!.makeCommandBuffer() let kernel = defaultLibrary!.makeFunction(name: "add_kernel") let computePipeLineDescriptor = MTLComputePipelineDescriptor() computePipeLineDescriptor.computeFunction = kernel let computePipelineState = try! await device.makeComputePipelineState(descriptor: computePipeLineDescriptor, options: [] ) // Set up thread groups to be used in commandEncoder let thrdWidth = 3 // FOUND NO REPLACEMENT FOR: computePipelineState.threadExecutionWidth, SO USED INTEGER let thrdsPerGroup = MTLSize(width:thrdWidth,height:1,depth:1) let numThrdgroups = MTLSize(width:(N+thrdWidth)/thrdWidth, height:1, depth:1) // Create input and output vectors, and corresponding metal buffers var vectorA = Array(repeating: Float(0.0), count: N) for (index, _) in vectorA.enumerated() { vectorA[index] = Float(index) } var vectorB = Array(repeating: Float(0.0), count: N) for (index, _) in vectorB.enumerated() { vectorB[index] = Float(index * 2) } var vectorC = Array(repeating: Float(0.0), count: N) let bufferA = device.makeBuffer(bytes: vectorA, length: bufferLength, options: []) let bufferB = device.makeBuffer(bytes: vectorB, length: bufferLength, options: []) let bufferC = device.makeBuffer(bytes: vectorC, length: bufferLength, options: []) // Create Compute Command Encoder and add buffers and thread groups let computeCommandEncoder = commandBuffer!.makeComputeCommandEncoder() computeCommandEncoder!.setBuffer(bufferA, offset: 0, index: 0) computeCommandEncoder!.setBuffer(bufferB, offset: 0, index: 1) computeCommandEncoder!.setBuffer(bufferC, offset: 0, index: 2) computeCommandEncoder!.setComputePipelineState(computePipelineState.0) computeCommandEncoder!.dispatchThreadgroups(numThrdgroups, threadsPerThreadgroup: thrdsPerGroup) // Finalize configuration and start job computeCommandEncoder!.endEncoding() commandBuffer!.commit() // Wait for job to finish commandBuffer!.waitUntilCompleted() // Get output data back into Swift let data = NSData(bytesNoCopy: bufferC!.contents(), length: bufferLength, freeWhenDone: false) data.getBytes(&vectorC, length:bufferLength) print("\(#file):\(#line) vectorA = \(vectorA)") print("\(#file):\(#line) vectorB = \(vectorB)") print("\(#file):\(#line) vectorC = \(vectorC)") exit(0) Note that I found no replacement for thrdWidth declaration and so just inserted an integer.
Topic: Graphics & Games SubTopic: General Tags:
Apr ’22
Reply to SecureCoding roadblock?
Sorry, I'll try that again. Here are the class declarations. I suspect my problem is in them. class classOne: Equatable, NSSecureCoding, Codable, NSCoding { static var supportsSecureCoding = true var a_One : String var b_One : [UInt8] init(a_One: String?, b_One: [UInt8]?) { self.a_One = a_One ?? String() self.b_One = b_One ?? [UInt8]() } enum CodingKeys: String, CodingKey { case a_One, b_One } static var allowedTopLevelClasses: [AnyClass] { return [NSArray.self, NSString.self] } func encode(with aCoder: NSCoder) { aCoder.encode(a_One, forKey: CodingKeys.a_One.rawValue) aCoder.encode(b_One, forKey: CodingKeys.b_One.rawValue) } required init?(coder aDecoder: NSCoder) { a_One = aDecoder.decodeObject(forKey: CodingKeys.a_One.rawValue) as? String ?? String() b_One = aDecoder.decodeObject(forKey: CodingKeys.b_One.rawValue) as? [UInt8] ?? [UInt8]() } static func == (lhs: classOne, rhs: classOne) -> Bool { // unnecessary but mirrors my more-elaborate code if lhs.a_One == rhs.a_One && lhs.b_One == rhs.b_One { return true } else { return false } } } class classTwo: NSObject, NSSecureCoding, Codable, NSCoding { static var supportsSecureCoding = true var c_Two : Int var d_Two : Double var e_Two : [classOne] init(c_Two: Int, d_Two: Double?, e_Two: [classOne]? ) { self.c_Two = c_Two self.d_Two = d_Two ?? Double() self.e_Two = e_Two ?? [classOne]() } enum CodingKeys: String, CodingKey { case c_Two, d_Two, e_Two } static var allowedTopLevelClasses: [AnyClass] { return [NSArray.self, NSString.self, classOne.self] } func encode(with aCoder: NSCoder) { aCoder.encode(c_Two, forKey: CodingKeys.c_Two.rawValue) aCoder.encode(d_Two, forKey: CodingKeys.d_Two.rawValue) aCoder.encode(e_Two, forKey: CodingKeys.e_Two.rawValue) } required init(coder aDecoder: NSCoder) { c_Two = aDecoder.decodeInteger(forKey: CodingKeys.c_Two.rawValue) d_Two = aDecoder.decodeDouble(forKey: CodingKeys.d_Two.rawValue) e_Two = aDecoder.decodeObject(forKey: CodingKeys.e_Two.rawValue) as? [classOne] ?? [classOne]() } }
Topic: App & System Services SubTopic: General Tags:
May ’22
Reply to SecureCoding roadblock?
piecemeal then: func genData() { var myOutput = Array(repeating: [classOne](), count: 16 ) let words:[UInt8] = [ 0b01111100, 0b00111100, 0b00011100, 0b00001100, 0b00001000, 0b00000000 ] for word1 in words { for word2 in words { for word3 in words { let candidate = classOne( a_One: "Nothing", b_One: [word1, word2, word3] ) let bitCount = word1.nonzeroBitCount + word2.nonzeroBitCount + word3.nonzeroBitCount myOutput[bitCount].append(candidate) } } } let dataToSave = classTwo(c_Two: Int(myOutput[15][0].b_One[0]), d_Two: log(Double(myOutput[15][0].b_One.count)), e_Two: myOutput[15]) // just some/any data to save saveFile(fileName: "TestFileSecureCodingExample", object: dataToSave, ext: "test", appendToFile: kCFBooleanFalse) }
Topic: App & System Services SubTopic: General Tags:
May ’22
Reply to SecureCoding roadblock?
// // save-load-code.swift // exampleClassInClassSecureCoding // import Foundation func saveFile(fileName: String, object: classTwo, ext: String, appendToFile: CFBoolean) { let fileDir = URL(fileURLWithPath: "~/") let fileURL = URL(fileURLWithPath: "~/\(fileName)").appendingPathExtension(ext) if !FileManager.default.fileExists(atPath: fileDir.path) { do { try FileManager.default.createDirectory(atPath: "~/", withIntermediateDirectories: false, attributes: nil) } catch { print(error) } do { let data = try NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: true) try data.write(to: fileURL ) let defaults = UserDefaults.standard defaults.set(data, forKey: "classTwo") } catch { print(error) } } else if appendToFile == kCFBooleanTrue { do { let fileHandle = try FileHandle(forWritingTo: fileURL ) let data = try NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: true) try fileHandle.seekToEnd() let buffer = FileHandleBuffer(fileHandle: fileHandle) buffer.size = data.count try buffer.write(data) let defaults = UserDefaults.standard defaults.set(data, forKey: "classTwo") } catch { print(error) } } }
Topic: App & System Services SubTopic: General Tags:
May ’22