My app generates piecemeal near terabyte data distributed over one hundred files. Due to RAM and internal HD limitations I must store to an external HD in piecemeal fashion. That is to say, append fresh records directly to an existing file without reading-in the whole file, appending, and writing it out again.
Ultimately (when data generation ceases) I will check each file to ensure uniqueness of member data structures.
Is Core Data the tool I should use?
If not, how do I append directly to disk-files without first reading it in?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Attached is an entire project (4 files) that mirrors my actual project including the failure to save to file.
Am I:
missing some syntax in this code?
failing to config a defaults file?
not set the necessary parameters in " "Build Settings" or "Build Rules etc.?
I was writing to JSON files, but now that I must append to files directly, and JSON doesn't do that easily, I am trying to write using native macOS tools.
WELL, IT SEEMS I CAN'T SEND YOU THE CODE, TOO MANY CHARS. I CAN'T ATTACH ANY FILE EITHER. WHY OFFER IT IF IT IS NOT ALLOWED?
ANYWAY, CAN YOU GLEAN ANYTHING FROM THIS... Thanks.
My debugger area:
2022-05-28 12:03:11.827372-0500 exampleClassInClassSecureCoding[1508:29981] Metal API Validation Enabled
2022-05-28 12:03:11.940123-0500 exampleClassInClassSecureCoding[1508:29981] *** NSForwarding: warning: object 0x600003cf7090 of class 'exampleClassInClassSecureCoding.classOne' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector -[exampleClassInClassSecureCoding.classOne replacementObjectForKeyedArchiver:]
2022-05-28 12:03:11.940416-0500 exampleClassInClassSecureCoding[1508:29981] Unrecognized selector -[exampleClassInClassSecureCoding.classOne replacementObjectForKeyedArchiver:]
Unrecognized selector -[exampleClassInClassSecureCoding.classOne replacementObjectForKeyedArchiver:]
Performing @selector(didPressButton:) from sender _TtC7SwiftUIP33_9FEBA96B0BC70E1682E82D239F242E7319SwiftUIAppKitButton 0x7ff08ab06480
Developing a program that needs maximum cores. My previous Intel Mac mini used all 6 cores, according to Activity Monitor. It showed 600% cpu usage. I assumed the M2 would use twelve, but only shows 400% cpu usage in Activity Monitor, ergo, two less!
I don't recall setting a core usage parameter in Xcode.
Any ideas?
Ventura 13.3 and Xcode 14.3 up to date as of this post.
Below is some simple code that does nothing, saves nothing. Yet the memory usage keeps rising. Am I missing something or is this a bug?
The code requires 6 core CPU minimum.
ContentView.swift
import SwiftUI
import Combine
struct ContentView: View {
@EnvironmentObject var loopClass:LoopClass
var body: some View {
ProgressView(value: Float(loopClass.loop_count), total: Float(loopClass.max_loops) ).progressViewStyle(.circular).padding()
Button("Run looper", action: {
loopClass.loopFunc()
}
)
}
}
LoopClass.swift
import Combine
class LoopClass: ObservableObject {
@Published var loop_count = 0
@Published var max_loops = 0
func loopFunc () {
let loopSet = [ 1, 3, 5, 7, 11, 13 ]
max_loops = Int(pow(Double(loopSet.count), 13.0))
print("max_loops = \(max_loops)")
for loop13 in loopSet {
DispatchQueue.global().async {
for loop12 in loopSet {
for loop11 in loopSet {
for loop10 in loopSet {
for loop9 in loopSet {
for loop8 in loopSet {
for loop17 in loopSet {
for loop16 in loopSet {
for loop5 in loopSet {
for loop4 in loopSet {
for loop3 in loopSet {
for loop2 in loopSet {
for loop1 in loopSet {
DispatchQueue.main.async{ self.loop_count += 1 }
}
}}}}}}}}}}}
} // DQ
} // for loop13
}
}
given [URL.lastPathComponent] how do I sort as Finder sorts in macOS?
Example: urlPaths = contentsOfDirectory(at: ... e.g., ["1H", "10Ne", "11Na"]
urlPaths.sort(by: { $0 < $1 } //Apple Swift version 5.9
print(urlPaths) // 10Ne 11Na 1H
whereas Finder filename sort gives // 1H 10Ne 11 Na
and is beautiful. I have always taken this sort for granted and am now buggered to duplicate it.
there are other unresolved posts on this issue but maybe mine is solvable.
I copied the files I contributed from a working project to a new project using the finder (drag and drop). So I did not copy entitlements. Xcode automatically added the files to the project just fine. My app uses data on a removable drive, or used to, because I now get the error above. At one point I copied the product app to the desktop hoping to get the permissions alert window, but it never came. Oddly, in System Settings/Privacy & Security/Files & Folders my "new" app is listed with "Removable Volumes" slider = on.
The file permissions (unix-like) on that drive haven't changed between projects and allow everyone to read.
How can I fix this?
I have used SceneKit for several years but recently have a problem where a scene with fewer than 50 nodes is partially drawn, i.e., some nodes are, some aren't, and greater than 50 nodes are always draw correctly. This seems to have happened since concurrency was introduced. (w.r.t. concurrency, I had been using DispatchQueue successfully before then.)
Since all nodes (few or many) are constructed and implemented by the same functions etc. I'm baffled.
When I print the node hierarchy all nodes are present whether few or many.
SceneView() has [.rendersContinually] option selected. Every node created (few or many) has .opacity = 1.0, .isHidden = false
I haven't tried setting-back the compiler version as that is not a long term solution, and I know the same code worked fine then.
I didn't find a suggestion box on Swift's website so I'll post it here.
SwiftCharts are great but limited. I need more data on a single chart. Candlestick and OHLC type charts would be an excellent addition. Hopefully, influencers from Apple can make that happen.
Thanks.
by selecting Help under my Help menu item or cmd-h no window appears until the menu bar is touched.
myApp.swift file:
import SwiftUI
import QuickLook
@main
struct myApp: App {
@Environment(\.openWindow) var openWindow
@State var helpURL: URL? = nil
var body: some Scene {
WindowGroup {
ContentView()
}
.commandsReplaced {
CommandGroup(before: .appInfo) {
Button("Quit") {
NSApp.terminate(nil)
}.keyboardShortcut("q")
}
CommandGroup(before: .help) {
//FIXME: only shows help if the menu bar is touched again.
Button("Help") {
helpURL = Bundle.main.url(forResource: "help", withExtension: "txt")
}
.keyboardShortcut("h")
.quickLookPreview($helpURL)
}
}
}
}
How should this be coded for proper action?
Thanks
Topic:
App & System Services
SubTopic:
General
running my Xcode app in Simulator: screenshots are sent to Library/Developer/CoreSimulator/Devices
followed by the cryptic code for the device ( given in /Library/Developer/CoreSimulator/Devices/device_set.plist ), a subdirectory then the PNG file. This is very inconvenient.
How to I set the desired directory?
My SceneView hides part of my NSStackView's TextFields. I don't see anything in the inspector for the z dimension. How can I ensure the StackView is on top, i.e., wholly visible?
I don't want to shove views around to "fit them in". They must overlap.
Indeed, I may wish to have all TextFields, etc. overlay the SceneView in the future, but that's a different subject.
I know this would be easy in SwiftUI, but...
I launch the following runSavePanel() from, e.g.,
@IBAction func JSONall(_ sender: NSButton) {
if !nsPanelActivatedThisSessionForSandbox {
nsPanelActivatedThisSessionForSandbox = true
runSavePanel() }
...
}
where var nsPanelActivatedThisSessionForSandbox = false
is declared as a global in the AppDelegate.swift file and is intended to prevent repeated user prompting as the program creates many files but needs sandbox acknowledgment at least once.
The problem behavior is that upon clicking the OK button, the app merrily creates the files in the chosen directory but the modal window stays open until the app is done creating files (around ten minutes). Here is my runSavePanel() and its (empty) delegate:
func runSavePanel() {
let defaults = UserDefaults.standard
let savePanel = NSSavePanel()
savePanel.canCreateDirectories = true
savePanel.canSelectHiddenExtension = false
savePanel.showsHiddenFiles = false
// savePanel.allowedFileTypes = ["JSON", "csv"] // deprecated
savePanel.directoryURL = defaults.url(forKey: "fileDirectoryPref")
let delegate = OpenSavePanelDelegate() // cannot consolidate with next line
savePanel.delegate = delegate
let result = savePanel.runModal()
if result == NSApplication.ModalResponse.OK {
if savePanel.url != nil {
do {
try savePanel.delegate!.panel!(savePanel, validate: savePanel.url!)
defaults.set(savePanel.url, forKey: "fileDirectoryPref")
// defaults.set(savePanel.url, forKey: "NSNavLastRootDirectory") // does not write
} catch {
print("\(result) ViewController Structures.swift:739 runSavePanel()")
}
}
}
}
class OpenSavePanelDelegate: NSObject, NSOpenSavePanelDelegate {
func panel(_ sender: Any, validate url: URL) throws {
/* In Swift, this method returns Void and is marked with the throws keyword to indicate that it throws an error in cases of failure.
You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.
*/
// throw CustomError.InvalidSelection
}
}
// enum CustomError: LocalizedError {
// case InvalidSelection
//
// var errorDescription: String? {
// get {
// return "\(CustomError.InvalidSelection)"
// }
// }
// }
Idk how to stop the double spacing when pasting my code. Sorry.
The delegate is a requirement but I don't know how to configure it. The app doesn't generate errors... or at least it allows the desired output.
Is the delegate supposed to terminate the modal window somehow?
it may not deliver what you expect. For example:
if you are using NASA/JPL/Standish equations of heliocentric planetary motion, it requires:
"3. Modulus the mean anomaly (M) so that -180deg<=M<=+180deg and then obtain the eccentric anomaly, E, from the solution of Kepler's equation..."
If you attempt to use the Swift "Modulo operator, %" you'll get the Xcode directive to use truncatingRemainder instead.
Which IS better than % because of this note in "The Swift Programming Language (Swift 5.3)":
"“NOTE
The remainder operator (%) is also known as a modulo operator in other languages. However, its behavior in Swift for negative numbers means that, strictly speaking, it’s a remainder rather than a modulo operation.”
Excerpt From
The Swift Programming Language (Swift 5.3)
Apple Inc.
https://books.apple.com/us/book/the-swift-programming-language-swift-5-5/id881256329
This material may be protected by copyright.
But you should try truncatingRemainder in your playground!
Let: 0deg = 12 O'clock, 180/-180deg = 6 O'clock, -90deg = 9 O'clock and +90deg = 3 O'clock
Now run this on your playground:
let M = -181.25
var M180 = M
while M180 > 180.0 { M180 -= 360.0 }
while M180 < -180.0 { M180 += 360.0 }
print("M = \(M)\t\tM180 = \(M180)\t\tM.truncatingRemainder(dividingBy: 180.0) = \(M.truncatingRemainder(dividingBy: 180.0))\t\tM.truncatingRemainder(dividingBy: 360.0) = \(M.truncatingRemainder(dividingBy: 360.0))")
and you'll get this result:
M = -181.25
M180 = 178.75
M.truncatingRemainder(dividingBy: 180.0) = -1.25
M.truncatingRemainder(dividingBy: 360.0) = -181.25
Thus, truncatingRemainder(dividingBy: 180.0) puts your planet 180deg away from where it should be, while M180 keeps the planets moving without quantum leaps.
I print a lot of SIMD3 vectors to the debugger area in Xcode. Some vector-elements have prefixed signs and some values are longer than others. I would like the printed vectors to align as they did in my old days of Fortran.
The SIMD3 members are scalars which can't be cast as Double ( I know how to format output for Double) or even as NSNumber.
Something akin to a NumberFormatter for vectors would be the objective, but I don't see how to do it. Scalars are wierd and (helpful) documentation sparse.
I use as many cpu's as I can get with DispatchQueue. How do I test the Mac for cpu count in my code?