Swift is a powerful and intuitive programming language for Apple platforms and beyond.

Posts under Swift tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Swift Student Challenge Devices / Simulator preferred building device
For the SSDC submission, the app playground must run on Swift Playgrounds 4.5+ or Xcode 16+. Key questions: In Swift Playgrounds, is the app tested on iPadOS or macOS? In Xcode 16+, is the playground tested using Mac Catalyst, an iPad simulator, or an iPhone simulator? The submission form only mentions a simulator but doesn’t specify which one. Can I build an app primarily for iPhone (portrait mode), or is it better to focus on iPad (landscape mode) if that’s the expected testing environment in all cases?
0
1
343
3w
Swift, kevent, and wth?!?!?
I have this code: var eventIn = kevent(ident: UInt(self.socket), filter: Int16(EVFILT_WRITE), flags: UInt16((EV_ADD | EV_ENABLE)), fflags: 0, data: 0, udata: nil ) I looked at it and thought why do I have those extra parentheses? So I changed it to var eventIn = kevent(ident: UInt(self.socket), filter: Int16(EVFILT_WRITE), flags: UInt16(EV_ADD | EV_ENABLE), // changed line! fflags: 0, data: 0, udata: nil ) and then kevent gave me EBADF. Does this make sense to anyone?
0
0
153
3w
cell.textLabel?.text breaking if a number value is in an array
Hi the below array and code to output a list item works fine: var quotes = [ [ "quote": "I live you the more ...", "order": "1" ], [ "quote": "There is nothing permanent ...", "order": "2" ], [ "quote": "You cannot shake hands ...", "order": "3" ], [ "quote": "Lord, make me an instrument...", "order": "4" ] ] cell.textLabel?.text = quotes[indexPath.row]["quote"] However if I change the "order" values to be numbers rather than text like below then for the above line I get an error message in Xcode "No exact matches in call to subscript". Please could someone tell me how to make it work with the numbers stored as numbers? (I'm wondering if creating an any array type and using the .text function has caused a conflict but I can't find how to resolve) [ "quote": "I live you the more ...", "order": 1 ], [ "quote": "There is nothing permanent ...", "order": 2 ], [ "quote": "You cannot shake hands ...", "order": 3 ], [ "quote": "Lord, make me an instrument...", "order": 4 ] ] Thank you for any pointers :-)
2
0
371
3w
Won't compile/build after a "Clean Build Folder..." invoked
I have 2 versions of my app. This version I issued the "Clean Build Folder..." command. After doing so it will no longer compile/build. I've restored the directory to a copy prior to the Clean Build Folder with same result. The other version of this code will build and execute. Command SwiftCompile failed with a nonzero exit code /Users/martinwoscek/develop/iOS_switft_DEVELOP/FullScreenCamera-master-no_drivemonitor/AV Foundation/Base.lproj/LaunchScreen.storyboard: Encountered an error communicating with IBAgent-iOS. Showing Recent Issues . . . Command SwiftCompile failed with a nonzero exit code Command SwiftCompile failed with a nonzero exit code Build failed 2/11/25, 8:15 AM 1.4 seconds
4
0
200
3w
How to custom swift playground preview application ($title.app) window size
I used Swift Playground to develop application in Mac OS. Also using ZStack I used limited area in full page (using .frame(width: $, height: $)). However using command + R or clicking start button to see preview .app, while non resizing application my ZStack show as cutted. Please tell me how to set preview .app frame size as width, height... The buttom code is ContentView.swift code. @main struct ContentView: App { init() { MyFont.registerFonts() } // @StateObject private var audioPlayer = AudioPlayer() var body: some Scene { WindowGroup { NavigationStack { StartMenuView() .frame(minWidth: 594, maxWidth: 594, minHeight: 1142, maxHeight: 1142) .preferredColorScheme(.dark) // Dark Mod .statusBar(hidden: true) // Hidden Status Bar .edgesIgnoringSafeArea(.all) // Ignoring Safe Area } } .windowResizability(.contentSize) } } Thank you for reading. ![]("https://developer.apple.com/forums/content/attachment/8ad9f219-6caa-49bf-b8c3-e4b7c91ab40f" "title=image.png;width=1050;height=803") ![]("https://developer.apple.com/forums/content/attachment/395ee85e-9543-4bfd-9caf-3ce3c2ca8414" "title=image2.png;width=1104;height=973")
0
0
205
3w
Report a bug on Swift Playground, "Learn to Code 2" - "Seeking Seven Gems"
Hello folks, I'd like to report a bug in Swift Playground to Apple official dev team, it's in "Learn to Code 2" - "Seeking Seven Gems". The puzzle map can't be loaded, please check the following screenshot, My system environment: MacOS 15.3 Swift 6.0.3 (swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)) Swift Playground 4.6.2 Xcode 16.2 Hardware: MacBook Pro/M2 Pro/32G
1
1
285
3w
not work paragraphStyle in AttributedString
I tried to create a Text View using attributedString. I want to set the line height using paragraphStyle and return the Text, but paragraphStyle is not being applied. Why is that? extension Text { init?(_ content: String, font: StyleType, color: Color = .ppBlack) { var attributedString = AttributedString(content) attributedString.font = Font.custom(font.fontWeight, fixedSize: font.fontSize) attributedString.foregroundColor = color let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.minimumLineHeight = 16 paragraphStyle.maximumLineHeight = 16 paragraphStyle.lineSpacing = 0 attributedString.mergeAttributes(.init([.paragraphStyle: paragraphStyle])) self = Text(attributedString) } }
1
0
218
3w
[iOS, SwiftUI] UiRefreshControl.tintColor is not the same as given one
Hello! I'm trying to set a UiRefreshControl.tintColor: .onAppear { UIRefreshControl.appearance().tintColor = UIColor.systemBlue } But instead of I get The color in the second picture is a high contrast version of the first one. I can't understand why it works this way. I also tried the following. UIRefreshControl.appearance().tintColor = UIColor(red: 0, green: 0.478, blue: 1, alpha: 1) // doesn't work UIRefreshControl.appearance().tintColor = UIColor(named: "RefreshControlColor") // doesn't work, here set "High contrast" on and indicated Universal.systemBlueColor Perhaps I missed something?
0
0
117
3w
Contacts Framework Question
Hey, I would love to access the users Contact (ie. the Me Card) Apple recently released the Invites app and within this app you can find the users Contacts Photo. I tried to replicate this behaviour but I currently need to match based on a name or email or something else. I have no idea how to receive this data because when using the Invites app I only remember the app asking for Contacts permission and nothing else so far. let store = CNContactStore() let keysToFetch = [CNContactImageDataAvailableKey, CNContactImageDataKey, CNContactThumbnailImageDataKey] as [CNKeyDescriptor] let email = "test@test.de" let predicate = CNContact.predicateForContacts(matchingEmailAddress: email) do { let contacts = try store.unifiedContacts(matching: predicate, keysToFetch: keysToFetch) let imageDatas: [Data] = contacts.compactMap { $0.imageData } self.images = imageDatas.map { UIImage(data: $0) ?? UIImage() } } catch { print("Error fetching contacts: \(error)") } This is how I am retrieving the Image. MAYBE someone can help me out. Thank you so far ~ Flo
1
0
237
2w
Adding Markdown support in notes app
Hi guys, I’m making a simple note taking app and I want to support markdown functionality. I have tried to find libraries and many other GitHub repos but some of them are slow and some of them are very hard to implement and not very customizable. In WWDC 22 apple also made a markdown to html document app and I also looked at that code and it was awesome. It was fast and reliable (Apple btw). But the only problem I am facing is that the markdown text is on the left side and the output format is on the right in the form of html. I don’t want that I want both in the same line. In bear notes and things 3 you can write in markdown and you can see that it is converting in the same line. I have also attached example videos. So, I have markdown parser by apple but the only thing in the way is that it is converting it into a html document. Please help me with this. Also please look into the things 3 video they have also completely customized the text attributes selection menu. By default with UITextView we can only enable text attributes and it shows like this. By clicking more we get the complete formatting menu but not the slider menu which is more convenient. Please also help me this. I don’t know if I can provide apple file but it is from wwdc 22 supporting desktop class interaction
0
0
246
4w
Background App wake up when Live Activity Offline Push Arrived not reliable
we have three problem when using the push notification on Live Activity. 1. What is the specific callback strategy for the activityUpdates property in ActivityKit? We found that in actual user scenarios, there is a probability that we may not receive callbacks. From the community experience, there are some resource optimization strategies that do not perform callbacks. From this perspective, the explanation is kind of vague. Is there any clear feedback to understand why callbacks are performed/not performed? 2.what is the specific description of the wake-up strategy, when background app receive Live Activity offline start Push? From community experience, we can see that the system may wake up for a duration of 0-30s due to resource optimization strategies, or not wake up/not deal with it. Is there an official description of the wake-up strategy? or we also have to follow this description: Wake up of apps using content-available pushes are heavily throttled. You can expect 1-2 wakeup per hour as a best case scenario in the hands of your users. so this cannot be assumed to be a reliable wake-up on demand mechanism for an app. 3 How can we determine user have selected (allow or always allow) of the Live Activity permission? When we use real-time activity offline push, there are two system prompts in iOS: the first prompt : allow and disallow real-time activity the second prompt : always allow and disallow Is there an interface that can directly determine which permission the user has chosen (allow/always allow)? (By the way, we can get disallow status). At present, we haven't seen any interface in the official documentation/interface that can determine (allow/always allow). The difference here will affect the generation of Update Token. Without Update Token, we can not update our activity instance.
0
1
379
4w
Task cancellation behaviour
Hi everyone, I believe this should be a simple and expected default behavior in a real-world app, but I’m unable to make it work: 1. I have a View (a screen/page in this case) that calls an endpoint using async/await. 2. If the endpoint hasn’t finished, but I navigate forward to a DetailView, I want the endpoint to continue fetching data (i.e., inside the @StateObject ViewModel that the View owns). This way, when I go back, the View will have refreshed with the fetched data once it completes. 3. If the endpoint hasn’t finished and I navigate back to the previous screen, I want it to be canceled, and the @StateObject ViewModel should be deinitialized. I can achieve 1 and 3 using the .task modifier, since it automatically cancels the asynchronous task when the view disappears: view .task { await vm.getData() } I can achieve 1 and 2 using a structured Task in the View (or in the ViewModel, its the same behavior), for example: .onFirstAppearOnly { Task { away vm.getData() } } onFirstAppearOnly is a custom modifier that I have for calling onAppear only once in view lifecycle. Just to clarify, dont think that part is important for the purpose of the example But the question is: How can I achieve all three behaviors? Is this really such an unusual requirement? My minimum deployment target is iOS 15, and I’m using NavigationView + NavigationLink. However, I have also tried using NavigationStack + NavigationPath and still couldn’t get it to work. Any help would be much appreciated. Thank you, folks!
0
0
250
3w
[iOS, SwiftUI] Navigation Bar background is always hidden when navigation destination is TabView
Hello! I have a destination navigation which is TabVIew where each tab item is ScrollView. And when scrolling content of any of tab items is underneath navigation bar its background is always hidden. But at the same time tab bar background is toggled depending on scrolling content position. I expected it would work with TabView the same as with any other view. Is it supposed to work like that?
2
0
209
2w
Fatal Error in Swift Playground
Fatal Error in Swift Playground Description I'm experiencing a catastrophic error when importing Package Dependency in any Swift Playgrounds that has icon or name that caused the whole Playground won't work anymore with error messages below. I'm current running macOS Sequoia 15.3 (24D60) and Swift Playgrounds 4.6.1. They're all up-to-date. Reproduction Open Swift Playgrounds and and create a new project. Import a package dependency https://github.com/simibac/ConfettiSwiftUI.git Rename the project and add an icon Then you should able the reproduce the problem. I strongly believed that this is a serious bug. You'll find that Assets in the left column are disappeared and appeared Assets.xcassets, you're unable to reveal the Dependency in the column like the reference picture above. The whole Playground is destroyed now and unable to work anymore.
2
0
338
4w