Post

Replies

Boosts

Views

Activity

Reply to How to operate a image file
a URL can point at a local file (the scheme is 'file', so such URLs begin "file://"). For example, if you use NSOpenPanel on macOS to enable the user to select the file(s) to open, you'll get an array of URLs from the panel. See https://developer.apple.com/documentation/appkit/nsopenpanel. NSImage supports jpeg format input.
Topic: Programming Languages SubTopic: Swift Tags:
May ’23
Reply to Swift language, how to convert an array of int type to data type
plain old data in Swift arrays are contiguous in memory. If the type you are storing were more complex, you may need to use ContiguousArray instead of Array. There are lots of withUnsafeXXX functions, both free and member functions; it took me quite a while to find the right ones. This code generates your array of Int values, makes a Data from the array's data, then makes a new Array from the Data's data. There doesn't seem to be a way to make an Array or even a ContiguousArray directly from a buffer pointer. import Foundation let sizeofElement = MemoryLayout<Int>.size // create array (example is twelve Ints from 1 to 12 var array = Array(1...12) // create a Data from the bytes in the original array var data = Data() array.withUnsafeBufferPointer { data = Data(bytes: $0.baseAddress!, count: $0.count * MemoryLayout<Int>.size) } // construct a new array by walking through the bytes of data, one Float at a time // start with an empty array, which we can manipulate in the closure below var newArray: [Int] = [] data.withUnsafeBytes { rawBufferPtr in rawBufferPtr.withMemoryRebound(to: Int.self) { buffer in // access it as contiguous Int values var iter = buffer.makeIterator() while let aNumber = iter.next() { newArray.append(aNumber) } } } print(array) print(newArray)
Topic: Programming Languages SubTopic: Swift Tags:
May ’23
Reply to Project Won't Build with .h File
Don't you hate it when this happens? Yes, there is a newer version of Xcode (14.3.1), but I doubt that the problem is that you are not using the latest version, given that your project didn't change. I suggest you take a deep breath, boot into Recovery mode and run Disk First Aid. Perhaps something is messed up in your file system.
Jun ’23
Reply to When to use utf8 vs utf16 vs ascii character codes?
If you're doing this for a user-entered string, don't worry about how they're encoded. CNPhoneNumber.stringValue is of type String A String is a collection of Characters You could iterate through the String by hand, but it is awkward. Swift offers compactMap, which will give you an array of single-character strings. A new String can be created from this Array. for example let likeAPhoneNumber = "(451)∕234-141😃0" let newNumberArray = likeAPhoneNumber.compactMap { $0.isNumber ? $0 : nil } let newNumber = String(newNumberArray) print (newNumber)prints 4512341410 None of this is high-performance, because iterating through a Unicode string is non-trivial.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’23
Reply to How to implement drag and drop of SF Symbols within a SwiftUI grid?
the 'drop' part of a DragGesture can be handled by the DragGesture.onEnded closure. In your .onChanged closure you can figure out where the drag is currently (value.location), so you could highlight legal destinations. In your .onEnded closure you figure out whether the move was legal and update your model accordingly. Your question is a bit broad in scope. Try to narrow it down to something where you can show a piece of self-contained code, and explain what you expect, and what actually happens.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to AppleScript. How do I get a list of all files in all subfolders without any conditions?
something like this tell application "Finder" get entire contents of alias "Users:username:Documents:somefolder" end tell but be warned that if somefolder is large, this will take a very long time. This asks the Finder to do the work on behalf of your script. The Finder doesn't show hidden files, so they don't appear in the entire contents result. There's a post here which uses System Events to do the same thing, with more code, but much quicker (and you'd have to filter out invisible files yourself) https://www.macscripter.net/t/getting-all-files-list-of-directory-and-of-its-subdirectories/71573/4 Did you search for "AppleScript list files and folders"? It wasn't difficult to find these options. Perhaps you did find them but were not happy with the result in your application? If so, please describe what exactly you did try to do, and how it fell short of your expectations.
Topic: App & System Services SubTopic: Core OS Tags:
Jun ’23
Reply to How to update macOS Beta on VM devices
why are you using a VM, and what are you testing with it, and how? I gave up on using VMs because of the inability to sign into iCloud on a VM, and because it really didn't seem to save any time. I wanted to test the first-time-install experience for our software, which seems impossible to replicate without starting with a new OS and a new user account. It seems to take just as long to reinstall the OS on a VM as it does to reinstall the OS on a physical partition. So that's what I do now - I install beta OSs on a partition of an external drive, and boot a second laptop from that (so that I can continue to use my development machine for other tasks like email and Slack). I often need to debug behavior on the new OS, so I have to install Xcode on that new OS, which also takes its sweet time. I put the beta OS on an external disk, and use a second laptop booted from that disk as my test machine. I'd really like to hear how other people are using VMs for testing their software, and how that experience is better than using a separate Mac and/or a separate boot partition.
Jul ’23
Reply to How to operate a image file
a URL can point at a local file (the scheme is 'file', so such URLs begin "file://"). For example, if you use NSOpenPanel on macOS to enable the user to select the file(s) to open, you'll get an array of URLs from the panel. See https://developer.apple.com/documentation/appkit/nsopenpanel. NSImage supports jpeg format input.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’23
Reply to Previous MacOS Builds
last week, when I answered your post, softwareupdate --list returned a few versions of macOS 13 and macOS 12 (but not 12.0.1) for me. Today, all it offers me is 13.4.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
May ’23
Reply to Swift language, how to convert an array of int type to data type
plain old data in Swift arrays are contiguous in memory. If the type you are storing were more complex, you may need to use ContiguousArray instead of Array. There are lots of withUnsafeXXX functions, both free and member functions; it took me quite a while to find the right ones. This code generates your array of Int values, makes a Data from the array's data, then makes a new Array from the Data's data. There doesn't seem to be a way to make an Array or even a ContiguousArray directly from a buffer pointer. import Foundation let sizeofElement = MemoryLayout<Int>.size // create array (example is twelve Ints from 1 to 12 var array = Array(1...12) // create a Data from the bytes in the original array var data = Data() array.withUnsafeBufferPointer { data = Data(bytes: $0.baseAddress!, count: $0.count * MemoryLayout<Int>.size) } // construct a new array by walking through the bytes of data, one Float at a time // start with an empty array, which we can manipulate in the closure below var newArray: [Int] = [] data.withUnsafeBytes { rawBufferPtr in rawBufferPtr.withMemoryRebound(to: Int.self) { buffer in // access it as contiguous Int values var iter = buffer.makeIterator() while let aNumber = iter.next() { newArray.append(aNumber) } } } print(array) print(newArray)
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’23
Reply to Why AVPlayer returns video duration (seconds) as Double?
an AVPlayerItem has a duration property, of type CMTime. CMTime does not have a .toString property, it looks like a member of your team wrote an extension on CMTime to provide such a property. Your confusion probably arises because that extension chose to only display whole seconds. Your video really has a duration of 37,568 ticks of a 1/1000s clock.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
May ’23
Reply to Where is the link to Swift language book (epub)?
you can get it in the Books app. Search for "swift" in the Apple Books/Book Store section. It was free, I already have it so I can't tell you if it still is.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to Project Won't Build with .h File
Don't you hate it when this happens? Yes, there is a newer version of Xcode (14.3.1), but I doubt that the problem is that you are not using the latest version, given that your project didn't change. I suggest you take a deep breath, boot into Recovery mode and run Disk First Aid. Perhaps something is messed up in your file system.
Replies
Boosts
Views
Activity
Jun ’23
Reply to When to use utf8 vs utf16 vs ascii character codes?
If you're doing this for a user-entered string, don't worry about how they're encoded. CNPhoneNumber.stringValue is of type String A String is a collection of Characters You could iterate through the String by hand, but it is awkward. Swift offers compactMap, which will give you an array of single-character strings. A new String can be created from this Array. for example let likeAPhoneNumber = "(451)∕234-141😃0" let newNumberArray = likeAPhoneNumber.compactMap { $0.isNumber ? $0 : nil } let newNumber = String(newNumberArray) print (newNumber)prints 4512341410 None of this is high-performance, because iterating through a Unicode string is non-trivial.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to How to implement drag and drop of SF Symbols within a SwiftUI grid?
the 'drop' part of a DragGesture can be handled by the DragGesture.onEnded closure. In your .onChanged closure you can figure out where the drag is currently (value.location), so you could highlight legal destinations. In your .onEnded closure you figure out whether the move was legal and update your model accordingly. Your question is a bit broad in scope. Try to narrow it down to something where you can show a piece of self-contained code, and explain what you expect, and what actually happens.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to AppleScript. How do I get a list of all files in all subfolders without any conditions?
something like this tell application "Finder" get entire contents of alias "Users:username:Documents:somefolder" end tell but be warned that if somefolder is large, this will take a very long time. This asks the Finder to do the work on behalf of your script. The Finder doesn't show hidden files, so they don't appear in the entire contents result. There's a post here which uses System Events to do the same thing, with more code, but much quicker (and you'd have to filter out invisible files yourself) https://www.macscripter.net/t/getting-all-files-list-of-directory-and-of-its-subdirectories/71573/4 Did you search for "AppleScript list files and folders"? It wasn't difficult to find these options. Perhaps you did find them but were not happy with the result in your application? If so, please describe what exactly you did try to do, and how it fell short of your expectations.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to iOS AvQueuePlayer Playback Issue
you should file an issue using Feedback Assistant, including the problematic file. Bugs mentioned here don't make it into Apple's bug tracking system
Topic: Media Technologies SubTopic: Audio Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to Controlling F-Stop, exposure time, and zoom level, in Swift
look at AVCaptureDevice in the developer documentation
Replies
Boosts
Views
Activity
Jun ’23
Reply to AppleScript. How do I get a list of all files in all subfolders without any conditions?
You asked about AppleScript. You can use ls in a shell to get a list of the contents of a directory, add the -R flag to recurse through directories. What are you trying to do?
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to AppleScript. How do I get a list of all files in all subfolders without any conditions?
I don't understand your question "what is the name of what you proposed?". I proposed that you use the 'ls' command, rather than 'find'. Once again, what are you trying to do?
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to Make a new Xcode target that's a copy of an existing one
click on the project in the navigator on the right, to expose the list of targets in the editor. Right click on the target you want to duplicate, and select "Duplicate".
Replies
Boosts
Views
Activity
Jun ’23
Reply to How to update macOS Beta on VM devices
why are you using a VM, and what are you testing with it, and how? I gave up on using VMs because of the inability to sign into iCloud on a VM, and because it really didn't seem to save any time. I wanted to test the first-time-install experience for our software, which seems impossible to replicate without starting with a new OS and a new user account. It seems to take just as long to reinstall the OS on a VM as it does to reinstall the OS on a physical partition. So that's what I do now - I install beta OSs on a partition of an external drive, and boot a second laptop from that (so that I can continue to use my development machine for other tasks like email and Slack). I often need to debug behavior on the new OS, so I have to install Xcode on that new OS, which also takes its sweet time. I put the beta OS on an external disk, and use a second laptop booted from that disk as my test machine. I'd really like to hear how other people are using VMs for testing their software, and how that experience is better than using a separate Mac and/or a separate boot partition.
Replies
Boosts
Views
Activity
Jul ’23