One TWO Many - Managers

How many Swift Managers?

So you have an App and all these great iOS Capabilities in the platform... each one seems to have a "manager" or "Service" class to control and oversee its functions. Is there a problem here...

Seems I need a manager-Manager. I'm getting really confused... and for my next trick... I'm going to try to use count all the managers at once... will it all work out?

Come back and find out... I counted on multiple days and somewhere between 4 & 8 would be the statistical range... as I rewrite this paragraph the exact number is 7.53.

Mono-Di-Poly Bifurcations

My first muzing on this lead me to create a taxonomy of managers...

Here is what I've come up with - please improve it...

___Manager - old skool completion handlers

_____Service - new Async/Await service

_______Subscription - new Combine Future/Promises


What do you think? Will it work?


David's Somewhat Conical Canonical Taxonomy of Managers of Currency for Concurrent usage in Software that is very HARD.

hmm... What do I use for a "service" that is concurrent... like HapticsManager.swift... I don't think it will have concurrency issues?

The military has the term Fire-And-Forget. Rethinking my list and applying the power of a TheTetraSaurous (plural thesauri)...
_____ Assistant

_____Utility

I think these go above the others in the cone of responsibility.

I ran into a bit of name clashing (titants not involved) with Apple and their use of Subscription in the CloudKit API over CKSubscription... Apple got there first... so I'm using CKProducer (as in actor, director, producer).



Canonical Conical Taxonomy of Managers of Concurrenacy
of Non-
Currency for Usage: -- in Software that is very HARD

And by HARD I mean brittle.

takes no personal responsibility ______ Assistant

reliable always on and ready for usage _________ Utility

say they do a lot, generally just passes calls to someone else ____________ Manager

returns with some very nice info that you could not generate yourself - saving much time _______________ Service

when you least expect it to explode, it implodes: messages sent automagically some of which you need __________________ Subscription

not only responsible but generally does a great job of providing for the well-being of your data needs _____________________ Producer

Calling a Friend...

So I've spent a few days reworking (without a net - no TEST) the APIManager ... morphing it into a classic Async/Await (like there is the neo-classical form) called FinnhubService. But all this work did not produce the desired effect - that my Stocks Portfolio App start behaving like it does inside my brain. Is it something I've done wrong <incredulously>?

What do I have to do... write UNIT test!?

Here's the questions I now have (in an unordered priority-free numbered list):

  1. How big should the Task block of code be...?

  2. What happened to the once upon a time @AsyncHandler?
    Async handlers introduce the ability to declare a synchronous actor function as an asynchronous handler.

  3. How do I extract myself from the pyramid of doom in Async-Land?

  4. When I use the Result outside of the Task block - Mr. Compiler complains that it is uninitialized ... when I try... things get really messy.

  5. How do I move my data from inside the Task block to the outside scope, this seems like it should be obvious - but it is not (apply copious Obvious-jitsu)?

Have you tried unit testing Async Code?

I really do not think my skills are up to the Async-Unit-Test... meaning mock the unit - so that it is not a randomly returning service... always behaves exactly as planned... what's the point?


Let's look at some code - <do NOT try this at HOME>

... it is at this exact moment that I wish I had iOS Ventura running on my old antiquated 2016 MacBook Pro... for in that parallel universe where Tesla stock is worth $10,000/share - I could use XcShot (but requires MacOS 13) so... I bet there is an older App... CodeShot! A small suggestion... in the About window - give a hint about how to use the App... in CodeShot's case I was grabbing a screenshot of my code... I should have copy/pasted the text of the code! Big difference! Learning curves - they are tough.

I start with HTTPClient because as an old-timer... it all comes down to the network protocol - right?! Well - the fact is we want a big Abstraction sitting on top of HTTP.

Do you think I could factor out the API personal Token a bit better? OK ... most are in comments from an easy copy/paste ... as reference.

In what universe is that Protocol FinnhubServiceable going to be useful - should I fill it out?


Ignorant and Plowing on...

Keep in mind... I don't really know what I'm doing here... For example - I've annotated the class FirstUseSetup with @MainActor - cause it reduced some compile errors at one time... doing it seemed like a no-cost OK thing to do... upon reflection, and not knowing what it means - yes it gives me ... pause for concern.

I guess it is the annotation that took the place of some early on beta -
@AsyncHandler code. Paul Hudson said - it just puts the execution back upon the main thread.


Quite a Stack ya' got there...

So that's a brief (detailed) overview (summary) of just one of my learning experiments attemping to read an API and cache that Stock data to iCloud. It aint working! ... YET!

Yes - I've got other stacks... doing similar things like reading from iCloud - or UserDefaults or some News API. Who said - just write an API and call it!