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
lord funk
Feb 16, 2004

I was unclear: I am not against calling didSet after withUnsafeMutableBufferPointer. I just got real worried that Swift was trying really hard to save me from myself inside the block too.

So, just to be clear, this is okay? Or am I committing some unheard of horror.

code:
var a: [Int] = [1, 2, 3, 4, 5]

a.withUnsafeMutableBufferPointer{ p in 
    for i in 0..<p.count {
        p[i] = ...
    }
}

Adbot
ADBOT LOVES YOU

lord funk
Feb 16, 2004

Doh004 posted:

How concerned do I need to be that OpenGL has been deprecated for "2 years" now and won't work in iOS 14?

Where are you seeing it as "won't work" in iOS 14? I'm only seeing rumors.

lord funk
Feb 16, 2004

Doc Block posted:

Is there a reason you haven’t switched to Metal already?
Speaking as someone with OpenGL apps on the store for going on 10 years now, I haven't switched because it's a pointless rewrite of an entire graphics system with no benefit to my app. OpenGL isn't the bottleneck in my app's performance, and there is nothing gained by switching to Metal.

If this is true it just means a complete waste of time and effort to continue supporting an app that works perfectly fine.

lord funk
Feb 16, 2004

Doctor w-rw-rw- posted:

So yeah Apple probably would rather you just get onboard their ship since it's either them or you and they chose you.

Yeah, this is by far the worst part about developing for Apple. Instead of my platform supporting me, I support my platform. It's rear end backwards IMO.

lord funk
Feb 16, 2004

ultramiraculous posted:

Yeah it's kinda the nature of the platform, unfortunately. I wish sometimes that they'd at least offer the ability to boot up older versions of the OS for one purpose or another, like even just like spinning up a Corellium-y thing so you can run ancient OSes and play with apps that have since been purged from the App Store. There's definitely a value to looking forward rather than back all the time, but it's a trade off.

Looking forward / looking back are not mutually exclusive. Progress will be made whether apps are purged or not. You could freeze iOS and macOS for 5 years and it would make zero difference on whether new experiences would happen on the platform or not.

All I see is that Apple has zero respect for legacy software. They 100% subscribe to the idea that old == useless. But they forgot that old can equal classic, or vintage, or timeless.

lord funk
Feb 16, 2004

Okay... FileWrapper. Typically, an image file (like a PNG) gets loaded into an app as image data, using UIImage. So when it is saved and loaded, it tends to look like this:

code:
//save:
    override func contents(forType typeName: String) throws -> Any {
        let contents: FileWrapper = FileWrapper(directoryWithFileWrappers: [:])

        let image: UIImage = UIImage(named: "xyz.png")!
        let imageData: Data = image.pngData()!
        let imgWrapper: FileWrapper = FileWrapper(regularFileWithContents: imageData)
        imgWrapper.preferredFilename = "image.png"
        
        contents.addFileWrapper(imgWrapper)
        
        return contents
    }
code:
//load:
    override func load(fromContents contents: Any, ofType typeName: String?) throws {
        if let contentWrapper = contents as? FileWrapper {
            if let imageWrapper = contentWrapper.fileWrappers?["image.png"] {
                if let imageData = imageWrapper.regularFileContents {
                    let image = UIImage(data: imageData)
                }
            }
        }
    }
But in my app, my PNG file has already been saved to disk by Metal. I do not use UIImages at all, but rather point Metal to the PNG file to generate a MTLTexture.

Is there a way to skip UIImage, and instead just move the existing PNG into the FileWrapper? Also, when loading from the FileWrapper, is there a way to just point to the stored PNG file instead of allocating a data instance of it?

lord funk
Feb 16, 2004


Hmm seems like I should just be able to read into the package like a directory, no? And I guess I don't mind too much to waste the extra time allocating the UIImage during the save operation. Could be worse.

lord funk
Feb 16, 2004

