Post

Replies

Boosts

Views

Activity

Reply to Novice SwiftUI developer can't make network call
"Statements are not allowed at the top level" occurs because you put the code into a file but didn't wrap it in a func. The line if let banjo = URL(string: ... etc is a statement, not a declaration. Swift wants you to be clear about when that statement should be executed. You can sprinkle declarations around your program more or less wherever you like, because (generally) a declaration just makes a thing exist as a named object in your program, and doesn't have side effects which may differ depending on order of instantiation. There is built-in documentation in Xcode. Window / Developer Documentation. Type URL into the search field, choose Swift as the language. You can also search on https://developer.apple.com/documentation/ . Click on the magnifying glass icon. The documentation for URL is surprisingly difficult to find on the web site, but it is here: https://developer.apple.com/documentation/foundation/url There is some more comprehensive documentation about using URLSession to download files here: https://developer.apple.com/documentation/foundation/downloading-files-from-websites To your question about the "shared task" - there isn't a shared task. What is shared is the URLSession. Read the documentation for URLSession. https://developer.apple.com/documentation/foundation/urlsession/ URLSession.shared returns a URLSession. You're making a request to the URLSession (a class, which is a collection of functions) to get its shared instance, which is a single URLSession object (a class instance, which is a collection of functions and state). https://developer.apple.com/documentation/foundation/urlsession/shared "For basic requests, the URLSession class provides a shared singleton session object that gives you a reasonable default behavior for creating tasks. Use the shared session to fetch the contents of a URL to memory with just a few lines of code." From that single URLSession object you are creating a dataTask with a URL called "banjo". https://developer.apple.com/documentation/foundation/urlsession/datatask(with:)-10dy7 The dataTask "Creates a task that retrieves the contents of the specified URL." But that task won't do anything until you tell it to, by calling resume() on it. Please, when you post code, wrap it in a code block, using the Code Block widget under the Reply box on this forum. Otherwise your code is difficult to read. You can post up to 7000 characters in a reply - it is easier for us to help you if you post a complete code snippet.
Topic: Design SubTopic: General
Sep ’25
Reply to Novice SwiftUI developer can't make network call
var banjo = URL(string: myString) is using this initializer for URL: init?(string: String) The ? after init means that it returns an optional URL. If it can't create a URL from your string, it will return nil. Your next line, let task = URLSession.shared.dataTask(with:banjo ) is using this function of URLSession: func dataTask(with url: URL) -> URLSessionDataTask which takes a URL, not an optional URL. You've got to decide what to do in your code if you get a nil in banjo. the simplest thing to do is use if let banjo = URL(string: myString) { // do stuff with banjo } else { // whatever you want to do if you've made a // string that can't be turned into a URL } if let binds a non-nil result from the URL initializer to banjo. It is fine to use let here because you're not going to alter banjo after you've created it.
Topic: Design SubTopic: General
Sep ’25
Reply to AudioQueue Output fails playing audio almost immediately?
instead of sleeping for 10 (what? seconds?) try running a runloop for a while: CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, false); It gets a bit tedious during development if you always have to wait until your program is done (even if it isn't working), so you can set up a runloop dispatch source before hand. Hitting any key then return should exit your program. This example is Objective-C++, I'm sure you can adapt it to C, or just make your main file a .mm file. dispatch_source_t source = dispatch_source_create( DISPATCH_SOURCE_TYPE_READ, // dispatch_source_type_t _Nonnull type, STDIN_FILENO, // uintptr_t handle, 0, // uintptr_t mask, (unused) DISPATCH_TARGET_QUEUE_DEFAULT); dispatch_source_set_event_handler(source, ^{ std::cout << "exiting\n"; exit(0); }); dispatch_activate(source); do { CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, false); } while (true);
Topic: Media Technologies SubTopic: Audio Tags:
Sep ’25
Reply to How do I use IOUserSCSIPeripheralDeviceType00?
Splendid! Thank you Kevin, thank you for pointing out my spelling mistake. Also, thanks for the extra information about matching. It looks like some IOService subclasses copy properties from their providers to themselves, presumably to facilitate matching - is that so? When you say "DriverKit handles this differently", what do you mean? In a kext, I can crawl down the provider chain to the root, inspecting properties as I go. That doesn't seem possible with DriverKit, which (by design) severely limits access from a dext to its associated objects (at least, those that lie outside its own address space).
Sep ’25
Reply to How do I use IOUserSCSIPeripheralDeviceType00?
Hi Kevin, thanks for your reply. Sorry for the delay, I was out for a while. Here's my current personality dictionary. With this dictionary, the driver crashes, presumably in its init. The crashed thread has OSMetaClassBase::Invoke(RPC) in its stack trace, none of the code appears to be mine. I can see my driver as an object in the IORegistry called "driver" - I use SetName late in my Start_Impl() to give it a globally unique name, so I crash before this. I also tried setting IOProviderClass to IOSCSIPeripheralDeviceNub, but my driver didn't appear to load at all then. As you can see, I changed the name of IOPropertyMatch so that it won't be considered, but I would prefer to match on USB vendor and product ID, rather than a name. Does the property I'm trying to match on have to be a property of the provider, or a property of the provider or any of its parents? And is IOPropertyMatch always considered, regardless of family, or are only some family-dependent property keys considered? <dict> <key>OSBundleUsageDescription</key> <string>do stuff with a disk</string> <key>IOKitPersonalities</key> <dict> <key>driver</key> <dict> <key>CFBundleIdentifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER) </string> <key>CFBundleIdentifierKernel</key> <string>com.apple.kpi.iokit</string> <key>IOClass</key> <string>IOSCSIPeripheralDeviceType00</string> <key>IOProviderClass</key> <string>IOSCSILogicalUnitNub</string> <key>IOKitDebug</key> <integer>65535</integer> <key>IOResourceMatch</key> <string>IOKit</string> <key>IOUserClass</key> <string>driver</string> <key>IOUserServerName</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> <key>Peripheral Device Type</key> <integer>0</integer> <key>Product Identification</key> <string>EX400U</string> <key>Vendor Identification</key> <string>Corsair</string> <key>IOProbeScore</key> <string>5001</string> <key>IOMatchCategory</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER) </string> <key>xxIOPropertyMatchxx</key> <dict> <key>idVendor</key> <integer>6940</integer> <key>idProduct</key> <integer>6688</integer> </dict> <key>UserClientProperties</key> <dict> <key>IOClass</key> <string>IOUserUserClient</string> <key>IOUserClass</key> <string>userClient</string> </dict> </dict> </dict> when I use this IOKitPersonality, my "driver" object appears in the IORegistry in line with the driver stack. Its parent is IOSCSILogicalUnitNub, and its child is IOBlockStorageServices. Is this correct or should there be a system supplied IOSCSIPeripheralDeviceType00 next to it in the IORegistry?
Sep ’25
Reply to Idea for Wallpaper Feature
wrong forum. This one is for developers to ask questions and (perhaps) provide answers about developing software and accessories for Apple devices. You can submit unsolicited feature requests for iPhone here: https://www.apple.com/feedback/iphone/
Topic: Community SubTopic: Apple Developers Tags:
Sep ’25
Reply to Mac mini M2 Pro SOS blinking power light after rebooting to complete Tahoe 26 Beta 9 update from beta 8
if your Mac Mini turned into a brick, try reviving or restoring it with Apple Configurator on another Mac and a USB C (but not Thunderbolt 3!) cable in between. There's a particular port you need to use (or not use), dependent on your particular Mac (the leftmost, as seen from the back of the Mac Mini). Do I know the difference between Revive and Restore? No, I do not, and the docs don't tell me. Maybe you can figure it out. https://support.apple.com/en-us/108900
Topic: Community SubTopic: Apple Developers Tags:
Sep ’25
Reply to Screen layout positioning in Swift
something went wrong with formatting the code in your post, so it is a difficult to reproduce. I'm not sure what you're trying to get at here - you can wrap the two check boxes in an HStack, they will then appear side by side HStack { Toggle(isOn: $isCheckedOption900) { Text("9:00am") } .toggleStyle(CheckboxToggleStyle()) Toggle(isOn: $isCheckedOption930) { Text("9:30am") } } Please, when you post code, say for which platform (your code doesn't work on iOS). If you have check boxes for every half hour from 9am till 6:30pm, they're probably not going to fit across one screen anyway, if you don't want a fixed-size window, maybe you want to think about using some other container.
Topic: UI Frameworks SubTopic: SwiftUI
Sep ’25
Reply to AVAudioSession.outputVolume not reporting correctly in iOS 18+ devices
This kind of thing is where I've had some success with a code-level developer technical support question. Sometimes, you'll get an answer on the forum here, but more often not. It seems like a genuine regression, and one that you could report with a small test app and good steps-to-reproduce. You file the bug first, then ask for code level support; "hey, this worked in older OS versions, how do I make it work on the current OS"? At worst, you get an answer like "oops, we broke it, it will be fixed in future, there's no workaround", but at least it is an answer and you don't have to spend your time poking around in the dark trying to find non-existent workarounds.
Topic: Media Technologies SubTopic: Audio Tags:
Sep ’25
Reply to XCode Refuses to Load Team
so if you log in to developer.apple.com and click the Account tab, you see the missing team under your name? But in Xcode's Settings, you don't see that team under your account? That does sound frustrating. It has never happened to me, so I can't help directly. There is a link to Membership and Account help here: https://developer.apple.com/contact/topic/select good luck!
Sep ’25
Reply to Why does AVAudioRecorder show 8 kHz when iPhone hardware is 48 kHz?
Is the iPhone mic actually capturing at 8 kHz, or is it recording at 48 kHz and then downsampling to 8 kHz internally? the latter. Your own investigation indicates this. The microphone doesn't record, it provides samples. The AVAudioRecorder records, you gave it the settings to use. Is there any way to force the hardware to record natively at 8 kHz? Have you tried setPreferredSampleRate? The docs say it is hardware dependent, the microphone might provide samples at a single fixed, or a few fixed rates. If not, what’s the recommended approach for telephony-quality audio (true 8 kHz) on iOS devices? Well, 8kHz 16-bit recordings from a modern iPhone microphone probably yields better than telephone quality. What are you actually trying to achieve? "Sounds like an old analog telephone" is probably a job for a narrow bandwidth filter (300 to 3.5kHz), the injection of noise at about 45 dB below the maximum amplitude, and some distortion and clipping. See https://developer.apple.com/documentation/avfoundation/creating_custom_audio_effects
Topic: Media Technologies SubTopic: Audio Tags:
Sep ’25
Reply to iPadOS: remove system actions from Menu Bar
if you're building your app with SwiftUI, you're looking for CommandGroup(replacing: .windowList) { } if you remove too many (for example, if the windowList command group contains Close Window), then you'll need to put it back in manually, using CommandMenu. But if you don't have a New Window command, why would you keep Close Window around? What happens when you close the last (or only) window? If you elect to quit the app, all you need it a Quit command, which is another menu.
Topic: UI Frameworks SubTopic: UIKit
Sep ’25
Reply to Xcode won't execute code?
in this example: struct ContentView: View { var body: some View { Button("Tap Me") { // Action to perform when the button is tapped print("Button was tapped!") startAccelerometer() } } } you see the error "Cannot find 'startAccelerometer' in scope" because startAccelerometer is outside the scope of the structure ContentView (which begins at its { and ends at its }. The compiler doesn't know you mean the function called startAccelerometer inside your MyViewController class. That's a good thing, because names are often re-used in different places in code. In your more recent example, your ContentView doesn't refer to startAccelerometer, and there is no code to call it (what happened to your button? Your screen is blank and white because that's what an empty content view looks like. Your startAccelerometer function, if called, would call itself again and again until your program ran out of stack space and was terminated. You usually don't need a UIViewController in a SwiftUI app. Interfacing between SwiftUI and UIKit is an advanced topic. I suggest you take a step back and review a few simple SwiftUI projects so you can get the hang of drawing into a window and responding to clicks and drags inside a view. You should also try to learn about basic programming concepts like scope. Or, if you are just desperate to see what is going on with the accelerometer, here is a quick and dirty program which will print the results into the debugger console in Xcode on your Mac while the program runs on your phone. It is not a good example of app design (most code samples are not) import SwiftUI import CoreMotion struct ContentView: View { @State private var motionManager: CMMotionManager = CMMotionManager() var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .padding() .onAppear() { if motionManager.isAccelerometerAvailable { motionManager.accelerometerUpdateInterval = 0.1 // 10 updates per second motionManager.startAccelerometerUpdates(to: .main) { (data, error) in guard let accelerometerData = data else { return } let x = accelerometerData.acceleration.x let y = accelerometerData.acceleration.y let z = accelerometerData.acceleration.z // Process the x, y, and z acceleration values here print("X: \(x), Y: \(y), Z: \(z)") } } } } }
Aug ’25