Swift

blamellors,

Swifties.
Stand back and stand by.

❄️ be tripping
#Swift #NFL #football #Kelce #taylor

amerika,

@Bunnyslope @wjmaggos @blamellors @nam

They are its ancestors, and so we can trace the patterns of this behavior to the present.

Kind of fascinating how the past is not even past, as some writer said once.

wjmaggos,
@wjmaggos@liberal.city avatar

@amerika @blamellors @Bunnyslope @nam

so what did it take to post to a newsgroup or bbs? and what exactly did meower do? I mean we even used to have to pay for phone minutes back then. and they'd be pissed you were using the line. it wasn't like keeping open a browser window all day to shit post. you claim it was some kind of cultural evolution when there were so many other factors. if people could key cars with drones with no repercussions, it would happen more. same number of assholes.

davidbures,
@davidbures@mstdn.social avatar

macOS programming question:

Is there a way to schedule a background task, so that the system executes it whenever it deems appropriate?

I want to create a func that will check for updates on a server. This is not a time-sensitive task at all, and I don’t want to waste system resources forcing it to fire every x minutes

I just want to tell the system „fire this task whenever you feel is appropriate, preferably when you’re already doing other network calls“. Is this possible?

davidbures,
@davidbures@mstdn.social avatar

@mattiem Sweet! I will hit you up with so many questions you will regret this 😂 But seriously, thank you for being available. I'll give you a shotout in the next version of Cork :)

mattiem,
@mattiem@mastodon.social avatar

@davidbures I cannot promise I’ll know all the answers of course but please ask away!

drahardja,
@drahardja@sfba.social avatar

I’m getting pretty fluent at writing these days, but I still miss writing in . I banged out a command-line tool in ObjC and it was glorious. I love the laid-back nature of the language, its verbosity that makes the code immediately readable, and its not-super-eagerness to get everything fixed up at compile time.

Would I recommend ObjC over Swift for new projects? No. I think most people will create better programs in Swift than ObjC. But I do miss those good old days. The Delegate pattern with optional methods is still exceedingly powerful and IMO yet to be surpassed with callbacks, builders, or what-have-you. The ability to cheat and directly examine the runtime without too much type safety in LLDB is extremely refreshing too.

Anyway, back to Swift.

mmalc,

@drahardja @GeekAndDad @uliwitness @leeg

Ah, no; he wasn’t at Apple at the time CoreData was developed. That was @bbum with Ben Trumbull, Melissa Turner et al. IIRC.

drahardja,
@drahardja@sfba.social avatar

@mmalc @GeekAndDad @uliwitness @leeg @bbum That makes more sense actually!

davidbures,
@davidbures@mstdn.social avatar

I took what the pros are saying to heart and measured the memory and CPU impact of three different ways of storing data inside Cork:

  1. Array, the original implementation that’s been around since the beginning
  2. IdentifiedArray from https://github.com/pointfreeco/swift-identified-collections
  3. Set

Set ended up being the best overall in memory consumption. The CPU benchmarks weren’t that decisive.

So I gotta convert Cork to Sets now! Where appropriate, of course :)

davidbures,
@davidbures@mstdn.social avatar

@sideshow_boz I will 👀

davidbures,
@davidbures@mstdn.social avatar
ctietze,
@ctietze@mastodon.social avatar

async/await question:

What are the patterns/conventions to expose async closures in one place, and handle getting back to the main queue in another?

Context:

The Xcode warning here makes perfect sense:

"""
Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.
"""