Is it possible to set a file's icon from an app? I'm saving user documents, and would like each one's icon to use a screenshot of the doc (that is already part of the document). So, not a single icon, but each file gets its own?

lord funk
Feb 16, 2004

Dog on Fire posted:

Maybe this method? I’ve never done this so I don’t know which ... limitations it has.

Ooh, I'll look into that, thanks. Searching for 'custom file icons xcode' gets a million links about app icons, not files.

lord funk
Feb 16, 2004

Doctor w-rw-rw- posted:

Hah. That’s a very suggestive req. I have a feeling I know exactly what it’s going for, having gone down that route.
Fill us in for those of us who don't know? I'm just curious.

lord funk
Feb 16, 2004

Okay this gets me every time. Why does load(fromContents:type:) call in a UIDocument when you first create the document with save(to:for:completionHandler:)? It's like, you create this blank document, and then a second later it tries to load its contents?

edit: hmmm nope maybe there is something going on in my document that's causing this

edit 2: double nope, I am confused as hell. I made a blank test document class, and in my app it calls load(fromContents:type:) after save(to:for:completionHandler:). But in a new blank project, the same thing doesn't happen :confused:

solution: okay figured it out. If the file already exists at the fileURL, and you call save(to: fileURL for: .forCreating), it will load the contents. But if it's actually a new file, it won't.

lord funk fucked around with this message at 17:02 on Jul 19, 2020

lord funk
Feb 16, 2004

Finally got tired of SF Mono not having the U+203E 'overscore' character so I edited the font:

Before:


After:

lord funk
Feb 16, 2004

3D people, some advice.

I would like to draw 'letterbox' black bars on the top and bottom of my scene. One way I could do this is just do another render pass, and draw the black boxes on top of the already rendered 3D scene.

However, I think it would be better to simply stencil out the top and bottom. This would leave it black (yay!) and also skip any rendering underneath (performance!). And, I wouldn't have to load up another render encoder to draw the black bars (performance!).

My question is: how do I draw directly on the depth texture / stencil texture? In Metal, they are the same texture (which confuses me... why does the stencil texture show up black in the inspector?). I could blit copy in from another texture, but I'm not really sure how to do that if I also clear the depth texture on load.

lord funk
Feb 16, 2004

Doc Block posted:

They’re “together” because of legacy reasons (Depth24Stencil8 hardware formats), but people use 32-bit float depth buffers now with stencil existing in a separate texture and so it’s just done for convenience.

Anyway, the stencil test happens at the rasterization stage, so instead try to use scissor rects or a smaller viewport, so that geometry in those parts of the screen will just get clipped instead (skipping rasterization entirely).

👍🏻👍🏻👍🏻 scissor rects is exactly what I needed.

lord funk
Feb 16, 2004

frogbs posted:

I realize i'm just getting started with Swift, so everything is going to have a learning curve, but i'll be damned if I can't wrap my head around using Codable to parse even moderately complicated/nested JSON.

Yeah good luck. I just went through this a few weeks ago, and was surprised at how difficult heterogenous arrays were to encode / decode.

lord funk
Feb 16, 2004

I won't be getting a silicon Mac any time soon, but does this mean that Metal apps will run natively in the Simulator?

lord funk
Feb 16, 2004

Pulcinella posted:

Sorry just needed to vent. The start of learning new things is always the most painful.

Yeah one day I realized that doing all my layout in code means not having to go through growing pains every time the latest UI toolset comes along.

lord funk
Feb 16, 2004

Right. That falls under my general rule of: UI responders don't do anything but call functions that do stuff. Because inevitably that update needs to be triggered from four different sources.

lord funk
Feb 16, 2004

I'm a little surprised no one has mentioned the new Small Business Program. Getting a 15% increase in revenue is really a big deal, and I'm happy that Apple is doing this. Just got my notice today.

lord funk
Feb 16, 2004

jabro posted:

It’s actually a 21% increase in revenue!

Math! Good point.

lord funk
Feb 16, 2004

All I ever wanted was crash reporting. Crashlytics >> Fabric >> Firebase just became a sea of bloat that I didn't want any part of.

lord funk
Feb 16, 2004

I also don't get analytics. The one time I went to WWDC I was floored how often devs were talking about sales analytics. In the 11 years I've had stuff on the App Store I've looked up my total sales once.

lord funk
Feb 16, 2004

Y'all are smart, so maybe you can point me in the right direction here.

I have an audio thread running C code that references an array of floats (it's a sound waveform). I would like to update that array with new values from the Swift side / main thread.

code:
Main Thread:
[n,n,n,n,...] new [Float] values

AVAudioThread:
[o,o,o,o...] old float[] values
How does one do this in a thread safe way? Should I be writing to a separate array first, then setting a flag to say that it's ready? This is right at the edge of my thread knowledge.

lord funk
Feb 16, 2004

I think I'm headed towards the sophisticated techniques. Locks are pretty verboten in audio, and there's a link there to a circular buffer that I think is what I'm looking for.

lord funk
Feb 16, 2004

prom candy posted:

I don't, is there a better way if I want to do everything programmatically?

Subclassing is a fine idea. Alternatively you could make a label formatter object that you could pass them through.

lord funk
Feb 16, 2004

I guess maybe reuse of labels too. It might be fine if the only time you format them is initialization, but in a reusable view that might become an issue.

lord funk
Feb 16, 2004

Glimm posted:

Does anyone use Applanga or a similar tool to handle translations? Any thoughts on it?

I saw a demo from them recently and like most marketing demos it looked a little too good to be true, but still probably useful.

I don't know anything about Applanga, but I've used Applingua for translation before, and they did a good job.

lord funk
Feb 16, 2004

It'd be super nice if the App Store screenshot section actually told me which device produces the exact resolution they want instead of making me guess which of the 50 simulators is 5.5".

lord funk
Feb 16, 2004

Thanks, yeah I had to find a website to help out. It's just dumb that it's not at all clear in the actual screenshots area of App Store Connect.

Speaking of dumb complaints: thanks Xcode for giving me a warning for EACH AND EVERY OPENGL FUNCTION IN MY APP. Yes, I know it's deprecated. No, I'm not rewriting my graphics engine, and 695 warnings won't make me.

lord funk
Feb 16, 2004

Well gently caress. Looks like running my app on iOS 14 causes saved files to have data payloads of nothing because of deprecated keyed archiving. Awesome! Glad my data is more secure because of the move to NSSecureCoding!

gently caress.

lord funk
Feb 16, 2004

Just ran into the bug where network access permissions are missing, and there's no way to reset it.

I'm already annoyed at the barrage of permissions popups that happen when you open an app for the first time (great user experience!). But now I can't even get those to appear. Awesome.

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.

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.

lord funk
Feb 16, 2004

I mean, this is ridiculous. Last time I noticed the size was when it pushed passed 10GB. Suddenly it's 3x bigger? It's half of my entire Applications directory size.

But, you know, we should all be reducing our little mobile app sizes.

lord funk
Feb 16, 2004

While we're on the subject, don't put view creation in viewDidLoad, because the view is almost definitely not its actual size yet, which sucks for layout. That leaves viewWillAppear, which calls multiple times, but you can put an 'if view == nil { ... }' check in there for that.

lord funk
Feb 16, 2004

I kinda wish I learned VS years ago, because it seems like everyone really likes it. But I tried it for some Unreal development and just couldn't get over my Xcode habits, and found myself being pretty clunky.

Adbot
ADBOT LOVES YOU

lord funk
Feb 16, 2004

Data Graham posted:

It was perfectly fine when the trackpad was half this size.
I don't have a solution for you but I just want to say I have similar problems, this trackpad is too big, you're not the only one.

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