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
rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
A propos, there’s a Swift extension for VS Code now.

Adbot
ADBOT LOVES YOU

Stringent
Dec 22, 2004


image text goes here

Plorkyeran posted:

Which is it? Fantastic, or just like Xcode? Those are pretty contradictory.

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.

Stringent
Dec 22, 2004


image text goes here
i really appreciated how android studio has xcode key bindings

Pulcinella
Feb 15, 2019
Probation
Can't post for 3 days!

commie kong posted:

All you pros going to be switching to iPads for development now?

I tried it. The good: SwiftUI previews are actually pretty fast and don’t bring the system to a crawl or heat up the system. (Even an M1 mac has problems with SwiftUI previews). Also it supports UIKit. It’sthe easiest way by far to test and iterate custom drawing code and CALayers. Just throw a UIview in a SwiftUI preview and you are good to go.

The bad: everything else. It uses its own file type and you can’t import an existing project beyond manually copy and pasting files. You can’t import existing stirybiard/xib files. I didn’t expect IB to get ported, but you can’t even build with these files. So all y’all doing layout in code get the last laugh. It doesn’t support Swift packages that contain binaries or Obj-C. Also I don’t believe it has source control!

KidDynamite
Feb 11, 2005

Pulcinella posted:

. Also I don’t believe it has source control!

lol. teaching young devs bad habits.

fankey
Aug 31, 2001

I made the always poor choice of upgrading Xcode to 13.2.1 and now I'm running into code signing issues. I have another project that I've dragged in as a Framework and had the signing set up like this

free img host
When I attempt to archive the app I get the following error
code:
Warning: unable to build chain to self-signed root for signer "Apple Development: XXXXXX"
/Users/XXXXXXX/Library/Developer/Xcode/DerivedData/XXXXXX-egshcztqxjcvajccurikbgmmndvq/Build/Intermediates.noindex/ArchiveIntermediates/QSys Controller/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/ANTLR4.framework: errSecInternalComponent
Command CodeSign failed with a nonzero exit code
I've both restarted Xcode and removed my developer account and re-added it in the Xcode prefs but neither fixed the issue. Any ideas what to try beyond installing the previous version of Xcode to see if that fixes the issue?

Vesi
Jan 12, 2005

pikachu looking at?
revoke your certificates and let xcode re-create them

I feel your pain, I think I've wasted weeks of my life just to fight apple certificates but in recent years revoke has never failed me

holefoods
Jan 10, 2022

Hello thread, I have been teaching myself to code over the past year and became intensely interested in Swift in the past few months. I had been trying to learn C which seems to have been a pretty foolish effort and man are books on C dry. I’ve found Apple’s free resources on learning Swift to be really helpful and I’m almost finished with the Explorations book.

One thing I am continuing to struggle with is how to translate a problem to code and solve it. I’m not quite sure how to phrase it, a conceptualization issue, I guess? Is this something that generally improves the more you code on your own or is this more of a skill that you need to build out separately? If there are any books or resources that anyone can recommend I would really appreciate it.

Arcsech
Aug 5, 2008

holefoods posted:

One thing I am continuing to struggle with is how to translate a problem to code and solve it. I’m not quite sure how to phrase it, a conceptualization issue, I guess? Is this something that generally improves the more you code on your own or is this more of a skill that you need to build out separately? If there are any books or resources that anyone can recommend I would really appreciate it.

A bit of both, honestly - it’ll build up over time as you program more, but I think you could accelerate it with practice if that’s what you’re looking for. What I’d recommend is spending some time on data structures and algorithms and do some programming problems like Advent of Code (NOT something math-focused like Project Euler for this) - I find my process for translating a problem into the code to solve it starts with identifying the data structures I’ll want to use to hold the data and access it efficiently.

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, with the Swift playgrounds app I’m getting back into trying to learn hobby iOS programming, and I’ve as usual hit a fairly early “there should be a way to solve this problem but” scenario.

Main Problem: I’m working on an app just to read a Lone Wolf gamebook (CYOA kind of thing; all of them are available online at Project Aon, and a sample page showing what I’m doing is at https://www.projectaon.org/en/xhtml/lw/01fftd/sect70.htm ). I just want to have a line of text that ends with “turn to [page X]” and have that part take an action when clicked.

Option 1: I could just make it a link and then handle the press in some fashion.

Option 1 Problem: I can’t figure out how to handle the press. Is it even possible to register a custom url programmatically or through the Swift playgrounds app from an iPad? Or is there any other way to have a Link object that just goes to another part of your application than a custom url?

Option 2: I could just break things up and then have a button next to the text, which is the most obvious solution.

Option 2 Problem: Then the wrapping and flow is all wonky. How can I put a Button next to a Text and have the Button be basically laid out as if it were part of the text?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

holefoods posted:

One thing I am continuing to struggle with is how to translate a problem to code and solve it. I’m not quite sure how to phrase it, a conceptualization issue, I guess? Is this something that generally improves the more you code on your own or is this more of a skill that you need to build out separately? If there are any books or resources that anyone can recommend I would really appreciate it.

I've found over time that the general process hasn't changed: break problem down into smaller steps, code the steps, done. With experience (and not much dedicated practice, though in retrospect that would've been smart), I've found that I can take bigger steps without getting lost. Part of it, I think, is higher fluency with tools (languages and libraries in addition to basic typing skills and use of an editor/IDE) letting me go faster, so I can take a bigger step in the same amount of time before I lose focus or get tired. This is absolutely something you can practice: do typing drills, internalize how to get around your editor faster, read random bits of documentation to see what's available in languages and libraries.

There's more to it but I have no idea how to practice those parts.

ulmont posted:

Option 1: I could just make it a link and then handle the press in some fashion.

Option 1 Problem: I can’t figure out how to handle the press. Is it even possible to register a custom url programmatically or through the Swift playgrounds app from an iPad? Or is there any other way to have a Link object that just goes to another part of your application than a custom url?

Option 2: I could just break things up and then have a button next to the text, which is the most obvious solution.

Option 2 Problem: Then the wrapping and flow is all wonky. How can I put a Button next to a Text and have the Button be basically laid out as if it were part of the text?

Are you using SwiftUI or UIKit (or something else)? If you're using a UITextView, you can add a link (or a text attachment of anything you like), then be the text view's delegate and implement textView(_:shouldInteractWith:in:interaction:) (for a link, or textView(_:shouldInteractWith:in:interaction:) for a text attachment). You can set whatever you want for the link's URL and just pull it back out as the delegate, then do whatever you like without actually loading the URL.

I'm being kinda handwavy here but I'm happy to explain any and all of it in more detail.

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

pokeyman posted:

Are you using SwiftUI or UIKit (or something else)? If you're using a UITextView

SwiftUI. I had been working with the Text view, which can automatically include a Link control (also technically a view) if you use Markdown in initializing it.

I think I could try UIKit if you think it would be simpler, but it seems like this should be easy enough to handle in SwiftUI?

Froist
Jun 6, 2004

ulmont posted:

SwiftUI. I had been working with the Text view, which can automatically include a Link control (also technically a view) if you use Markdown in initializing it.

I think I could try UIKit if you think it would be simpler, but it seems like this should be easy enough to handle in SwiftUI?

If you can find a way to stick with SwiftUI and the new Markdown support I'd suggest going that direction, though I can't help directly.

I've had to wrap UITextView to use within SwiftUI for this purpose this week (as my "work" app needs to support pre-iOS 15 so can't use the Markdown features) and there are edge cases everywhere.

Arcsech
Aug 5, 2008

pokeyman posted:

This is absolutely something you can practice: do typing drills, internalize how to get around your editor faster, read random bits of documentation to see what's available in languages and libraries.

There's more to it but I have no idea how to practice those parts.

In addition to what I said above, this. Spend time familiarizing yourself with your chosen tools: Read the manual and stdlib docs for your primary programming language (not cover to cover as that’s probably too dry and boring, just pick things that look interesting or at random) and your editor, and get very familiar with your editor - and not just for editing. Tools like “Go To Definition” or opening a file by using fuzzy matching should be second nature - it really helps to not have to think about navigation when you’re trying to grok new code (which happens as much or more than actually writing code, IME) as well as when trying to write or debug it.

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

Froist posted:

If you can find a way to stick with SwiftUI and the new Markdown support I'd suggest going that direction, though I can't help directly.

It should be possible. I think I need to find out how to do one of two following things to go this approach:

1. I need to detect which specific character in a Text view was pressed. This appears to be non-trivial but I am far from the first to want this. If this works I can just create a Text with an AttributedString where the link part is link color and go from there.

2. I need to get access to a Link inside a Text and then manipulate it. If this works I can just swap the default url action for something else.

EDIT: 3. Or I could just try again with HStack and a Text followed by a Button and have it do what I want, which is annoying but promising.

ulmont fucked around with this message at 21:48 on Jan 12, 2022

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

ulmont posted:

SwiftUI. I had been working with the Text view, which can automatically include a Link control (also technically a view) if you use Markdown in initializing it.

I think I could try UIKit if you think it would be simpler, but it seems like this should be easy enough to handle in SwiftUI?

UIKit would be simpler for me as someone with a million times more UIKit experience than SwiftUI experience :)

I would expect it to be doable with SwiftUI. Does this help? https://www.fivestars.blog/articles/openurl-openurlaction

edit: just saw your post, looks like you know about openURL already!

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

pokeyman posted:

edit: just saw your post, looks like you know about openURL already!

Actually, that might be perfect. I had been thinking about trying to register a custom-url for the default url handling, but customizing the url handling in general on an application-wide basis might be the real answer.

Mind you, I may have solved the problem a completely different way, but I should probably play with openURL to see if I can get that solution to work just in case.

holefoods
Jan 10, 2022

Thanks for the recommendations everyone, Advent of Code looks great as I had been trying to find a website with problems but Swift specific stuff is rare. I know that I am still very early on in the learning process, so it's great to get some pointers and see what people think would have been beneficial.

Apple's curriculum seems a bit odd because it seems to indicate that you should go Explorations -> Fundamentals -> Data Collections but the first two books seem to largely cover the same things, but Fundamentals looks a bit more in-depth and has less guided portions/Playgrounds. So, it's possible I'm jumping the gun a bit with the things I think I should have a better grasp on. Either way, it's all really clicking a lot better than other books I had tried for C so I'm looking forward to becoming a thread regular.

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
Update to the update: NavigationView probably would have been the perfect way to go and would have given me the links for free along the way.

https://www.hackingwithswift.com/articles/216/complete-guide-to-navigationview-in-swiftui

SaTaMaS
Apr 18, 2003
I'm working on an app with computer vision, and one thing I'm working on is having the user take multiple images of a target from multiple angles since every so often there is a bad angle that fools the vision model. I'm working with the attitude quaternion in Core Motion and trying to store the axis of rotation while ignoring the tilt (portrait/landscape), then making sure any new axis is at least a small angle from any previous ones. The default basis doesn't seem very conducive to this. I think the tilt of the phone is changing the axis? However I came across some code on github that seems to fix the problem. The issue is I only sort of understand quaternions, and I really don't understand what this code is doing and why it fixes the problem. My guess would be that it's tilting the quaternion from portrait into landscape since it's a VR app, but it's also flipping the x/y/z around for some reason? Also when I change the viewportTiltAngle to 0 it stops working for me.

Here is the repo:
https://github.com/bartlomiejn/6dof-vr/blob/425393b55312901a84ae91c3204aba8840d23bb0/6dof-vr/Modules/Motion/MotionService.swift

