/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
Hey guys, I apologize if this is not the right place to post this. I'm somewhat desperate at this point, as I'm trying to find receipts of my historical app ranking data for my YC application.
In a nutshell: I started publishing apps to the App Store at age 11 (over a decade ago) and a number of them hit top charts, for differing categories, in multiple different countries. Many were also featured on the front page, in Apple Stories, and some even had bulk education institution purchases.
Unfortunately, I was far too young to think about saving any of this data.
AppAnnie used to offer a free service to find this data in a super easy-to-consume fashion. You could select any app from a list and it would show your rankings, for all countries, sorted by highest rank. I figure that developers here might be actively utilizing services that may have this feature as well.
Here's an example screenshot of the sort of data view I'm looking for:
AppAnnie's (discontinued) data view for highest ranks in all countries and categories
As you can see, it was super easy to consume what ranks were reached in what countries, how many hit Top 1/5/10 and for which category.
To make matters even more complicated, I sold a small fraction of these apps to other parties, and so they are no longer connected to my account. Thus, viewing apps connected to my account will not solve 100% of my problems, but it would be a start. Unfortunately, these apps also happened to be my most impressively-ranked products, and so they are relevant. (For any developers reading in the future, never do this. I regret selling them every day.)
Here are the services that I've tried so far:
I would very much appreciate any insights that people can provide. Thank you!
^(Posted to) ^(iOSProgramming) ^(as well.)
Hi all,
I'm developing a side project and I"m having a bit of an internal debate with myself on the best way to handle my data layer to keep it it simple but testable.
I have worked professionally with several architecture over the years (MVC, MVVM, VIPER and pseudo TCA) and I'm kinda experimenting with the MV approach too. To keep things simple this is overall what I have and the operations I'm planning to do:
- App in SwiftUI + Firebase
- Have an entity named "Person" with several properties that conforms Identifiable, Codable and Equatable.
- As part of the common interactions I'll have a few operations:, including create a new person, edit or fetch a person or list of people.
Now the dilemma: Where to handle those operations? following MVVM likely I would just have a view model for the view that will do any of the operations and in there either interact with Firebase for the operation or to talk to "FirebaseService" class that handle all the operations with Firebase. Alternatively I could have some use cases and interactions following a VIPER approach.... but what about just including those operations directly in the model? (VM pattern?"), in which case would look like this:
struct Person: Identifiable, Codable, Equatable {
// 1-. My properties, enums, coding keys etc
// 2-. Operations (create/fetch...) ->
i.e:
static func saveToFirestore(person: Person) async throws {}
}
The main benefit I see is the simplicity to access to any related operations while keeping operations linked to the model itself not to the view, however the biggest negative I could see are the issues to setup different environments and use dependency injection due the static methods..
Thoughts?
I've been developing iOS apps for about a year now, and I'm curious whether it's worth learning UIKit or if I should just focus on getting better at SwiftUI.
What do you guys think?
let input =
"""
8 11 13 14 15 18 17
43 44 47 49 52 52
"""
/// I am trying to make each line an array of ints, so
[[8, 11, 13, 14, 15, 17], [43, 44, 47, 49, 52]]
I have done:
let numbers = input.components(separatedBy: .newlines)
but this then returns :
"8 11 13 14 15 18 17"
and I feel like I am running in circles parsing out whitespace, getting stuck because then it becomes one large Int. How to preserve the human read number?
Any guides or suggestions welcome. Wondering if I should be using python for some of these problems I am working on....
Hey guys, I usually Post in the other sub for my Check-in, but I reached an impasse so I just thought I ask here.
I didn’t need any hints of u/twostraws, meaning I understood that myself. Yet I don’t write code that compiles(parses?runs?)
The idea is to write a function that finds out the square root of an integer, whereas I was not allowed to use sqrt and I should only consider whole Int as roots, otherwise throw an error.
This is what I came up with (apologies for the formatting, I am on mobile)
enum outOfBounds: Error { case tooBig, tooSmall }
func findSquareroot(_ number:Int) throws -> Int {
if number > 10000 {throw outOfBounds.tooBig}
for i in 1...100{
if i*i == number {
return i}
//("The Squareroot of (number) is(i), because (i) x (i) equals (i*i)"); break}
else if i*i != number {continue}
else {throw outOfBounds.tooBig}
}
do {
let result = try findSquareroot(number)
print ("Result achieved, it is \(result)")} catch {print("Squareroot is irregular or out of Bounds")
}
} findSquareroot(25)
The last one is not part of the function, just a trial if it worked. Which it did not. Why?
Edit: I get the following error message: call can throw it is not marked with try If XCode fixes it, it makes try findSquareRoot(25) but that seems wrong? I want to call the function, not have the trial be part of it. When XCode makes it, it also doesn’t accept it because now it doesn’t return an Int.
Another Edit: I commented out a part because that was a String which the function doesn’t allow, I’d still like to know how to run that, though I guess it belongs in the error handler
I am working on developing a front end launcher for Mac emulators. Development has been offline so far but I am looking for contributors. Does GitHub lend to a good tool for collaborative development, specifically regarding Swift? How does one go about founding Swift contributors?
Yup, we've all been there. We want a 'music' icon, but what's available is 'headphones' or 'speaker.' I fixed the problem -- now you can use natural language to search through SF Symbols. It's available for free on the app store.
Here's the story behind it: https://x.com/mansidaksgh/status/1861637411089850807
Would love y'alls feedback :
Hi, Combine noob here. Here is a unit test that demonstrates what I am trying to achieve:
import XCTest
import Combine
final class CombineTests: XCTestCase {
func testPassThroughSubject_whenSendBeforeSubecribing_theSubscriberReceivesAValue() {
let sut = PassthroughSubject<Void, Never>()
var cancellables = Set<AnyCancellable>()
// First: send
sut.send(())
// Then: subscribe
let expectation = expectation(description: "Subscriber receives a value")
sut
.sink { expectation.fulfill() }
.store(in: &cancellables)
wait(for: [expectation], timeout: 1)
}
}
I've read somewhere that publishers will only emit values once they are subscribed to, and my naive interpretation of that is that this test should pass. But it fails - the expectation is never fulfilled. (The inverse test (swapping around the send and subscribe) works fine.)
In my real code situation, I can't guarantee the order in which these operations occur (sending a value to the subject vs subscribing to the subject). I want to ensure that, regardless of which happens first, if both those conditions are eventually met, then the subscriber will receive the value that was sent. How do I go about that?
Ok, so I thought it was OK to store my cancellables in the method scope, but it seems like all that was needed to make my test pass was to store them in a class property. This test passes:
final class PublishSubscribeTests: XCTestCase {
private var cancellables = Set<AnyCancellable>() // NB: Store cancellables in class scope
func testPublishBeforeSubscribe_shouldTriggerSubscriber() {
let subject = PassthroughSubject<Void, Never>()
let expectation = expectation(description: "Subcriber should receive event")
subject
.sink { expectation.fulfill() }
.store(in: &cancellables)
subject.send(())
waitForExpectations(timeout: 1)
}
}
We're getting this weird crash infrequently, not sure if it's because data source was changed incorrectly. I searched for _Bug_Detected_In_Client_Of_UITableView_Invalid_Batch_Updates
but got nothing, all results said it's related to data source changing but the message seems different. Any help is appreciated! Thanks.
Hello!
I have a junior SDET interview coming up in swift and I have no idea what I should be studying. I’ve gone thru codecademys course on ios Development but not sure what else I should do. I’ve also set up XCUITest automation for my app. They said the interview would be over swift fundamentals and heavily focused on structs vs classes and knowledge of enums. Anything helps. Maybe a guide or a list of study questions.
Thanks
I am trying to make my code swift6 compatible. When I set "Strict Concurrency Checking" to "complete" I get the following error:
Passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure; this is an error in the Swift 6 language mode
for the this code:
class S6Class {
var number:Int = 0
init(){
Task{ //-- warning: Passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure; this is an error in the Swift 6 language mode
number += 1
}
}
}
Any suggest how to resolve this.
Thanks Reza
Hey everyone,
Recently built an app that got decent traffic coming to it and going into free trial. All US iOS users.
But most the uncanceled free trials go into a "Billing Retry" state on App Store Connect. If anybody has any ideas they want to share to solve this, it would be amazing.
Some things I tried:
- Doing $1 trials, and same thing happened (Billing Retry) after the $1 trial ended.
- Switched fully to RevenueCat instead of my own StoreKit2 implementation, problem still continued.
Just having a hard time thinking that 75% of US users would invalidate their CCs when almost no other app developer has this same issue online.
Hello fellow iOS enthusiasts. I'm currently taking Angela Yu's iOS course and am loving it thus far. The only issue is when it comes time for me to do some of the challenges, I hit a road block and feel stuck. It's so easy to get down on yourself and be self critical because I know I'm very capable of learning new things when I really put my mind to it and when I get stuck it makes me feel like I'm not cut out for this.
I'm so eager to learn the basics and start building a portfolio so that I can achieve my goal of getting my first job as an iOS dev in a year, so that's why thinking about going back to review past sections of the course bothers me because I want to grind through and move on to actually building my own projects.
At the same time I feel like it's a really bad idea to rush through this because I want to genuinely understand the principles and really lock them into my brain so that I can scale these fundamentals and do whatever my vision is for any given project I'm working on in the future.
I'm on a challenge now that I just can't crack and I would feel foolish if I just looked at the solution, but trust me this is the 4th session of me coming back to my computer and trying again and I just feel defeated. I'm sure every single developer goes through this or has gone through it so, any advice would be greatly appreciated.
Nothing worth doing is easy and I truly get that, I'll never give up. Just so easy to be hard on yourself...
Thanks for reading if you did,
Nick
Currently learning SwiftUI and the tutorial I am following can use the magnifying icon to zoom in on the preview canvas, and it will zoom in towards the middle. For some reason, mine will only zoom in towards the top left corner of the virtual canvas when zooming close up. Any way to fix this?
I've been working on an ML project in Swift, and through all of it, I've tried to ensure that it was as well optimized for performance as possible. Now, however, I'm actually trying a full scale test, and I'm seeing large memory leaks and seemingly constant severe hangs. I've tried using Instruments to see the root causes of the leaks and hangs, but I can't see anything that I understand. The framework is available on GitHub here.
If anyone is able to identify issues with my code that could cause it to run slow, or induce memory leaks, it is greatly appreciated.
Is there any C library for Swift that has the same features like Darwin/Glibc?
Hello my name is victor I would like to develop a productivity application that interacts with the reading of NFC and access the screen time api to make reports of the improvement of time of use of the phone, I would also like to know if you would have problems to access the parental control and that people can block applications while they are in focus mode.
My doubt lies in whether to do it with cross-platform technology or I would find too many problems when accessing native modules of swift sdk, I'm new to mobile any recommendation or help would be good.
Best regards
Hello everyone,
Well, that's my doubt. I've been practicing and trying to improve my skills by building a portfolio with some simple apps and I want to know if I'm ready or not to apply to JR roles. Is that difficult to code in live due to the nervousness? What kind of questions did the recruiters ask to you? What type of tasks did you have to do while you were a JR?
Thanks for reading me.
I'll be attentive to any suggestion.
Hi, I am trying to process all the images in my photo library. I have the following function:
func analyzeImages(_ inputIDs: [String])
{
let manager = PHImageManager.default()
let option = PHImageRequestOptions()
option.isSynchronous = true
option.isNetworkAccessAllowed = true
option.resizeMode = .none
option.deliveryMode = .highQualityFormat
let concurrentTasks=1
let clock = ContinuousClock()
let duration = clock.measure {
let group = DispatchGroup()
let sema = DispatchSemaphore(value: concurrentTasks)
for entry in inputIDs {
if let asset=PHAsset.fetchAssets(withLocalIdentifiers: [entry], options: nil).firstObject {
print("analyzing asset: \(entry)")
group.enter()
sema.wait()
manager.requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .aspectFit, options: option) { (result, info) in
if let result = result {
Task {
print("retrieved asset: \(entry)")
let aestheticsRequest = CalculateImageAestheticsScoresRequest()
let fingerprintRequest = GenerateImageFeaturePrintRequest()
let inputImage = result.cgImage!
let handler = ImageRequestHandler(inputImage)
let (aesthetics,fingerprint) = try await handler.perform(aestheticsRequest, fingerprintRequest)
// save results
print("finished asset: \(entry)")
sema.signal()
group.leave()
}
}
else {
group.leave()
}
}
}
}
group.wait()
}
print("analyzeImages: Duration \(duration)")
}
If I pass this an array with <100 or so image IDs, memory grows, but the function completes. When the function completes, all memory is freed. If I pass this with more than 100 images, memory grows and the app crashes. I added the semaphore to ensure that only two images are being processed simultaneously. But, when I use the memory analyzer in Instruments, there are a ton of 35MB IOSurfaces that haven't been freed. I'd have thought that at the end of each Task, the image being analyzed would be freed? Any thoughts/help?
Thx,
I've been following some swift guides, many focus on the beginner stuff and accessing the UI. I get this and feel like I could make something simple, but for the app I have planned I need to access the OS's display data. Is there a way to get access to the current displays? For example, I need to detect if there is a 2nd or third monitor and then be able to shift the focus to those displays when needed. Is this possible? I haven't exactly made a practical app like this before, especially on MacOS.
I'm not looking to have my hand held, but just a pointer in the right direction, because I can't seem to figure out where to start.
Hi guys, in the past few months I’ve tried to learn combine following countless tutorials and reading two books. I learned a huge amount of stuff but still I wouldn’t know how to use it and I don’t fully understand the code I write when following the guided projects in the book I’m reading now. It makes me fell bad about myself because I usually learn stuff much faster.
Is it just me or is Combine actually hard to learn?
Hello, my name is victor im traying to create productivity app, i need to interact with a nfc both to write on it and to read, im a bit lost as i dont know too much about mobile development (im a web developer) and well i would like some advice on these topics
-If I have the application open in the xcode emulator I understand that I need an nfc reader plugged to the computer to be able to read from the emulator?
-Recommendations for nfc readers and writers for computers?I was looking at this website which is where I purchased the NFC https://www.shopnfc.com/es/38-lectores-nfc-usb
-I need the NFC to interact with FamilyControls to block certain applications, if anyone has any advice I would appreciate it.
Thanks
I’ve integrated another SwiftUI iOS app with Firebase. Have several working correctly. With this one I’ve tried everthing
I don’t have any other ideas. No information is being sent to firebase.