Post

Replies

Boosts

Views

Activity

Reply to WWDC2023 "Support external cameras in your iPadOS app" presentation sample code
I haven't found the modified sample, but you can download the original code (linked in the WWDC video description) and modify it by following the instructions in the video. At least the slide showing how to preferentially detect and use an external camera is visible for a few seconds, I haven't bothered with the rest yet (which deal with hot plugging etc). It is a couple of lines of code to changes to get a picture from your external camera.
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’23
Reply to Problem when working with .onChange and .onAppear modifier
you haven't shown code complete enough for anyone to reproduce your problem. Try to reduce the problem to a minimum (maybe in a new project), then repost if need be. You'll probably find that you'll figure it out yourself by performing the reduction. What does "showAlert" do? What do you mean by "the issue is in the .onAppear modifier"? It doesn't compile, it is never executed, it behaves in some other way you don't expect - what?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’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 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 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 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 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 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