/r/iOSProgramming

Photograph via snooOG

A subreddit to discuss, share articles, code samples, open source projects and anything else related to iOS, macOS, watchOS, tvOS, or visionOS development.

FAQ

About

There is an extensive FAQ for beginners. Please browse it first before asking questions that are answered there.

If you are looking to get started (iOS programming in general or some specific area), here are more relevant links for you:

  • Swift or Objective-C? if you don't know which language to choose. (New posts asking this will be removed)

Related Subreddits

Related Links

There's too many to list them all, however here's a convenient link to all programming guides at apple.com

Take note that this list is live and based on most frequent questions in posts will be updated with "quicklinks".

/r/iOSProgramming

132,559 Subscribers

5

Those top grossing QR Scanner Apps. Are they really making that much money?

I was checking the top grossing apps chart in US yesterday, there are still a lot of QR Scanner Apps with basic design and full of negative reviews. Some of them are new apps, published in 2022.

I'm honestly curious about this. Why do people pay for a QR scanner in 2023?

Edit: Source - https://app.sensortower.com/top-charts?category=6002&country=US&os=ios&date=2023-12-10&device=iphone

7 Comments
2023/12/10
04:59 UTC

2

Location push entitlement

I have requested the entitlement for more than 3 weeks and I still didn't get any response , how long would it take ?

I have even replied to the automated email 3 times with the case-id , but no response at all

0 Comments
2023/12/10
01:45 UTC

49

Is iOS programming hard now?

I'm hoping I'm having an anomalous experience. I haven't programmed for iOS in earnest since 2019 but I'm back in the thick of it now and... everything seems harder? Here are a few examples from the last week:

- I downloaded a ScreenCaptureKit sample app (here) and had to rearchitect the thing before I could understand what was happening. All the AsyncThrowingStream/continuation bits I find much more confusing than a delegate protocol or closure callback with result type.

- The debugger takes between 2 and 10 seconds for every `po` that I write. This is even if I have a cable attached to my device (and despite the cable attached, it is impossible to uncheck 'connect-via-network' from cmd+shift+2)

- Frameworks are so sugary and nice, but at the expense of vanilla swift features working. If I'm using SwiftUI property wrappers I can't use didSet and willSet. If I use a Model macro I can't use a lazy var that accesses self (later I learned that I had to use the Transient property wrapper).

- I wrote a tiny SwiftData sample app, and sometimes the rows that I add persist between launches, and sometimes they don't. It's as vanilla as they come.

- I just watched 'Explore structured concurrency in Swift' (link) and my head is swimming. Go to minute 8 and try to make heads or tails of that. When I took a hiatus from iOS, the party line was that we should judiciously use serial queues, and then dispatch back to the main thread for any UI work. That seemed easy enough?

I don't know, maybe I just need some tough love like "this stuff isn't that hard, just learn it!". And I will. I'm genuinely curious if anyone else is feeling this way, though, or if I'm on my own. I have been posting on twitter random bits looking for company (link), but I don't have much iOS following. What do you all think?

My personal iOS history: I wrote a decently popular app called Joypad in 2009-2010 (vid), obj-c before ARC, and did iOS off and on since then. My most legit iOS job was at Lyft. I feel like when I started with obj-c the language was actually pretty simple, and the effort towards improved approachability (Swift with lots of power and sugary DSLs) has actually made things harder.

49 Comments
2023/12/09
22:42 UTC

4

Introducing CrowdTranslate.io - Get your app translated by your users.

We'd like to introduce CrowdTranslate.io. - Designed for indie developers to easily localize their apps into other languages. The service leverages the power of crowd-sourcing, and is completely free as we try to make sure it meets the demands of users. We would greatly appreciate your feedback after giving it a try.

🎞️ Watch the video on: https://www.youtube.com/watch?v=HGBvLjFKGeI

👉 Try it today at www.crowdtranslate.io

https://preview.redd.it/9jdopop94c5c1.png?width=2648&format=png&auto=webp&s=400c8c5d49d81dcbb2310afd81465bee3a6111f6

0 Comments
2023/12/09
21:11 UTC

2

Ibdesignables deprecated UIKit doubt

In Xcode 15.1 rc it is mentioned that ibdesignables are deprecated and will be removed in the future, I have a bunch of old objc views with ibdesignables, and the solution given online is previews , can anyone shed some light on how to go about replacing this?

0 Comments
2023/12/09
19:43 UTC

3

Call me back option not available Apple enrollment company #appledeveloper

