/r/swift
Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns.
Dedicated to the Swift programming language released by Apple. More info in the Swift Wiki.
Please, check the FAQs before submitting.
General Swift Discussion
irc.freenode.net #swift-lang
Cocoa/Cocoa Touch Discussion
irc.freenode.net #cocoa-init
Keywords: swift, swiftlang, ios, os x, apps, apple, mac, iphone, ipad
/r/swift
So Im doing the angela yu course on udemy and I am on the structures exercise currently. I feel as if I structured the code correctly however im not getting what i am supposed to. I posted the code and the errors i received but not really understanding what the errors are trying to tell me and the solutions to this exercise that im finding are just about identical to what i wrote but still not working so I am just confusion now. Can somebody with more experienced eyes help me please? TIA
Hey folks,
Tomorrow I’ve got interview for Mobile Software Development Engineer in Test role. What according to you - developers - should good SDET know about Swift to make good impression on technical interview/live coding? I’ve got over two years of experience in similar role but this will be my first live coding in swift and I’m looking for some advice. Thanks for any hints!
I use Apple Pay via Stripe SDK in my application. I even used it in previous versions and users make purchases from there. In the last version I sent, my application was rejected below. Apple Pay appears as a payment option for me, I asked my friends in Europe to check it, it appears for them too, but it is not in the image from the rejection. I could not understand this situation. What could be the problem? Does anyone know why Apple testers cannot see the Apple Pay option?
Hi, just made a course on iOS development, uses swiftui with firebase, also teaches how to add In App Purchases, submitting to testflight and App Store, if you would like to get free access drop me a Dm i can provide you with a coupon code, happy learning!
I'm currently working on a Carousel, which autoscrolls horizontally, with each image, when tapped, navigates to its respective viewcontroller.
I used a custom cell , with a collectionview in it, which uses a custom collectionview cell which has the image to be displayed.
However, as per the client's requirement, the dot indicators under the carousel, need to be as per the image attached. I've managed to work out with the default dot indicators. But it's a no from them.
How do I make this in swift?
I asked chatgpt and it said custom dot indicators are possible but I'm not able to wrap my head around how do I make it in the xib, as we're working with xib's in our project.
Any help or references to any tutorials in swift would be of great help.
Thanks in Advance.
New Api is now available for Android for LocalNotifications (iOS Support for this API is coming up soon).
You can now schedule & manage local notifications to run at anytime in the future, which will run regardless if the app is running, closed, or in the background.
You can use these apis for managing your app's calendar, scheduling events for your users, or scheduling reminders.
https://github.com/TheArchitect123/KmpEssentials
And please give a star on github if you can :)
Check out the documentation here:
Im looking to make an iOS game as a mini project to get me son into design work. The idea is to make a turned based tactics kind of game and I wanted to ask peoples opinion if swift is the right way to go or if its better to look into unity. I have an extensive background in software engineering, so im not too concerned about the learning curve related to either. But I have concerns if swift is going to be capable with sprite kit etc to create this kind of game. Essentially I don't want to waste a bunch of time learning swift to later learn it wasn't the right choice
I am currently fetching users via pagination but the issue is some how it is comes with duplicates and I cannot fetch how the duplicates comes....
Published private(set) var users = [UserItems]() // it is declared inside of viewModel
this is the struct from which I am getting users and paginating them
taking the users from the user that we declared in view model and showing the view
taking the users from the user that we declared in view model and showing the view
I want to tokenize a JSON, and I can't figure out how to handle escaped double quotes in a string.
if char == "\"" {
var value = ""
current += 1
char = characters[current]
while char != "\"", current < characters.count {
value.append(char)
current += 1
char = characters[current]
}
current += 1
tokens.append(Token(type: .string, value: String(value)))
continue
}
This will fail when the full string is "He said, \"Hello World!\""
.
Trying to get XCode cloud UI testing set up.
Locally my tests pass every time, but when triggering the a build on the same commit on XCode cloud, its 50/50 pass or fail.
Has anyone experienced anything like this or have any advice?
I want to make this nice “carousel” style Title text transition in the Nav bar when swiping between different screen sections, is it even possible? Basically need a text carousel + gradient layers of background color on top on the sides.
Hey Swift community,
I'm currently working on an app that needs to scan for Bluetooth Low Energy (BLE) devices, gather location data, and submit it to a server regularly—even when the app is in the background. Initially, I thought Background Tasks (via BGTaskScheduler
) would be a good fit for this, but after some testing, I'm running into several issues that make it feel unsuitable for my use case.
BGTaskScheduler
, and I've set up everything to handle network operations and BLE scanning in the background.BGProcessingTaskRequest
(requiring network), the system often delays or skips the task.beginBackgroundTask
, but this only works for a limited period and doesn’t solve the long-term background activity issue.BGTaskRequest
configurations like BGProcessingTaskRequest
and BGAppRefreshTaskRequest
, but the results are still inconsistent, and tasks don’t always fire as expected.Has anyone in the community encountered similar challenges when trying to implement long-running or periodic background tasks, especially for BLE scanning and location services? How did you work around iOS's strict background limitations?
Are there any other techniques or patterns to:
I’m open to ideas, whether it’s using some combination of local notifications, Core Bluetooth hacks, or server-triggered mechanisms. Right now, Background Tasks just feel too unreliable for the job.
Appreciate any insights you can share!
Thanks in advance 🙏
How is something like this done? https://www.typibara.com/
What kind of APIs does one need to use to place this on a screen, animating, playing sounds and create elements around the image that are usable?
Hey folks!
I’m looking for some options for managing code coverage in our CI that will preferably analyze new code in an MR and enforce a certain threshold of test coverage. Ie fail the pipeline if the code coverage in the new code is less than 80% for example.
I know that enforcing code coverage is not the best metric to use since anyone can write trash tests that cover lines of code with useless tests but I’m working with a team that isn’t used to writing tests at all and the codebase is in dire straights and if I can force them to at least write tests to start I can work on the quality as a second step.
I’m looking for something that isn’t too bloated, I’ve looked into sonarqube which is a nightmare to setup for iOS and that’s my last resort but wondering if any other folks on here may have used any other tools that aren’t as difficult to manage.
Doesn’t necessarily have to be the code coverage for the diff, but even just a way to make sure the code coverage doesn’t go below what it already is at based on the number of lines of code in the project.
Any ideas / help would be greatly appreciated!
Thanks!!
So I've been using PythonKit for python interop, which is pretty great. However, it isn't threadsafe. This isn't an issue if everything's running on a single thread, but as I consider adding more concurrency, it would be nice if I could set up a dedicated thread for python calls and dispatch all python calls to that thread. I initially attempted to do this as follows (this is only for cases where I don't need a return value).
//Global variable for python queue
let pythonQueue = DispatchQueue(label: "Python", qos: .userInteractive)
func runInPython(_ code: @escaping () -> Void) {
print("Running code in python queue...")
let item = DispatchWorkItem { code() }
pythonQueue.async(execute: item)
print("Dispatched")
item.wait()
print("Finished")
}
On testing, I find that this works about half the time and fails about half the time. When it fails, the second call to runInPython never gets past item.wait(). I'm guessing this is because the DispatchQueue is making a new thread for the second call, rather than reusing the original thread.
Given this issue, does anyone know if there's any way to guarantee that all code gets run in the same thread?
Thanks.
The VideoLite app seems using a WkWebView or some other UIView to load the YouTube website. When the app is pushed to background, the video is still playing. There is a movie_player element on the page to play/pause the video. But explicitly calling playVideo() on the element after app is put to background is not working.
When making a recording with an RPScreenRecorder, is there any way to tell it not to record the mouse? Or is there a different approach to making a screen recorder that I should consider? I only want to record the SwiftUI window.
Thanks.
import SwiftUI
@main
struct MenuApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
MenuBarExtra {
ContentView()
.frame(width: 300,height: 900)
}
label: {
Image(systemName: "car")
}.menuBarExtraStyle(.window)
}
}
import SwiftUI
import AppKit
struct ContentView: View {
@State private var hoveredItem: String? = nil
let numbers: [String] = Array(0...30).map { "\($0)" }
let color0021 = Color(hue: 0, saturation: 0, brightness: 0.2, opacity: 1)
let color0031 = Color(hue: 0, saturation: 1, brightness: 1, opacity: 1)
var body: some View {
List(numbers, id: \.self) { z in
Button(action: {})
{
Text(z)
.frame(width: 250, height: 40)
}
.background(hoveredItem == z ? color0031 : color0021)
.buttonStyle(.plain)
.onHover { isHovering in
hoveredItem = isHovering ? z : nil
if isHovering {
print(z)
}
}
}
}
}
import SwiftUI
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
NSEvent.addGlobalMonitorForEvents(matching: .mouseMoved) { e in }
NotificationCenter.default.addObserver(self,
selector: #selector(didBecomeKey),
name: NSWindow.didBecomeKeyNotification,
object: nil)
}
@objc func didBecomeKey() {}
}