Here is the function:
code:
    private func correctedRotation(from quaternion: CMQuaternion?) -> simd_float4 {
        guard let quaternion = quaternion else {
            return simd_float4()
        }
        
        let quat = simd_quatf(quaternion)
        let correctedAxisAngle = simd_float4(
            quat.axis.y,
            quat.axis.z,
            -quat.axis.x,
            quat.angle)
        
        let correctedQuat = simd_quatf.fromAxisAngle(correctedAxisAngle)
        
        let viewportTiltAngle = Float(90.0.degreesToRadians)
        let tiltQuat = simd_quatf(
            ix: -1.0 * sin(viewportTiltAngle / 2),
            iy: 0.0 * sin(viewportTiltAngle / 2),
            iz: 0.0 * sin(viewportTiltAngle / 2),
            r: cos(viewportTiltAngle / 2))
        
        let correctedQuat2 = correctedQuat * tiltQuat
        
        let correctedAxisAngle2 = simd_float4(
            correctedQuat2.axis.x,
            correctedQuat2.axis.z,
            correctedQuat2.axis.y,
            correctedQuat2.angle)
        
        return correctedAxisAngle2
    }

Good Sphere
Jun 16, 2018

Is there any known way to have a button a Safari extension's popup (written in html) trigger a javascript function in the same script that manipulates the site you are visiting? I cannot find any documentation on it.

e: Hey, I got it. It's html, and js stuff, but for reference:

I found out you need a lot more going on. First you need a script inside the popup, where you just make html tags with a button tag inside with an ID. I'd post the html, but it trigger's SA's security warning, and won't let me post it.

This is popup.js. I have a function to get the current browser tab, which is returned when you click the button in popup.html. It sends the command "test" to content.js.
code:
    function getActiveTab() {
    	return browser.tabs.query({active: true, currentWindow: true});
    }
    
    document.getElementById("onOffToggleButton").addEventListener("click", function() {
    	getActiveTab().then((tabs) => {
    		browser.tabs.sendMessage(tabs[0].id, {
    			command: "test",
    		});
    	});
    });
content.js receives the message, and writes the message to the console:

code:
    browser.runtime.onMessage.addListener((message) => {
    	if (message.command === "test") {
    		console.log("hi")
    	}
    });
I don't think this is mentioned in any of Apple's docs. I got this off Mozilla, and the example scripts linked to it.

Good Sphere fucked around with this message at 04:09 on Jan 14, 2022

Pulcinella
Feb 15, 2019
Probation
Can't post for 3 days!
There is no way to specify image assets by screen dimensions right? Just 2x,3x, iPhone, iPad, etc. right? I have some background images and I would like to avoid having the mini phones need to download pro max sized images just because they are both 3X scale.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
You're on your own in that case, yep.

KidDynamite
Feb 11, 2005

holefoods posted:

Thanks for the recommendations everyone, Advent of Code looks great as I had been trying to find a website with problems but Swift specific stuff is rare. I know that I am still very early on in the learning process, so it's great to get some pointers and see what people think would have been beneficial.

Apple's curriculum seems a bit odd because it seems to indicate that you should go Explorations -> Fundamentals -> Data Collections but the first two books seem to largely cover the same things, but Fundamentals looks a bit more in-depth and has less guided portions/Playgrounds. So, it's possible I'm jumping the gun a bit with the things I think I should have a better grasp on. Either way, it's all really clicking a lot better than other books I had tried for C so I'm looking forward to becoming a thread regular.

I don't know if you're planning to learn Swift for iOS development. If you are I want to recommend the Stanford iOS development course. You will learn a ton of poo poo in there that I think most average entry level iOS devs don't know.

The course tells you what you need to read from the Swift Programming Language so that's a pretty good guide of where you should be at.





Also very thankful Apple pushed the delete account in-app requirement. That was kinda stressing me out.

holefoods
Jan 10, 2022

KidDynamite posted:

I don't know if you're planning to learn Swift for iOS development. If you are I want to recommend the Stanford iOS development course. You will learn a ton of poo poo in there that I think most average entry level iOS devs don't know.

The course tells you what you need to read from the Swift Programming Language so that's a pretty good guide of where you should be at.