How did you guys solve the problem of not having the call me option being available for your Apple company enrollment . I messaged Apple several times but have gotten a response in over a week.

0 Comments
2023/12/09
12:03 UTC

0

What do you think about Swift's decline in popularity?

According to Tiobe Index, the usage rate decreased from 2.38 percent to 1.04 percent. Its popularity appears to have dropped by 70 percent. I started to wonder what the reason for this was, and the first thing that came to my mind was that programming is not native anymore, it is done as write once and run anywhere, so I decided to look at dart. Dart's usage is 0.5 percent, meaning Swift players have not switched to dart.

There are two options left: iOS programming is not as much work as it used to be, or programmers use C# and .net Maui, or use React Native and other JavaScript libraries.

I am eliminating C# .net Maui here. If we look at the increase in the popularity of JavaScript, which is currently in its infancy, it is likely that thanks to React Native and Ionic, Javascript has gained space from Swift and Java.

18 Comments
2023/12/09
10:49 UTC

58

I made a circular slider for my timer app

15 Comments
2023/12/09
09:55 UTC

1

A lightweight wrapper for lazily initializing UIViews

Hey! I recently published a small wrapper for views to initialize them lazily. It's better than using lazy var since you can conveniently wrap every place where you set up your views, such as setting delegates and constraints, and you don't need to manually check myView != nil. LazyView does this for you and even more!

Here are some key features:

  • Set a condition for when the view should be initialized.
  • Perform operations on the view only if it's initialized.
  • Describe complex lazy view hierarchies with an easy-to-use DSL so that when you initialize the most nested view, all required superviews are also initialized.

Check out the README!

For our company, it was quite useful since we measure the rendering time of our complex screens (or parts of screens), and this approach helped improve it.

I'm looking forward to receiving some feedback; it's very important to me. Also, if you like the project, please give it a star!

https://github.com/qstrnd/LazyView

1 Comment
2023/12/09
06:16 UTC

2

Seeking Apple's Official UIKit Guidelines for Edge-to-Edge Display on Modern iPhones

I recall that Apple released official UIKit guidelines for implementing edge-to-edge displays on iPhones without a home button (like the iPhone X), but I can't seem to find these guidelines now.

For example, in my case, I simply changed the auto layout bottom constraint (for Collection View) from being relative to the safe area to being relative to the superview.

Before

https://preview.redd.it/nuwyo9cpj75c1.png?width=325&format=png&auto=webp&s=da564ae4b759ecd6ecd027cdbde76b6ff98bad9e

https://preview.redd.it/6i0j4xjqj75c1.png?width=443&format=png&auto=webp&s=5c294754bd30d8e52bedb30d60bda4a09d4bfc2c

After

https://preview.redd.it/sg6rciesj75c1.png?width=325&format=png&auto=webp&s=2365d97b3a6d8c01b472bf8310d03f816c196ad1

https://preview.redd.it/obf6g0dtj75c1.png?width=443&format=png&auto=webp&s=4ec1ef51a0707b67d9777f2da476e77e72b4d5cd

Surprisingly, this worked without additional adjustments. I didn't even need to modify the contentInset of my collection view. I had anticipated needing to increase the bottom contentInset to allow scrolling past the safe area, but it seems everything is handled automatically.

Before deploying my solution to production, I want to fully understand the underlying mechanism.

Does anyone know where I can find the official guidelines regarding this?

Thank you.

1 Comment
2023/12/09
05:48 UTC

13

My App has been live for a week!

When do I get 1 million downloads?

It generates custom children’s stories based on inputs they choose.

I’m proud of it, still working on updates, tweaks and features.

Also, which ad platform is best to integrate so I don’t have to restrict access to features?

https://apps.apple.com/au/app/storytimeapp/id6470764061

6 Comments
2023/12/09
05:09 UTC

2

Can an app monitor battery levels and control charging? And, if I only want to add functionality to my own device (run a specific charge cycle, if charge falls below a specific threshold, can I run it within an IDE app, rather than make a full app?

2 Comments
2023/12/09
00:53 UTC

13

Fell into depression while studying Swift.

I feel like Mowgli finding himself in the Metropolis. Although, partly, it's more like the truth than an analogy. I live in a third-world country, and the level of education here still leaves much to be desired, but thanks to my knowledge of the English language, I've expanded my horizons and worldview quite well.

History of interest in programming: Two months ago, having an overall picture of programming in hand, I decided to delve into iOS development. My cousin, upon learning about my interest in programming, kindly provided me with everything I needed: a new MacBook, iPhone, courses, books, websites, YouTube channels, etc.

Start: The first thing I started with was learning the Swift syntax. I went through all the books, courses, etc. On this topic, even then, I needed to stop and ask someone for help or advice. Because I didn't understand anything at all. To this day, I still don't understand all these sophisticated phrases, explanations, and terms. Separate searches on Google for everything said above only confuse me.

Questions: Am I too stupid for this game? Should I start over and study 5th-grade math? Or is there some kind of Bible for ultra-beginners where everything is laid out step by step?"

45 Comments
2023/12/09
01:11 UTC

2

Where to Get Debugging Help

Hey, i'm working on an app thats rather unique and i'm currently spinning not knowing where i'm going wrong at.

I'm looking for help debugging, wondering if theres a niche community or something that would be able to assist (paid or unpaid). I'm currently reaching out to freelancers on fiverr.

2 Comments
2023/12/08
23:54 UTC

3

Is there a way to further optimize this CoreData write operation?

I have the following CoreData write operation code

    static func _update(context: NSManagedObjectContext, entityName: String, objectID: NSManagedObjectID, propertiesToUpdate: [AnyHashable : Any]) -> Bool {

        do {
            var updatedObjectIDs : [NSManagedObjectID] = []
            
            let batchUpdateRequest = NSBatchUpdateRequest(entityName: entityName)
            batchUpdateRequest.predicate = NSPredicate(format: "self = %@", objectID)
            batchUpdateRequest.propertiesToUpdate = propertiesToUpdate
            batchUpdateRequest.resultType = .updatedObjectIDsResultType
            
            let batchUpdateResult = try context.execute(batchUpdateRequest) as? NSBatchUpdateResult
            
            guard let batchUpdateResult = batchUpdateResult else { continue }
            guard let managedObjectIDs = batchUpdateResult.result else { continue }
            
            if let managedObjectIDs = managedObjectIDs as? [NSManagedObjectID] {
                updatedObjectIDs.append(contentsOf: managedObjectIDs)
            }
            
            if !updatedObjectIDs.isEmpty {
                let changes = [NSUpdatedObjectsKey : updatedObjectIDs]
                CoreDataStack.INSTANCE.mergeChanges(changes)
            }
            
            return true
        } catch {
            context.rollback()
            
            error_log(error)
        }
        
        return false
    }

I am using background context to avoid blocking UI.

However, its performance is very slow, compared to pure SQLite.

If I use it to perform sorting, by updating ordering column of 1500 records, it will take roughly 10 seconds to complete.

Do you have any suggestion, how I can further optimize it?

Thanks.

1 Comment
2023/12/08
19:10 UTC

3

App promotion through Google and Facebook ads

Hello devs, I am an indie dev looking to run ad campaigns to promote my iOS app. I am currently thinking of promoting via Google Ads and Facebook ads. Apple search ads is not an option as they are asking for some business tax ID which I don’t have.

I am currently inclined to start with Google Ads App campaigns as it doesn’t require any extra setup as I already have the required Firebase Analytics installed. What has been your experience with Google ads? Do you get good results? Also what about FB ads, any good experience with them?

8 Comments
2023/12/08
19:06 UTC

0

How to implement a simple feeback form ?

I recently came across the following feedback form while using Soundcloud. While the UI is simple to replicate, i was wondering what are the potential ways to implement it? would it require using firebase for instance to intercept the feedback/ use other platforms?

9 Comments
2023/12/08
14:36 UTC

2

Renewed a bunch of certificates on developer.apple.com but still getting this error before pushing the TestFlight.

3 Comments
2023/12/08
10:48 UTC

2

Any way to detect how many other devices are in the area using an app?

If my app idea involves the need to see how many other iOS devices are in the vicinity from one particular phone using the app, is that possible? Maybe via airdrop recognition?

4 Comments
2023/12/08
05:59 UTC

5

Anyone experience getting China ICP for app?

So my niche app makes about 30% of revenue from China. (This is despite using Firebase as our backend so users have to VPN.)

As of a couple of months ago China said it will now require apps to have ICP there - and Apple agreed to comply. I missed that news... apparently the deadline is April 2024, though there is no clear info about how soon Apple will delist apps from then. New apps listing in China already require having an ICP since October apparently.

I was thinking of making my app use on-device storage instead of cloud anyway as it is not of value for most users, so I can negate that aspect of requiring to have a local backend.

But I wonder if anyone here has gone through the ICP application process? Does anyone recommend a vendor for doing that?

7 Comments
2023/12/08
00:27 UTC

5

Do basic ads take time to index and give relevant downloads?

Hey,
I created a basic ad campaign 4 days ago with a 600$ budget and a pretty high CPI(6$) because I understood that this is how I will get my app to be indexed fast and receive a lot of downloads.
I plan to get the CPI down to around 1$(did this before and it worked okay).

I do receive a bit more downloads than usual(around 40 additional downloads a day or so) but I don't see an increase in sales which is weird because from organic downloads I get about 1 yearly sale for every 20 downloads.

Can someone who is a bit more experienced shed some light on the matter?
What should I do? I don't have a large budget and I don't want to waste money away.

Thank you all!

4 Comments
2023/12/07
23:01 UTC

2

Those who have implemented Apple Pay - your server for token auth - Stripe for processing, how would you diagnose code 50 error?

For some reason the token isn't getting set to my server. I get code 50 as a print error, but I can't seem to narrow it down. Do any of you have any idea?

    @objc func applePayButtonTapped() {
        print("Apple Pay button tapped")
        let request = StripeAPI.paymentRequest(withMerchantIdentifier: "merchant.medical.daylike", country: "US", currency: "EUR")
        request.paymentSummaryItems = [PKPaymentSummaryItem(label: "Script", amount: NSDecimalNumber(string: "1.00"))]
        print("Payment request details: \(request)")
        paymentContext = STPApplePayContext(paymentRequest: request, delegate: self)
        print("Presenting Apple Pay sheet")
        paymentContext?.presentApplePay()
        
        print("yesue")
    }
        
    func applePayContext(_ context: STPApplePayContext, didCreatePaymentMethod paymentMethod: StripePayments.STPPaymentMethod, paymentInformation: PKPayment, completion: @escaping StripeApplePay.STPIntentClientSecretCompletionBlock) {
        
        print("Apple Pay did create payment method")
        let paymentMethodId = paymentMethod.stripeId
        let amount = 100 // Example amount in cents (€10.00)
        
        createPaymentIntent(paymentMethodId: paymentMethodId, amount: amount) { result in
            
            
            switch result {
            case .success(let clientSecret):
                completion(clientSecret, nil)
            case .failure(let error):
                print("Error in creating payment intent: \(error.localizedDescription)")
                completion(nil, error)
            }
        }
        
        
    }
    
    func applePayContext(_ context: STPApplePayContext, didFailToCreatePaymentMethodWithError error: Error) {
        print("Failed to create payment method: \(error.localizedDescription)")
    }

    func applePayContext(_ context: STPApplePayContext, didCompleteWith status: StripePayments.STPPaymentStatus, error: Error?) {
        print("Apple Pay process didCompleteWith status: \(status)")
        if let error = error as NSError? {
            print("Error in Apple Pay process: \(error.localizedDescription), Code: \(error.code)")
        }

        print("Apple Pay process completed with status: \(status)")
        switch status {
        case .success:
            // Payment succeeded
            break
        case .error:
            // Payment failed
            break
        case .userCancellation:
            // User canceled the payment
            break
        @unknown default:
            fatalError("Unknown Apple Pay status")
        }
    }

My Prints

Apple Pay button tapped
Payment request details: <PKPaymentRequest: 0x14bde0f80; APIType: PKPaymentRequestAPITypeInApp, requestType: PKPaymentRequestTypeApplePay, requestor: PKPaymentRequestorDefault, countryCode: DE, merchantCapabilities: 1, currencyCode: EUR, shippingType: SHIPPING, applePayLaterAvailability: enabledshouldUseMerchantSession: 0, suppressTotal: 0, paymentSummaryPinned: 0, supportedNetworks: (
    AmEx,
    MasterCard,
    Maestro,
    Visa,
    Discover
), supportsCouponCode: 0, paymentSummaryItems: 1, requiredBillingContactFields: {(
    post
)}, >
Presenting Apple Pay sheet
yesue
Apple Pay process didCompleteWith status: error
Error in Apple Pay process: There was an unexpected error -- try again in a few seconds, Code: 50
Apple Pay process completed with status: error

0 Comments
2023/12/07
21:12 UTC

2

How to permanently delete a test app from app store

I created an app in App Store. I deleted it but it shows up in removed apps. Is there a way to permanently delete the app? It's a test app. Thanks.

2 Comments
2023/12/07
18:54 UTC

Back To Top