A dummy implementation of an async throws closure modified an view model directly. (It's annotated MainActor.)

ctietze,
@ctietze@mastodon.social avatar

@mattiem If I wrap the screenshotted call in a closure it goes away :| Must be something different.

mattiem,
@mattiem@mastodon.social avatar

@ctietze I just sent you a message on slack - having trouble following everything

uliwitness,
@uliwitness@chaos.social avatar

I’ve done nearly 30 years of C/C++ by now, and probably 20 years of Objective-C. So usually, that's my baseline for programming. These languages don't hurt, they're just “how programming is”. Better languages are “oh cool I get to have fun”.

That said, I recently wrote some new Objective-C code and … actually wanted to go back to Swift. Those square brackets really are a downside of the language. The Swift-style of method call syntax is superior.

#objectivec #objc #swift #programming

chucker,
@chucker@norden.social avatar

@bugaevc @uliwitness @js did. that ship in Rhapsody/Mac OS X Server 1.x? Or did Apple propose and immediately shelve it?

uliwitness,
@uliwitness@chaos.social avatar

@chucker @bugaevc @js AFAIK that was a NeXTstep or OpenStep thing, and already gone by the time Apple bought NeXT.

The WebScript version might have shipped from Apple for a while longer, but as I come from the Apple side, not the NeXT side, all I know is vague third-hand knowledge and the odd PDF found on the web.

heyjaywilson,
@heyjaywilson@iosdev.space avatar

How do you get user feedback in your app?

Some things I've done before:

  • form in app that is directly feeding to GitHub (this is alright)
  • asked people to join my discord (low number of people did this)

gbuela,
@gbuela@mstdn.social avatar

@MuseumShuffle @manuel @jordanhipwell @mikaelacaron @heyjaywilson bringing back this conversation, dealing with this now.

From my testing, checking canOpenURL() on a mailto: URL returns false on simulator but ALWAYS true on device. So when calling open()…

Mail app installed without a mail account: opens Mail with welcome screen.
Not installed: invites you to install it.

Did anybody find a solution to that?

System prompt inviting the user to install/restore Mail.app when opening a mailto: URL and the Mail app has been uninstalled.

MuseumShuffle,
@MuseumShuffle@mastodon.social avatar

@gbuela @manuel @jordanhipwell @mikaelacaron @heyjaywilson Mikaela tested my app without Mail installed and it did present the “copy email” option I added. That was definitely before iOS 17.2 was out though.

davidbures, (edited )
@davidbures@mstdn.social avatar

Updates to Cork:

Even though it might not be required since Cork is not on the App Store, I still added the new AppPrivacy stuff to it in this commit: https://github.com/buresdv/Cork/commit/ca9c3746edeaee2e456593c3786d3d006b7bbabb

So you can be sure that there's no privacy shenanigans going on :cat_1:

puppethead,
@puppethead@ieji.de avatar

@davidbures @melgu @codedbydan That looks like what I ran into with the "id" property expected to be in the JSON data. I got around that by making my "id" property a computed property. JSONDecoder/JSONEncoder ignore those. I don't know if that would work for you in this case.

davidbures,
@davidbures@mstdn.social avatar

@puppethead @melgu @codedbydan Interesting idea, but it unfortunately doesn't work in my case. Making it a computed property makes my navigation stop working.

At times like this, I wish there was something like a @noncodable property wrapper that would allow you to exclude a property from the encoding/decoding process, instead of having to duplicate everything in CodingKeys :x

ctietze,
@ctietze@mastodon.social avatar

I have a question!

Never wrote my own Publisher. Always combined others.

But this once, I believe that it would be nicer to have a struct instead of a function.

So I wrote a Combine.Publishers.Either type, but now I'm not sure if that's all there is, really.

https://gist.github.com/DivineDominion/de85d2dc3d42f6ebfe29f1d35a3c7da3

Feedback very much appreciated! 🙏

mattiem,
@mattiem@mastodon.social avatar

@ctietze it is definitely the opposite of simple

icanzilb,
@icanzilb@mastodon.social avatar

@ctietze @mattiem sounds like a combineLatest + compactMap to me? The first takes all source values + the user selection, the latter emits only the source value ones for the selected source?

ctietze,
@ctietze@mastodon.social avatar

package recommendation question:

Say I want a simple JavaScript syntax highlighter for NSTextView, what would you recommend nowadays?

mattiem,
@mattiem@mastodon.social avatar

@ctietze Yes! Themes would be cool! But, so you understand where I’m going here. In the medium term: Neon is about managing the state of text efficiently. All the tree-sitter stuff is going to migrate into SwiftTreeSitter. Theme support is going to live here:

https://github.com/ChimeHQ/ThemePark

mattiem,
@mattiem@mastodon.social avatar

@krzyzanowskim @ctietze “in the medium term” 🙃

czottmann,
@czottmann@norden.social avatar

> Unable to get connection interface: Error Domain=LNConnectionErrorDomain Code=1100 "Unable to locate com.apple.appintents-extension extension"

Thanks, macOS, that's suuuuper helpful. 🤨 Trying to move app intents into an Intents Extension. They show up in Shortcuts but error out when run. If anyone has some pointers, I'd be grateful

csigritz,

@czottmann Did you find a solution for this? I once had this error back in July, but could resolve it via defining a results type to the return value of the perform() method of the App Intent: ReturnsValue<MyFeedEntity> instead of just ReturnsValue. But since the newest macOS beta it is broken again.

csigritz,

@czottmann You also have to delete archives you created on the same Mac. Just had to learn that, after installing a TestFlight build. This is definitely a Sonoma only issue.

krzyzanowskim,
@krzyzanowskim@mastodon.social avatar

If you asked how @SwiftStudio going. Well... it been better. Apple just recently decided to shutdown API I use (to make things CLI cannot provide). I find it unexpected (to me, not to apple) move after many years. https://github.com/apple/swift-package-manager/issues/7440

I'm disappointed with a move in that direction and find that decision harmful for the third-party dev tooling ecosystem trying to adopt SwiftPM. IMHO.

helge,
@helge@mastodon.social avatar

@heckj @nickmain I wrote a wrapper for Wasmer a while ago, not sure it still works, but might be worth a look if you want to go that route: http://www.alwaysrightinstitute.com/swifty-wasmer/

dgregor79,
@dgregor79@sfba.social avatar

@helge @nickmain @heckj if you’re looking to embed a Wasm interpreter, there’s also WasmKit: https://github.com/swiftwasm/WasmKit

gernot, German
@gernot@mas.to avatar

Lets say I have a number of arrays, in this case three: [a,b,c][d,e][f,g,h,i] and I want all elements at the first index, then the second, and so on, as long as there are elements. Result should be this: [a,d,f,b,e,g,c,h,i]

What would I call this function? (Is it a merge?) Is there anything anywhere that does this already in ?

gernot,
@gernot@mas.to avatar

@DebugStr @zeitschlag Zip implies same length. I think I’ll settle with “interleave”

DebugStr,

@gernot @zeitschlag Plus, of course, zip will not return a flat array, but an array of pairs. It will work with different inputs array lengths, but naming yours based on zip would still imply a different behavior. Should have considered this before suggesting the name 😳.
So yes, interleave is much better 👍

davidbures,
@davidbures@mstdn.social avatar

I’ve got a Swift question:

I may be going about this the wrong way, but suppose I have a contains closure inside a filter closure. Now, I want to access the first argument, using the $0 syntax. The problem is, I don’t want to access the first argument of the nested closure, but the top-level closure. Check out the picture for an example.

I want to access the first element of the filter closure, not the contains closure. Am I going about this in a completely wrong way?

ctietze,
@ctietze@mastodon.social avatar

@davidbures I mention Big-O notation just to make sure that there's a reference for future inquiry into the matter.

This is an easy win to get from quadratic to linear runtime no matter the label :)

andy,
@andy@iosdev.space avatar

@davidbures you need to name your variables the moment you got a nested closure call. The $0 syntax is pretty good for short one-liners.

below, German
@below@mastodon.social avatar

More Swift questions: Why is this index out of bounds?

import Foundation

let sampleData = Data([12, 0, 0, 0, 39, 95])

let a = sampleData[2...5]
guard a.count > 2 else {
fatalError("Expected 2, actual (a.count)")
}
let b = a[0...1]
// Swift/Collection.swift:714: Fatal error: Index out of bounds

dlx,
@dlx@mastodon.social avatar

@below slices use the original index and don’t start at 0

teilweise,
@teilweise@layer8.space avatar

@below Subarrays (or in this case) Subdata use the original index from where they come from. If you want zero based index, use let a = Data(sampleData[2...5]).

(Yes, subscripts in Swift suck. Big time.)

ctietze,
@ctietze@mastodon.social avatar

fam and lazyweb enthusiasts,

to kickstart a research project, do you have a link handy to limit Swift code to execute on a particular thread (!) that works on macOS 11+?

ctietze, (edited )
@ctietze@mastodon.social avatar

@mattiem Thank you for the offer! Favored solution 100%, but it's maybe not backdeployed, maybe it is, so not sure if we can wait for Xcode 15 RC 🤷‍♂️ @oliep

ctietze,
@ctietze@mastodon.social avatar

@icanzilb @mattiem :blobcatcoffee: thanks

phranck,
@phranck@chaos.social avatar

Simple (dumb?) but very important question to all , , developers using :

How do you secure your API keys?
It's clear that they don't belong hardcoded in the app. But how do you secure your keys?

Whether hardcoded or via Config.plist with a hex editor, they can be extracted from a binary. So what is the "right" way?

Please boost, thank you. 🙏🏼
:BoostOK:

grork,
@grork@mastodon.social avatar

@arroz @krzyzanowskim @phranck @benboecker it’s ultimately not about the client, it’s about the service being able to close the barn door after horse has bolted - revoke and push back a DDoS until they move to new keys, or billing/usage tracking.

kristoffer,

@phranck ok, it should be pretty straightforward.

  • Enable the capability and create a CloudKit container for your app
  • Add your data to the public database using the CloudKit dashboard
  • Write the code for fetching the data from the public database on app launch

https://developer.apple.com/documentation/cloudkit

davidbures,
@davidbures@mstdn.social avatar

Update on the categorized cached downloads (https://mstdn.social/@davidbures/112456702745516734):

Now, it also works when the name of the installed package is not exactly the same as the name of the cached download!

phranck,
@phranck@chaos.social avatar

@davidbures I've done that, and the error is gone.

davidbures,
@davidbures@mstdn.social avatar

@phranck That's good to hear 😊

JTostitos,
@JTostitos@techhub.social avatar

Apparently the name in NSPersistentCloudKitContainer(name: "") is supposed to be in bundle id format like "iCloud.com.yourDomain.YourAppName". And its supposed to match the iCloud container identifier.

I definitely did not know about or do it this way 😂

Is this true, and are there any long term consequences for not having it in this format?

deanatoire, (edited )
@deanatoire@mastodon.social avatar
JTostitos,
@JTostitos@techhub.social avatar

@deanatoire oh good! Thanks for the link. I saw online that Apple recommended doing it that way and I’ll admit I don’t have too much knowledge on Core Data and all its quirks. So good to see that according to Apple, it doesn’t need to be in a bundle id format 😅

finestructure,
@finestructure@mastodon.social avatar

“With the increased limit of the acceptance queue, and a patched version of wrk, we can now conclude that swift is a good competitor speed-wise as a web application server.

Memory wise it blows all the other technologies away, using only 2.5% of the amount of memory that the java implementation needs, and 10% of node-js.”

https://tech.phlux.us/Juice-Sucking-Servers-Part-Trois/

opticalaberration,
@opticalaberration@mastodon.scot avatar

@finestructure always seemed to me to be a weird benchmark where the endpoint has a heavy CPU load. Not very typical of a standard server. Some interesting discussion though. Not sure the decision to accept more connections when server is overloaded is very clever though.

finestructure,
@finestructure@mastodon.social avatar

@opticalaberration Yeah, the Swift forums thread goes into that in detail and was very interesting.

davidbures,
@davidbures@mstdn.social avatar

Guys, do you know if it’s possible to write a comment for a named tuple element in Xcode? Something like the pic below for functions.

image/jpeg

aCertainBru,

@mattiem @davidbures absolutely, in fact as I was writing it I thought “wait but have I actually measured this?” So to be clear: It’s just conjecture on my part - or “a safe bet”. Also remember to only measure/profile release builds, especially in Swift and when dealing with data types, you may end realising that your latest genius 10x optimisation actually runs slower in release config :) (speaking from experience :D :D)

davidbures,
@davidbures@mstdn.social avatar

@aCertainBru @mattiem Reminds me how I was going crazy trying to optimize memory by only passing individual variables needed to views, and then I gave up and threw everything into a single @EnvironmentObject and memory consumption decreased by almost 1/3 😅

finestructure,
@finestructure@mastodon.social avatar

I had a hunch that I could take on tasks that I used to do with Python + matplotlib + Jupyter with Swift Charts + SwiftUI + Playgrounds instead. But I had no idea it’d be this nice and easy. Plus I find the default result better looking and I have much more control over everything around the chart, like labels, titles etc.

This will change everything for me when working with charts.

