Search results for

Swift 6

49,196 results found

Post

Replies

Boosts

Views

Activity

Seeing some behaviour in Swift that I don't understand...
It's related to the passByValue nature of structs. In the sample code below, I'm displaying a list of structs (and I can add instances to my list using Int.random(1..<3) to pick one of two possible predefined versions of the struct). I also have a detail view that can modify the details of a single struct. However when I run this code, it will instead modify all the instances (ie either Sunday or Monday) in my list. To see this behaviour, run the following code and: tap New Trigger enough times that there are multiple of at least one of the sunday/monday triggers tap one of the matching trigger rows modify either the day, or the int expected: only one of the rows will reflect the edit actual: all the matching instances will be updated. This suggests to me that my Sunday and Monday static instances are being passed by reference when they get added to the array. But I had thought structs were strictly pass by value. What am I missing? thanks in advance for any wisdom, Mike struct ContentView: View { @State v
Topic: UI Frameworks SubTopic: SwiftUI Tags:
1
0
181
2w
Learn to code / beginner
Hello everyone, I’m completely new to programming and Apple development, but I’ve always had the strong wish to learn coding and to work more deeply with Apple’s system structures. My main questions are: How should I best start learning? For example, is Swift Playgrounds the right first step? How should I continue afterwards to gain further knowledge, possibly in areas like system architecture, cybersecurity, or cloud computing (even though I don’t want to commit too early to one direction)? Can you recommend a learning schedule or intensity (e.g., how often per day or week I should practice) for someone who works full-time? Is my current MacBook Air (2020, Intel i3, 8 GB RAM, 250 GB SSD) still suitable for learning and beginner development, or would you recommend upgrading to a newer model? On top of that, my English is not perfect yet – is it possible to improve it alongside learning coding? I’m very motivated to finally start this journey, even though I once turned down an IBM apprenticeship when
4
0
139
2w
Swift Package Fails iOS Validation
My app (called MuVis - Music Visualizer) passes the macOS App Store verification, but is failing the iOS verification. The errors indicate a problem with the Swift package github.com/Treata11/CBass. I have been in touch with the CBass package developer (Treata11) as well as the original BASS developers (un4seen.com). We think the problem is related to CBass swift-package config (which apparently works fine for mac, but doesn’t for iOS). The source code for the package is at the site package. All of us think that the package is configured correctly in accordance with the latest Apple package development documentation. Please tell us what is wrong with this package, and how to make it pass the iOS App Store verification. The Xcode error messages from validation testing include several items similar to: Upload Symbols Failed: inline-code The archive did not include a dSYM for the bass.framework with the UUIDs [18D5DBE2-3250-3EDE-B75C-D81B4E9F05AC, A88554A0-9087-3776-AC05-424B2D52F973, DEB682F5-
1
0
97
2w
Reply to mapkit js erro 401 Unauthorized
authorizationCallback:function(done) { // 注意这里不能 async done(eyJraWQiOiI3OVNYVEdIOU45IiwidHlwIjoiSldUIiwiYWxnIjoiRVMyNTYifQ.eyJpc3MiOiIzSzQ4UEE2MjRNIiwiaWF0IjoxNzU1ODAwMDAyLCJleHAiOjE3NTY0NTA3OTl9.qUD9RUV7oC6LAo1KmpDCst-CUyEvz1Lbk5ZPt4E3E0z0q_lFoES8YsJGdSc4_UV405XyCaBfyFNBP-BlKZzQew) }, language: zh-CN, }); // 使用的方法 async function getCurrentLocation() { if (!navigator.geolocation) { error.value = 您的浏览器不支持地理定位; return; } try { await mapTokenManager.initializeMapKit(); map = new (window as any).mapkit.Map(mapContainer.value); } catch (err) { error.value = 地图初始化失败; console.error(err); } isLoading.value = true; error.value = ; navigator.geolocation.getCurrentPosition( (position) => { currentLocation.value = { latitude: position.coords.latitude, longitude: position.coords.longitude, accuracy: position.coords.accuracy, timestamp: position.timestamp }; // 在地图上显示位置 if (map) { const coord = new (window as any).mapkit.Coordinate( position.coords.latitude, position.coords.longitude ); map.setCenterAnimated(coord); //
2w
Xcode 26 betas not work working
Hi all, I'm trying to install the Xcode 26 beta on Tahoe (M4 Mac mini). I tried the latest beta 6 both the universal and the apple silicon version, but at startup the system says the app is corrupted and will be deleted. I tried this multiple times - always with a fresh download. Then I downloaded the beta 5, which told me at startup that there is no macOS SDK available and then Xcode also quits. I want to update/test my macOS apps for the upcoming Tahoe and want to adapt for the new design. On my Mac is the Xcode version 16.4 installed and this is working correctly. In the last years I started with earlier versions of Xcode betas, but this year I'm a little bit more late. Are there any steps I missed or is this a known issue yet? I had never before so much trouble installing any beta. What can I do? Best regards, Jürgen Terpe
1
0
131
2w
iOS 26 @FocusState Doesn't Work If TextField Is In Toolbar
When I add a TextField with @FocusState to a toolbar, I noticed that setting focus = false doesn't cause the form to lose focus If I move the TextField out of the toolbar setting focus = false works fine. How can I unfocus the text field when the cancel button is tapped? Minimal example tested on Xcode Version 26.0 beta 6 (17A5305f): import SwiftUI struct ContentView: View { @State private var text: String = @FocusState private var focus: Bool var body: some View { NavigationStack { List { Text(Test List) } .toolbar { ToolbarItem(placement: .bottomBar) { TextField(Test, text: $text) .padding(.horizontal) .focused($focus) } ToolbarItem(placement: .bottomBar) { Button(role: .cancel) { focus = false // THIS DOESN'T WORK! } } } } } } #Preview { ContentView() }```
0
0
180
2w
Reply to iOS folder bookmarks
I figured out some further details: When I get a file or folder URL from the picker, I need to call startAccessingSecurityScopedResource on it first prior to converting it to a bookmark. If I don't do that and try to convert that URL to a bookmark, I am seeing this error in the console: [ERROR] getattrlist(/7{34}3/D{7}s/2{8}2/N{2}1/0{8}7/1{6}3/2{69}0.png) = 1 However, the call to make a bookmark: url!.bookmarkData(options: [], includingResourceValuesForKeys: nil, relativeTo: nil) doesn't return an error. Basically, yes, that all makes sense in terms of what's happening in the lower-level system. The situation isn't something I can easily describe, but the practical description is that the way the iOS's different file access control systems overlap means that your code can end up working that really shouldn't work. A few quick suggestions here: If it's feasible, I'd recommend testing your code as a native macOS app (not the simulator or in compatibility mode). macOS is better at enforcing the right be
Topic: App & System Services SubTopic: Core OS Tags:
2w
Reply to Where's the replacement for Quartz Debug?
Hello, Quartz Debug is available as an additional tools package for Xcode. For example, Additional Tools for Xcode 26 beta 6 contains: This package includes audio, graphics, hardware I/O, and other auxiliary tools. These tools include AU Lab, OpenGL Driver Monitor, OpenGL Profiler, Pixie, Quartz Debug, CarPlay Simulator, HomeKit Accessory Simulator, IO Registry Explorer, Network Link Conditioner, PacketLogger, Printer Simulator, 64BitConversion, Clipboard Viewer, Crash Reporter Prefs, Dictionary Development Kit, Help Indexer, and Modem Scripts.
2w
Foundation model adapter assets are invalid
I've tried creating a Lora adapter using the example dataset, scripts as part of the adapter_training_toolkit_v26_0_0 (last available) on MacOs 26 Beta 6. import SwiftUI import FoundationModels import Playgrounds #Playground { // The absolute path to your adapter. let localURL = URL(filePath: /Users/syl/Downloads/adapter_training_toolkit_v26_0_0/train/test-lora.fmadapter) // Initialize the adapter by using the local URL. let adapter = try SystemLanguageModel.Adapter(fileURL: localURL) // An instance of the the system language model using your adapter. let customAdapterModel = SystemLanguageModel(adapter: adapter) // Create a session and prompt the model. let session = LanguageModelSession(model: customAdapterModel) let response = try await session.respond(to: hello) } I get Adapter assets are invalid error. I've added the entitlements Is adapter_training_toolkit_v26_0_0 up to date?
2
0
188
2w
Equatable with default actor isolation of MainActor
I filed the following issue on swiftlang/swift on GitHub (Aug 8th), and a followup the swift.org forums, but not getting any replies. As we near the release of Swift 6.2, I want to know if what I'm seeing below is expected, or if it's another case where the compiler needs a fix. protocol P1: Equatable { } struct S1: P1 { } // Error: Conformance of 'S1' to protocol 'P1' crosses into main actor-isolated code an can cause data races struct S1Workaround: @MainActor P1 { } // OK // Another potential workaround if `Equatable` conformance can be moved to the conforming type. protocol P2 { } struct S2: Equatable, P2 { } // OK There was a prior compiler bug fix which addressed inhereted protocols regarding @MainActor. For Equatable, one still has to use @MainActoreven when the default actor isolation is MainActor. Also affects Hashable and any other protocol inheriting from Equatable.
3
0
1.1k
2w
Reply to Xcode won't execute code?
Thank you for your help! I put this code above the code already mentioned. inline-code struct ContentView: View { var body: some View { Button(Tap Me) { // Action to perform when the button is tapped print(Button was tapped!) startAccelerometer() } } func myFunction() { // Your Swift code to be executed print(myFunction was called!) } } `inline-code` I get an error message saying: Cannot find 'startAccelerometer' in scope
2w
Reply to Icon Composer: Any way to add icons to the app bundle for older macOS versions?
Well, I don't know what I'm doing wrong. I'm using Xcode 26 Beta 6 on a macOS 26 Beta 6 VM, with macOS 15.6.1 as the host. I can build the TahoeIconsTest project, pointed to by @superpixel, and it works just as expected, the LG icon is used on macOS 26 and the old icon is used on 15.6.1. I do note that the .icns and .icon files are not in the app bundle , but there is a .car file. The Info.plist only has CFBundleIconName set (to AppIcon). However, I'm just not able to replicate this outcome with my own app. I added the secret flag and all the other asset compiler options are the same as the test project. But my build has all three files, .icns, .icon, and .car in the bundle, and my Info.plist file has both CFBundleIcon* parameters set to AppIcon. The result is both OSs use the old icon. I just can't see what's different.
2w
How do you observe the count of records in a Swift Data relationship?
What is the correct way to track the number of items in a relationship using SwiftData and SwiftUI? Imagine a macOS application with a sidebar that lists Folders and Tags. An Item can belong to a Folder and have many Tags. In the sidebar, I want to show the name of the Folder or Tag along with the number of Items in it. I feel like I'm missing something obvious within SwiftData to wire this up such that my SwiftUI views correctly updated whenever the underlying modelContext is updated. // The basic schema @Model final class Item { var name = Untitled Item var folder: Folder? = nil var tags: [Tag] = [] } @Model final class Folder { var name = Untitled Folder var items: [Item] = [] } @Model final class Tag { var name = Untitled Tag var items: [Item] = [] } // A SwiftUI view to show a Folder. struct FolderRowView: View { let folder: Folder // Should I use an @Query here?? // @Query var items: [Item] var body: some View { HStack { Text(folder.name) Spacer() Text(folder.items.count.formatted()) } } } The above cod
1
0
111
2w
Reply to iOS folder bookmarks
I figured out some further details: when I get a file or folder URL from the picker I need to call startAccessingSecurityScopedResource on it first prior to converting it to bookmark. If I don't do that and try to convert that URL to bookmark I am seeing this error in the console: [ERROR] getattrlist(/7{34}3/D{7}s/2{8}2/N{2}1/0{8}7/1{6}3/2{69}0.png) = 1 however the call to make bookmark: url!.bookmarkData(options: [], includingResourceValuesForKeys: nil, relativeTo: nil) doesn't return an error. For a folder URL it's even less visible: no error from the call (same as for file URL) but also nothing in the console as a hint. Later on (perhaps on a different lunch) when I read a bookmark (file or folder) I don't need to call startAccessingSecurityScopedResource on it (not sure if that's intentional behaviour or not).
Topic: App & System Services SubTopic: Core OS Tags:
2w