Also very thankful Apple pushed the delete account in-app requirement. That was kinda stressing me out.

Oh hey, this looks really awesome, thank you! I don't know that I'm necessarily looking to solely focus on iOS but the more examples I have the better as far as I'm concerned.

KidDynamite
Feb 11, 2005

anyone familiar with getting swiftyjson to work on a m1 mac? one of my coworkers wants to make a small pr to our app but can't get it to build on his machine due to errors with swiftyjson and m1 architecture. I'm still on an intel mac and have been avoiding thinking about this situation and i can't find anything worthwhile via googling.

this might finally give me the coverage to rewrite the app's networking layer.

Fate Accomplice
Nov 30, 2006




Xcode 13 is absolutely unusable right now for work purposes. We have a shared kotlin library as a cocoapod, and every time I change a line even outside said library, I have to clear derived data, delete the Pods directory, and start fresh.

I get maybe three builds an hour.

Now I have to figure out how to downgrade to Big Sur because Monterey doesn't let you use Xcode 12.5.1.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

KidDynamite posted:

anyone familiar with getting swiftyjson to work on a m1 mac? one of my coworkers wants to make a small pr to our app but can't get it to build on his machine due to errors with swiftyjson and m1 architecture. I'm still on an intel mac and have been avoiding thinking about this situation and i can't find anything worthwhile via googling.

this might finally give me the coverage to rewrite the app's networking layer.

Have you looked through the issues on the repo? e.g. https://github.com/SwiftyJSON/SwiftyJSON/issues/1095

I'm not sure how a swift library for parsing json that is distributed as source manages to have architecture dependencies, but I realize you're playing the hand you were dealt :)

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
I know there’s been a perennial problem where CocoaPods tries to perfectly duplicate knowledge from the toolchain and then breaks whenever there’s a new configuration they didn’t anticipate. Like IIRC they were trying to link the Swift back-compatibility libraries on ARM64 macOS, which don’t exist because ARM64 macOS post-dates the integration of Swift into the OS, which is something the toolchain already knows but obviously has to be re-implemented if you’re set on writing out linker invocations by hand.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
tt's really impressive how objc/swift have three different package managers and they're all garbage. CocoaPods set a really low bar, but then Carthage and SPM found their own different ways to be awful.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

rjmccall posted:

I know there’s been a perennial problem where CocoaPods tries to perfectly duplicate knowledge from the toolchain and then breaks whenever there’s a new configuration they didn’t anticipate. Like IIRC they were trying to link the Swift back-compatibility libraries on ARM64 macOS, which don’t exist because ARM64 macOS post-dates the integration of Swift into the OS, which is something the toolchain already knows but obviously has to be re-implemented if you’re set on writing out linker invocations by hand.

This is entirely the toolchain's fault, though. It would be nice if the CocoaPods developers were better at reverse-engineering things, but problems are inevitable when you have to reverse engineer things because there's zero public documentation and DTS requests get replies along the lines of "that's an implementation detail of Xcode that you shouldn't use". You can gently caress around with loading the appropriate settings for the platform you're targeting from the appropriate json file tucked away in Xcode and have it break when the next version of Xcode rearranges things, or you can write a lovely shell script that breaks when there's a new platform. Either way something is going to break every year. Maybe you go okay fine we'll just use xcodebuild to compile things but whoops the input file for that is undocumented too! A hilarious number of CocoaPods's problems over the years have been them loving up xcode project generation because there's no supported way to do it programmatically.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
I’m happy to relay problems with SPM into the appropriate channels. I know for a long time it seemed like Apple wasn’t taking it seriously as a product at all, but we’ve been doing a lot of work with it recently, and we’re at least trying to turn that into a nice package ecosystem.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Plorkyeran posted:

This is entirely the toolchain's fault, though. It would be nice if the CocoaPods developers were better at reverse-engineering things, but problems are inevitable when you have to reverse engineer things because there's zero public documentation and DTS requests get replies along the lines of "that's an implementation detail of Xcode that you shouldn't use". You can gently caress around with loading the appropriate settings for the platform you're targeting from the appropriate json file tucked away in Xcode and have it break when the next version of Xcode rearranges things, or you can write a lovely shell script that breaks when there's a new platform. Either way something is going to break every year. Maybe you go okay fine we'll just use xcodebuild to compile things but whoops the input file for that is undocumented too! A hilarious number of CocoaPods's problems over the years have been them loving up xcode project generation because there's no supported way to do it programmatically.

I’m not sure what you think they have to reverse-engineer here. The standard way in a C-like toolchain to link with the language standard library is to ask the compiler to invoke the linker for you. They decided to bypass that and instead just directly invoke the linker, which means they have to duplicate a lot of platform-specific knowledge about the standard library. They are basically slowly duplicating the entirety of the swift driver’s logic for how to invoke the linker, and I don’t know why, because the swift driver exists.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

rjmccall posted:

I’m happy to relay problems with SPM into the appropriate channels. I know for a long time it seemed like Apple wasn’t taking it seriously as a product at all, but we’ve been doing a lot of work with it recently, and we’re at least trying to turn that into a nice package ecosystem.

It's really coming along. I think the only thing I do with CocoaPods that I can't do with SPM is include a copy of all my dependencies in my repo (i.e. commit my Pods directory), so I don't need a network connection (and GitHub to be up and nobody to delete their repo and transitively through the whole dependency tree blah blah blah) to build from a fresh checkout. But I realize that's an unpopular configuration.

Graniteman
Nov 16, 2002

I’m new to mac development, and working on an iOS app. Is xcode … unstable? Like, should I have to relaunch to get reproducible results?

I’m having a situation at least once a day where my unit tests will start failing and I’ll get unhandled nils, or access an array out of bounds, within unit tests unrelated to recent changes. If I run the test again, I get exactly the same error. If I restart Xcode everything works again.

And if I step through the code it will be something totally bonkers like
var myIndex = stuff
DoSomeUnrelatedFunction() // NOTE: myIndex is valid here
myArray[myIndex] // wtf myIndex is now -19283272975

If I reboot, that myArray access line will be fine.

Is this an Xcode bug, or am I doing something really hosed up in my code somewhere that’s corrupting memory in my app? As far as I know I’m not doing any funny memory access or unsafe stuff in my code at all. My fear is that I’m blaming Xcode for something that will end up being a problem on users’ devices.

A while ago I did try to nuke my Xcode install due to an unrelated problem and reinstall fresh, but it didn’t end up looking exactly like my original install. I didn’t have this memory instability problem before then, but I don’t know that it started right after, either. Should I try harder to completely Xcode from my mac and reinstall?

KidDynamite
Feb 11, 2005

pokeyman posted:

Have you looked through the issues on the repo? e.g. https://github.com/SwiftyJSON/SwiftyJSON/issues/1095

I'm not sure how a swift library for parsing json that is distributed as source manages to have architecture dependencies, but I realize you're playing the hand you were dealt :)

Thanks for this! We tried that and failed. I'm gonna try a few more things and if not use it as a reason to pull swiftyjson and rewrite networking stuff.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

rjmccall posted:

I’m happy to relay problems with SPM into the appropriate channels. I know for a long time it seemed like Apple wasn’t taking it seriously as a product at all, but we’ve been doing a lot of work with it recently, and we’re at least trying to turn that into a nice package ecosystem.

SPM is a very nice MVP of a package manager with integrated build system. The main problem with it is just that it's four years in and has zero momentum towards building the other 90% of a build system. Each year it gets one or two major new features and a few more minor build configuration flags get added, which means that in another fifty years or so it might finally not be frustratingly limited.

Some of the specific problems we've run into with it:

No reasonable way to expose any configuration options for people installing the package. Environment variables are decent for command-line swift build but are not when installing via Xcode. We want to have options like "Do you want to enable Concurrency support" and "Do you want to build the non-Swift parts from source or download a binary" and it just isn't really possible with SPM.

No support for anything other than compiling a static set of files which are committed to git. The proposal to add build tools is sorta wacky but would work, but seemingly got stuck in purgatory and abandoned.

No whitelist of allowed compiler flags. The rules around unsafeFlags() aren't unreasonable, but there's no corresponding safeFlags() outside of preprocessor defines and c++ version (and the c++ version being an enum is itself a problem because new versions aren't added to the enum at the same time as they're added to clang). One concrete effect of this was that we can't support 32-bit iOS with SPM (we have paying customers which care about that for some reason and I keep hoping new Xcode versions will drop support for it).

SPM has some strong opinions about repo layout, except for that they seem to be less opinions and more that there wasn't much thought put into it. It wants public headers in a different directory structure than building a dynamic framework via an xcode project wants, which we resolve with a stupid directory full of symlinks. The rules around overlapping source trees for targets are a nightmare when you have a pre-existing code base which is not structured with one directory per SPM target.

Running Package.swift in a sandbox without access to anything is great. Not including the rest of the repo in that sandbox is awkward.

SPM's decision to be both a dependency resolver and a build system was a very ambitious one, and I don't think that the authors recognized how ambitious it was. They did a good job of building the dependency resolver (other than that it thinks 5 is greater than 10), but build systems come with a very long tail of things people expect them to do.

rjmccall posted:

I’m not sure what you think they have to reverse-engineer here. The standard way in a C-like toolchain to link with the language standard library is to ask the compiler to invoke the linker for you. They decided to bypass that and instead just directly invoke the linker, which means they have to duplicate a lot of platform-specific knowledge about the standard library. They are basically slowly duplicating the entirety of the swift driver’s logic for how to invoke the linker, and I don’t know why, because the swift driver exists.

I thankfully have never had to look at CocoaPods's handling for Swift, but I had the distinct mispleasure of getting Catalyst support working with CMake and then fixing some CocoaPods bugs related to Catalyst. This is relatively straightforward via xcodebuild, but finding out what xcodebuild was doing was significantly less so. More similarly to bypassing the swift driver, I eventually gave up on using xcodebuild -create-xcframework because of how broken it was in Xcode 11 and just wrote a shell script to assemble xcframeworks. I assume they similarly hit a problem with calling the swift driver and then hacked together something awful that could be shipped immediately rather than waiting a year.

haveblue
Aug 15, 2005



Toilet Rascal

Graniteman posted:

I’m new to mac development, and working on an iOS app. Is xcode … unstable? Like, should I have to relaunch to get reproducible results?

I’m having a situation at least once a day where my unit tests will start failing and I’ll get unhandled nils, or access an array out of bounds, within unit tests unrelated to recent changes. If I run the test again, I get exactly the same error. If I restart Xcode everything works again.

And if I step through the code it will be something totally bonkers like
var myIndex = stuff
DoSomeUnrelatedFunction() // NOTE: myIndex is valid here
myArray[myIndex] // wtf myIndex is now -19283272975

If I reboot, that myArray access line will be fine.

Is this an Xcode bug, or am I doing something really hosed up in my code somewhere that’s corrupting memory in my app? As far as I know I’m not doing any funny memory access or unsafe stuff in my code at all. My fear is that I’m blaming Xcode for something that will end up being a problem on users’ devices.

A while ago I did try to nuke my Xcode install due to an unrelated problem and reinstall fresh, but it didn’t end up looking exactly like my original install. I didn’t have this memory instability problem before then, but I don’t know that it started right after, either. Should I try harder to completely Xcode from my mac and reinstall?

It's 90% likely you're doing something hosed up, the Xcode test harness generally does not eat itself for no reason. Have you tried catching the exact moment of corruption with a watchpoint?

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Do you have SIP disabled and/or are you downloading Xcode from a sketchy third-party? It shouldn't be possible for deleting and reinstalling Xcode to do anything at all these days as it's a signed package and everything mutable is in ~/Library/Developer or the keychain.

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