finestructure,
@finestructure@mastodon.social avatar

Since people asked, I’ve posted the self-contained example as a gist on Github and added a button to export the page as a PDF. Works wonderfully, even from within a simple playground 🎉

NB: the PDF is not rasterised - you can select the text and zoom in without any loss of fidelity.

https://gist.github.com/finestructure/45881a35819b5ebf850c437c54f43b8c

A Swift Playground window showing the code to generate a page with two histograms laid out vertically, complete with titles and chart headers. The charts are the MB size and file count distribution for documentation archives hosted on the Swift Package Index. Below the charts is a button to export them to PDF.

finestructure,
@finestructure@mastodon.social avatar

I've had more opportunities recently to create plots with / Swift Charts / playgrounds and the process absolutely holds up in replacing / / .

The dataset was larger this time, ~100k records, each containing a handful of data points, exported from a Postgres DB as JSON.

Massaging the data in a typesafe way is an absolute blessing – it's so easy to plot the wrong thing in python as you drill through three dicts.

Really happy with the results!

masukomi, (edited )
@masukomi@connectified.com avatar

Package Manager / People

I can't resolve known good packages from github. & searching has failed me.

I get 1 of these 2 errors. Unclear why it seems to alternate. API token has FULL access. SSH Key verified (by me and it). HTTP & SSH cloning configs both fail. Wifey can install the same package(s) just fine.

"realm-swift" is irrelevant. it's just a known good package & version to eliminate potential errors related to the package itself.

masukomi,
@masukomi@connectified.com avatar

The separate XCode bug we encountered:
I've been doing this a while & have been forced to jump through the 6 hells of GPG signing many times over the years. Consequently, I have my ~/.gitconfig configured Git to auto-sign all of my commits, with my SSH (not GPG) key.

I like knowing that all my commits to my public repos can be verified & weren't some malicious BS. You can fake the name & email on a commit trivially.

However, if I make a new XCode project w/ git it does this. 🎉
🧵5/?

masukomi,
@masukomi@connectified.com avatar

This isn't actually a problem for me because i never use IDEs to manage git.

So, XCode can't handle GPG signing configured git setups, their error messages are god-awful, and I think they're absolute 🍆's for bundling all their 💩 into their 💩 IDE.

You know who doesn't use XCode at Apple? Everyone‡ who isn't coding in Swift/Obj-C. I'm not kidding. NONE of my coworkers used it. Why? Because there are tons of great IDEs / Editors out there that aren't XCode.

FIN
‡some exceptions apply of course.

davidbures,
@davidbures@mstdn.social avatar

I have a question for the Swift gods:

On my journey to convert SwiftyJSON in Cork to Codable, I ran into a slight problem. Some of the JSON I’m parsing has this format:
[{formula: { // the data that I actually need}}, cask: { // empty and I don’t care}]

Is there a way to access the data inside “formula”, without having to define Formula as a useless struct? Using SwiftyJSON for this made the code really nice, since I could directly access the data in there.

deanatoire,
@deanatoire@mastodon.social avatar

@davidbures This is what I can suggest for your current structures

davidbures,
@davidbures@mstdn.social avatar

@deanatoire That’s very smart! Thanks a lot 👏

baronetty,

Today I finished day 23 of
It was a tough one! @twostraws gave the introduction to the new project and so I learned a lot of new things about custom view modifiers and custom containers. I understand the logic behind it, but it’s still pretty complicated! I’m curious what we will do with that in the next project.

MuseumShuffle,
@MuseumShuffle@mastodon.social avatar

@baronetty if you are a member of the Apple developer program, you can sign up for one for free during WWDC week!

baronetty,

@MuseumShuffle Uuh, that’s nice! Good to now 👍🏽

  • All
  • Subscribed
  • Moderated
  • Favorites
  • swift
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • cubers
  • rosin
  • thenastyranch
  • Youngstown
  • osvaldo12
  • slotface
  • khanakhh
  • kavyap
  • InstantRegret
  • Durango
  • JUstTest
  • everett
  • tacticalgear
  • modclub
  • anitta
  • cisconetworking
  • tester
  • ngwrru68w68
  • GTA5RPClips
  • normalnudes
  • megavids
  • Leos
  • provamag3
  • lostlight
  • All magazines