To check if my copying files with drag-n-drop was wrong, I created yet another new project and used the "add files" within the new app. No permissions to anywhere!
How do I add permissions to an app?
Post
Replies
Boosts
Views
Activity
OK, if that wasn't odd enough... as a work around I made a Data.dataset folder in the apps assets and copied-in a few files to read. Only, they also say "you don't have permission to view it" referring to Assets.xcassets! Yes, this folder was drag-n-dropped from the old project into this new project.
Yet if I create a new folder in the project and copy the data into it, I have no permissions as well. No permissions within my own project, anywhere! Hmm. Security gone awry.
I have not found an example of using "#selector(copy)" to access the objc "copy" method. All the syntax I have tried fails.
as an attempted work-around I created a global array of mySCNGeometry.copy() which should have allowed the materials to be changed independently as stated in the Developer Documentation. They are in fact all the same geometry whereas changing any one "copy" changes them all.
OK, I have just learned that objc methods can be called with Swift. Most examples are of custom functions or methods.
How can I call the existing objc version of .copy() since Swift's doesn't work?
Thanks
fyi: I could never grasp objc and stopped programming during that period. Please be generous with example code.
.copy() is broken
I have tested dozens of permutations in calling.
curiously, when I use .copy() on an SCNGeometry the geometry?.geometrySourceChannels, geometry?.elements, and geometry?.materials are all == to the original but the test whether the geometries themselves are equal returns false. How can a copy not equal its original?
Idk what else to test for "as missing" from the copy() .
SceneKit and SwiftUI are both imported.
The documentation shows SceneView is a member of both yet after SceneView is initiated any attempt to access ".defaultCameraController" gives the error "This property is defined on SCNView and may not be available in this context." And indeed, is not. So I'm guessing the SwiftUI-SceneView overrides the SceneKit-SceneView and it has no ".defaultCameraController" nor a camera as far as I can tell.
Every search involves importing AVFoundation which seems like another can of worms.
Converting to ARKit, likewise.
If the user chooses to manipulate the viewpoint, then he'll just have to restore it himself.
FYI, I append JSON files millions of times per file. Here's the code:
func saveBAToJSON(BA: myCustomClass) {
let fileName = "created from BA"
let ArchiveURL = getArchiveURL(fileName: fileName, ext: "JSON")
var ArchiveDirectoryPath = fileDirPath
let localFileManager = FileManager()
do {
let resources = try? ArchiveURL.resourceValues(forKeys: [.fileSizeKey])
let fileSize = resources?.fileSize ?? 0
/* The JSON file is appended many times and it must be limited in size otherwise memory is over taxed. maxFileSize is a global var that is machine specific. */
if fileSize > maxFileSize {
let dirContents = try! localFileManager.contentsOfDirectory(atPath: ArchiveDirectoryPath)
var elemFiles = 0
/* If a file would exceed MaxFileSize, start a new file copying it and appending an incremented counter to the name. */
for elem in 0..<dirContents.count { if dirContents[elem].contains(fileName) { elemFiles += 1 } }
try FileManager.default.copyItem(at: ArchiveURL, to: getArchiveURL(fileName: fileName+"-\(elemFiles)", ext: "JSON"))
try FileManager.default.removeItem(at: ArchiveURL)
}
} catch { print("\(Date.now):\(#file):\(#line) saveBAToJSON():fileSize", error) }
do {
let myJSONencoder = JSONEncoder()
myJSONencoder.nonConformingFloatEncodingStrategy = .convertToString(positiveInfinity: "+Infinity", negativeInfinity: "-Infinity", nan: "NaN")
var data = try myJSONencoder.encode(BA)
if let fileHandle = try? FileHandle(forWritingTo: ArchiveURL) {
defer {
fileHandle.closeFile()
}
/* This is the main trick: truncate the repeating JSON components from the top of file to be appended, strip the JSON components at the end of the file to append-to (after converting to base64) replacing it with a comma (in my case). Write to file. */
let truncateCount = UInt64(36 + filename.count + String(BA.myCustomClassElement1).count)
/* you must count chars in your specific JSON's to get this right. I'm sure this could be coded to adapt to any JSON file. */
let strippedRange = data.range(of: Data(base64Encoded: "my base64 encoded repeating components at end-of-file" )!)
let commaData = Data(base64Encoded: "LA==")!
data.replaceSubrange(strippedRange!, with: commaData )
let end = try fileHandle.seekToEnd()
if end > truncateCount {
try fileHandle.truncate(atOffset: end - truncateCount )
try fileHandle.write(contentsOf: data )
}
}
else { try data.write(to: ArchiveURL, options: [.atomic, .noFileProtection]) }
} catch { print("\(Date.now):\(#file):\(#line) saveBAToJSON():fileSize", error) }
}
Share and Enjoy
homage Eskimo
Armed with Scott's clue, ".localizedStandard", here's what works:
after collecting [URL] with "contentsOfDirectory(at:", parse-out a [String] from the URL components.
apply .sorted(using: .localizedStandard) and use in Picker()
from Picker() use the return value and re-assemble a path to use with "URL(fileWithPath:"
finish-off with JSONDecoder()
Gives a nice Finder-style Picker list and opens the file.
Thanks Scott
Ah, thank you! Yes, using .sortedKeys returned the desired behavior. It is curious that this must have been a default as evidenced by consistent formatting for over a year, that is, until now.
Thanks again.
Verified by commenting-out "DispatchQueue.main.async{ self.loop_count += 1 }"
A simple solution was to move the DQ between loop17 and loop16, the ProgressView works and no memory race.
Thanks Eskimo.
Sorry, my error. I had engineered my DispatchQueue's over two years ago. Re-engineering them uses all cores!
Found it...
“Build Phases”:”Compile Sources”:LAPACK functions.swift”. double-click and add: -DACCELERATE_NEW_LAPACK
hit return.
I had to re-launch XCode to get the alerts to stop.
Is this work entirely CPU bound?
No GPU's involved, so I guess so. The app does nothing outside of the machine upon which it runs. Once the database is generated the app just becomes a viewing instrument.
This reply is two weeks late because for two weeks the machine was busy generating useless data. lol. (Down from a 300 year estimated compute time, so yay, progress!)
We can probably close this thread because I have no need to generate data on unknown machines. Thanks.