Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
prom candy
Dec 16, 2005

Only I may dance

pokeyman posted:

My guess is you're getting tripped up by the scroll view's not having an intrinsicContentSize, so it ends up having zero height. Try making a UIScrollView subclass, override intrinsicContentSize to return contentSize, and then override contentSize to add a didSet observer that calls invalidateIntrinsicContentSize. Don't forget to set your scroll view to your new subclass.

Neat, I don't really know what contentSize or intrinsic contentSize is but it gives me some stuff to learn about tomorrow. Thank you!

Adbot
ADBOT LOVES YOU

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

prom candy posted:

Neat, I don't really know what contentSize or intrinsic contentSize is but it gives me some stuff to learn about tomorrow. Thank you!

You're welcome! intrinsicContentSize in particular is worth internalizing because it's fundamental to how Auto Layout works, and trying to go around it (e.g. with hardcoded width and height constant constraints) can bring unnecessary pain.

Siguy
Sep 15, 2010

10.0 10.0 10.0 10.0 10.0
Any SwiftUI wizards in here? I’m trying to learn by converting an old Mac utility I use (a glorified timer) to SwiftUI but I’ve run into a brick wall on an esoteric but essential feature.

The old app is a single window application with an URL scheme (appname://15) that can be used to change the timer.

I've attempted to recreate the old URL Scheme functionality using the new onOpenURL SwiftUI method, but whenever the URL Scheme triggers, the app opens a new window and I can't figure out how to stop that from happening.

Swift code:
var body: some Scene {
        WindowGroup {
            ContentView()
                .onOpenURL(perform: { url in
                    print("\(url)") // This is just debug code
                })
        }.commands {
            CommandGroup(replacing: .newItem, addition: { })
        }
    }
I don't mind if the new version of the app allows multiple timers, but the url scheme is definitely not intended to open up new windows every time it's used.

Anyone know how I stop onOpenURL from launching new windows or force SwiftUI to do a single window Mac app?

I'm converting the app specifically to learn SwiftUI, but if it's not possible to do this behavior in SwiftUI, I'm willing to mix and match in some AppKit code.

prom candy
Dec 16, 2005

Only I may dance

pokeyman posted:

You're welcome! intrinsicContentSize in particular is worth internalizing because it's fundamental to how Auto Layout works, and trying to go around it (e.g. with hardcoded width and height constant constraints) can bring unnecessary pain.

Oh okay I kinda understood this without knowing what it was called or how to affect it. Now I have a better understanding of the content hugging/compression resistance stuff. Your solution worked perfectly as well, thanks!

code:
class AutoSizingScrollView: UIScrollView {
    override open var intrinsicContentSize: CGSize {
        get {
            return contentSize
        }
    }
    
    override var contentSize: CGSize {
        didSet {
            invalidateIntrinsicContentSize()
        }
    }
}
Edit: I already used compression resistance again to get some labels to do what I want in a stackview, handy!

prom candy fucked around with this message at 15:04 on Mar 16, 2021

Siguy
Sep 15, 2010

10.0 10.0 10.0 10.0 10.0

Siguy posted:

onOpenURL problem

If anyone's curious, after some Reddit/StackOverflow help, I ended up switching to the poorly documented handlesExternalEvents method for my WindowGroup. Then I was able to use onOpenURL within my ContentView to handle the URL Scheme events without new windows popping open.

code:
var body: some Scene {
        WindowGroup {
            ContentView().handlesExternalEvents(preferring: Set(arrayLiteral: "pause"), allowing: Set(arrayLiteral: "*"))
        }.commands {
            CommandGroup(replacing: .newItem, addition: { })
        }.handlesExternalEvents(matching: Set(arrayLiteral: "*"))
    }

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Siguy posted:

If anyone's curious, after some Reddit/StackOverflow help, I ended up switching to the poorly documented handlesExternalEvents method for my WindowGroup. Then I was able to use onOpenURL within my ContentView to handle the URL Scheme events without new windows popping open.

code:
var body: some Scene {
        WindowGroup {
            ContentView().handlesExternalEvents(preferring: Set(arrayLiteral: "pause"), allowing: Set(arrayLiteral: "*"))
        }.commands {
            CommandGroup(replacing: .newItem, addition: { })
        }.handlesExternalEvents(matching: Set(arrayLiteral: "*"))
    }

Nice! I've not done much with SwiftUI yet so accumulating these gotchas will no doubt come in handy once I dive in.

For what it's worth, you can replace e.g. Set(arrayLiteral: "pause") with, as you might guess, an array literal: ["pause"]. The latter just calls the former, but it's more idiomatic.

Siguy
Sep 15, 2010

10.0 10.0 10.0 10.0 10.0

pokeyman posted:

For what it's worth, you can replace e.g. Set(arrayLiteral: "pause") with, as you might guess, an array literal: ["pause"]. The latter just calls the former, but it's more idiomatic.

Thanks. That felt wonky. I've been away from Apple land for a couple years and it's frankly shocking to return and realize how shallow the documentation is compared to other languages. I kept looking at the Set documentation and thinking "Where's the part that shows you ten different ways to create a Set like you get in the Rust or Ruby documentation?"

prom candy
Dec 16, 2005

Only I may dance
I want to make some kind of object that I can use to quickly access my app's colors and fonts, something like Styles.fonts.sansRegular(16) (returning a UIFont) or Styles.colors.lightText (returning a UIColor)

Is this a thing that people do or am I just trying to shoehorn web stuff into iOS? If it is cool to do this should I just use enums with static properties/funcs?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Yep people do that. There are tools that will autogenerate those types for you based on asset catalogs and resources, such as SwiftGen, if that sounds useful.

And yep, caseless enums with static func/var sounds legit.

KidDynamite
Feb 11, 2005

none of the legal folks can tell me what we should or shouldn't track to comply with the IDFA changes. I'm about to shut off all tracking and then get fired because number go down.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

KidDynamite posted:

none of the legal folks can tell me what we should or shouldn't track to comply with the IDFA changes. I'm about to shut off all tracking and then get fired because number go down.

I spent far too long trying to figure out if Awful.app "tracks users" by requiring a user identifier to log in and then letting you write posts associated with that identifier.

At one point I looked at a variety of seemingly adjacent apps (Reddit clients, Tumblr clients) and some listed nothing and others listed a lot.

Kind of a crapshoot.

prom candy
Dec 16, 2005

Only I may dance
With UICollectionViewCompositionalLayout does anyone have a nice way of defining and sharing layouts or individual sections layouts across their app? I have one screen that's built of a few different section layouts, and then another screen using completely different data that nonetheless wants the exact same section layouts as one of the sections from that first screen. I'm trying to think of a good way to share that code since it doesn't really fit into an object. I guess maybe subclassing NSCollectionLayoutSection and then setting up the items/groups/supplementary views within that class?

smackfu
Jun 7, 2004

I’m trying to do something I think should be supported natively but I can’t figure out... I have a list of currency values that have an amount and currency code. Like 800 USD or 700 EUR.

I want to print each value properly formatted using a NumberFormatter with currency style, like “$800.00” or “€ 700.00”. But it seems like currencySymbol is a property of the NumberFormatter, not something you pass when you format the value. So it seems like I need to create a new NumberFormatter for each different currency, and switch to the the appropriate one depending on the currency of the value. Am I missing something obvious?

Edit: after another day of playing with SwiftUI, my mistake was making any assumption about there being built in support for anything.

smackfu fucked around with this message at 23:10 on Apr 6, 2021

lord funk
Feb 16, 2004

smackfu posted:

I’m trying to do something I think should be supported natively but I can’t figure out... I have a list of currency values that have an amount and currency code. Like 800 USD or 700 EUR.

I want to print each value properly formatted using a NumberFormatter with currency style, like “$800.00” or “€ 700.00”. But it seems like currencySymbol is a property of the NumberFormatter, not something you pass when you format the value. So it seems like I need to create a new NumberFormatter for each different currency, and switch to the the appropriate one depending on the currency of the value. Am I missing something obvious?

Edit: after another day of playing with SwiftUI, my mistake was making any assumption about there being built in support for anything.

How much have you looked into localization? I think in this case you might want localizedString(from:number:), although, might want to look at some examples to see if it's what you need.

Having a pre-existing list of currency codes might require your own lookup table, though.

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE
Ok, it's 2021, so time for one of my every 5 year attempts to get things set up and develop toy iPhone apps.

...what's the current recommended set of tutorials for 2021 Swift + iPhone development?

commie kong
Mar 7, 2019

ulmont posted:

Ok, it's 2021, so time for one of my every 5 year attempts to get things set up and develop toy iPhone apps.

...what's the current recommended set of tutorials for 2021 Swift + iPhone development?

I’m enjoying LearnAppMaking.com

The demo projects are useful and it’s not a bunch of videos that you follow along with, but pages of well written instructions and explanations. You can end up copy+pasting code into places, but that’s up to you and the site explains what it does and why very clearly.

Not cheap at all tho: $99 for the developer courses.

There’s also the udemy course by Angela Yu that you can usually get for ten bucks or so. That’s also good, but less focus on coding and more on storyboards, which wasn’t what I was looking for. I haven’t checked recently, but don’t think there’s much SwiftUI in that course.

There’s also a free guide on hackingwithswift.com. That site is good and I end up there often via google searches. Same for raywenderlich.com


e: oh whoops, Apple also have tutorials: https://developer.apple.com/tutorials

e2: hate to post so much, but I want to add that awful.app is on GitHub, there’s lots of ways to contribute to it and you get real feedback from people that use it daily. So playing with that might hold your attention more than creating apps using tutorials. That’s been my experience

commie kong fucked around with this message at 01:07 on Apr 8, 2021

smackfu
Jun 7, 2004

The Apple SwiftUI tutorial wasn’t as good as I hoped. It seemed like it was more interested in showing a bunch of different topics than having a coherent path. Like drawing paths doesn’t seem that useful? And they started having you copy and paste a lot of code as it went on without really explaining it.

dc3k
Feb 18, 2003

what.

smackfu posted:

I’m trying to do something I think should be supported natively but I can’t figure out... I have a list of currency values that have an amount and currency code. Like 800 USD or 700 EUR.

I want to print each value properly formatted using a NumberFormatter with currency style, like “$800.00” or “€ 700.00”. But it seems like currencySymbol is a property of the NumberFormatter, not something you pass when you format the value. So it seems like I need to create a new NumberFormatter for each different currency, and switch to the the appropriate one depending on the currency of the value. Am I missing something obvious?

Edit: after another day of playing with SwiftUI, my mistake was making any assumption about there being built in support for anything.

Changing the currency code on a formatter works fine. Output is automatically localised based on the `.locale` property of the formatter.

code:
struct Currency {
    let value: Double
    let code: String
}

let formatter = NumberFormatter()
formatter.numberStyle = .currency

let currencies = [
    Currency(value: 800, code: "EUR"),
    Currency(value: 700, code: "USD"),
    Currency(value: 600, code: "CAD"),
    Currency(value: 500, code: "JPY"),
    Currency(value: 400, code: "HKD"),
]

currencies.forEach {
    formatter.currencyCode = $0.code
    print(formatter.string(from: NSNumber(value: $0.value)))
}
// Output:
// €800.00
// US$700.00
// $600.00
// JP¥500.00
// HK$400.00
I don't know if this is true anymore, but en_AU was broken at some point and would never localise the symbol unless the code was AUD. For all other currencies it would output the code next to the value, like USD700, EUR800, etc. :shrug:

dc3k fucked around with this message at 06:26 on Apr 8, 2021

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I might as well point out that NSDecimalNumber is bridged to Swift as Decimal, and it's a solid 30-40% easier to use too!

prom candy
Dec 16, 2005

Only I may dance
I have a singleton class that keeps track of active file uploads in my app. A user can start an upload from one section of the app and then gently caress off elsewhere and the upload should just continue chugging along. However in certain spots in the app I need to show how many uploads there are, overall progress, etc. At some point I'll probably have to add cancelation too. Anyway, I'm thinking the view controllers that need this info should be able to tap into it so that I'm not creating any tight coupling between the ActiveUploads class and whatever view controllers are interested in its data. I was thinking Combine might be a good solution to this, but after reading/watching some tutorials I'm not sure I really get the point or see the advantage of using it vs. just broadcasting notifications using NotificationCenter. For example, I want to be able to let whoever's interested know when the number of active uploads changes, when the progress of an upload changes, or when the status of an upload changes. Is there a benefit to using Combine for this? It seems like in a lot of the tutorials I've looked at they're using NotificationCenter.Publisher to accomplish essentially the same thing as NotificationCenter.addObserver so I'm not sure if I'm understanding it right. Is NotificationCenter the right way to handle situations like this or is it better for my consuming classes to more directly subscribe to ActiveUploads (and if so I guess using Combine to create one or more custom publishers within ActiveUploads would be the way to do it.

I'm also seeing a ton of talk about Combine in tandem with SwiftUI, am I wasting my time with it if I'm using UIKit?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
NotificationCenter would work, as would having some KVO-compliant properties on the singleton. In fact, if you're using OperationQueue, you already have a KVO-compliant property for numberOfOperations.

Combine can make publishers out of KVO-compliant properties if you want Combine involved. And I think Combine would work great with UIKit, though it's not strictly necessary of course. Just make sure to touch UI from the main thread.

prom candy
Dec 16, 2005

Only I may dance
I'm not using OperationQueue nor do I really know what it is but as usual from your answers there's another thread I can pull at, thanks! I haven't really done much with KVO either, I'll take a look and see if that would be a nicer way to manage this. A fun side effect of this is that I need these uploads to continue even if the app is backgrounded, and also after the uploads complete they need to fire off other API calls which in turn need to fire off other API calls and it sounds like OperationQueue may help with that. I'm also thinking I may just need to rearchitect some of this stuff so that the client is less responsible for all this orchestration after the file is uploaded.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
OperationQueue might not be helpful, just thought I'd mention it in case you were already using it.

If you're hoping to keep running in the background, you'll be subject to short and undocumented time limits (~seconds up to a couple minutes). Make sure to take a task assertion (UIApplication calls this a "background task" and NSProcessInfo calls it an "expiring activity") while you're working so you don't get terminated unceremoniously. https://developer.apple.com/forums/thread/85066 is the bible here.

To continue network activity while suspended (app process not running), you'll want a background URLSession. Not sure about triggering further API calls after a background session task completes though. I don't remember if your app will get to run in response to the background URLSession tasks completing. I'm almost certain you can't count on getting to run, even if you sometimes are. And you'll only get a few seconds. https://developer.apple.com/documentation/foundation/url_loading_system/downloading_files_in_the_background looks helpful, and some useful info at https://developer.apple.com/forums/thread/14855. Look for relevant WWDC videos too, last year had https://developer.apple.com/videos/play/wwdc2020/10063/ and head to https://asciiwwdc.com/ and search for e.g. URLSession, check out any video that sounds relevant.

prom candy
Dec 16, 2005

Only I may dance
Thank you! I think we're going to have to move some of the file coordination to the server and use S3 notifications or something rather than relying on the client to kick off all the post-upload tasks. If we can at least just finish the upload if the user backgrounds the app that should be a good start. My suggestion to just tell the user to keep the drat app open is not being well received.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
That sounds like the right approach.

prom candy
Dec 16, 2005

Only I may dance
So I'm working on this background uploading stuff and I'm at the point where I'm actually testing if the uploads continue in the background and it's all falling apart. A couple seconds after I put the app in the background I get this dump of errors:

code:
2021-04-14 16:53:47.454959-0400 [80205:7545374] BackgroundSession <A32D4A45-1603-4194-AE38-01D0F3C41EDE> connection to background transfer daemon interrupted
2021-04-14 16:53:47.455121-0400 [80205:7545374] BackgroundSession <A32D4A45-1603-4194-AE38-01D0F3C41EDE> connection to background transfer daemon invalidated
2021-04-14 16:53:47.457591-0400 [80205:7545372] [connection] nw_read_request_report [C6] Receive failed with error "Software caused connection abort"
2021-04-14 16:53:47.458428-0400 [80205:7545372] [connection] nw_read_request_report [C7] Receive failed with error "Software caused connection abort"
2021-04-14 16:53:47.460792-0400 [80205:7545372] Connection 8: received failure notification
2021-04-14 16:53:47.460889-0400 [80205:7545372] [connection] nw_flow_add_write_request [C8.1 x.x.x.x:443 failed channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] cannot accept write requests
2021-04-14 16:53:47.460943-0400[80205:7545372] [connection] nw_write_request_report [C8] Send failed with error "Socket is not connected"
I've googled the various errors in here but I'm not seeing a lot. One forums post suggested that "connection to background transfer daemon invalidated" could be indicative of a signing issue. I'm just running this on my phone via Xcode the way I always do. Has anyone seen anything like this before? I'm trying to upload to a presigned S3 url (it works fine if I keep the app in the foreground)

prom candy
Dec 16, 2005

Only I may dance
Huh, well interestingly the complete files are ending up on S3 so something else must be happening to cause the error.

Edit: nvm that was just small files finishing before the transfer was interrupted

prom candy fucked around with this message at 16:00 on Apr 15, 2021

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
No brainwaves from me, sorry. I do know that having a debugger attached will mess with all kinds of timeouts and resource limits, but it looked like you were checking the console so that's probably not it.

prom candy
Dec 16, 2005

Only I may dance
After even more checking it looks like even the large files are finishing (I was looking in the wrong bucket for them) so it might just be the debugger is sounding the "everything's ok" alarm

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I wonder if those console logs were announcing that your app has severed its (xpc?) connection with whatever daemon runs background URL sessions? Which would make sense as your app is being suspended.

KidDynamite
Feb 11, 2005

can y'all confirm for me that in ios 14.5 Settings>Privacy>Tracking "Allow Apps to Request to Track" is defaulted to off?

jabro
Mar 25, 2003

July Mock Draft 2014

1st PLACE
RUNNER-UP
got the knowshon


KidDynamite posted:

can y'all confirm for me that in ios 14.5 Settings>Privacy>Tracking "Allow Apps to Request to Track" is defaulted to off?

Mine was set to on. Never touched it before now when I turned it off. All the individual app settings were set to off though.

KidDynamite
Feb 11, 2005

jabro posted:

Mine was set to on. Never touched it before now when I turned it off. All the individual app settings were set to off though.

interesting I don't remember setting my phone to off. apple has rejected my app saying i don't use requestTrackingAuthorizationWithCompletionHandler: while using app tracking transparency but it's in app delegate's application(_:didFinishLaunchingWithOptions:) and running it on the simulator the alert shows up. running it on my phone even after deleting and setting Allow Apps to Request to Track to on it just pops into the completion handler saying it was denied. i appealed but there's been no response.


also number predictably went down and people are freaking out even after i explained it to them. fun times.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Some of those settings get cached for awhile, even between reinstalls. Might try deleting app, enabling things in Settings.app, rebooting phone, then build and run?

KidDynamite
Feb 11, 2005

pokeyman posted:

Some of those settings get cached for awhile, even between reinstalls. Might try deleting app, enabling things in Settings.app, rebooting phone, then build and run?

i tried that and no luck. used an old iphone and was able to get it to show up.

Froist
Jun 6, 2004

The other way of testing permission-based behaviours is to change your bundle ID temporarily for a test build.

TACD
Oct 27, 2000

KidDynamite posted:

can y'all confirm for me that in ios 14.5 Settings>Privacy>Tracking "Allow Apps to Request to Track" is defaulted to off?
I've read that this is dependent on whether the user has previously opted out of tracking (whatever the ad tracking setting used to be, I forget)

lord funk
Feb 16, 2004

I noticed that Xcode.app was 29 loving gigabytes, so I dug down and found that the .platforms take up most of that. So I tried deleting the AppleTV and WatchOS platforms, but Xcode complains that they're missing when you load it up and you have to reinstall.

Lame. I will never develop using those, so they're just going to take up >12GB of space for nothing.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Yeah, I really wish you could delete all the poo poo from Xcode you don't need.

Adbot
ADBOT LOVES YOU

prom candy
Dec 16, 2005

Only I may dance

Plorkyeran posted:

Yeah, I really wish you could delete all the poo poo from Xcode you don't need.

Same

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply