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 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.

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
It's been gradually creeping up over time, and then Xcode 12 doubled the size of it. I assume it's because it's now all x86_64/arm64 fat binaries with no option to only install the architecture you're actually using.

Vesi
Jan 12, 2005

pikachu looking at?
my 12.4 is only 15G on the M1, but I installed it with xcode-install, maybe it's different

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Vesi posted:

my 12.4 is only 15G on the M1, but I installed it with xcode-install, maybe it's different

I think the size reporting is a bit fucky with APFS.

chaosbreather
Dec 9, 2001

Wry and wise,
but also very sexual.

I'm trying to get Core Data working with SwiftUI's DocumentGroup, but it's not at all clear to me how that's supposed to hook up. It looks like ReferenceFileDocument expects to work on FileWrappers, while NSPersistantContainer only deals with URLs. I'm also a little confused about the Snapshot typealias ReferenceFileDocument needs. Strangely, I haven't found any tutorials that deal with this, does anyone here have any insight on this?

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
Now you don’t have to wonder why the Core Data checkbox is dimmed out when you select SwiftUI for your app lifecycle in the Document App template.

awesomeolion
Nov 5, 2007

"Hi, I'm awesomeolion."

I've got two SKShapeNode's, a rotated rectangle and a circle, and I'm trying to check of they intersect or not. I definitely can't use frame.intersects because frame is the smallest containing unrotated refrangle. Any hot tips on how to approach this?

Doc Block
Apr 15, 2003
Fun Shoe
Maybe something like this

You’ll have to work out the vertices of your rectangle and transform them based on its rotation, but that’s pretty easy, especially in 2D (I believe Core Graphics has functions for translating and rotating 2D points that you could use).

You could also bring in SpriteKit’s physics engine, but that’s kind of overkill for such a simple case, especially if all you want is to know if two shapes overlap and don’t need all the bouncy physics results.

Doc Block fucked around with this message at 15:54 on May 10, 2021

awesomeolion
Nov 5, 2007

"Hi, I'm awesomeolion."

Doc Block posted:

Maybe something like this

You’ll have to work out the vertices of your rectangle and transform them based on its rotation, but that’s pretty easy, especially in 2D (I believe Core Graphics has functions for translating and rotating 2D points that you could use).

You could also bring in SpriteKit’s physics engine, but that’s kind of overkill for such a simple case, especially if all you want is to know if two shapes overlap and don’t need all the bouncy physics results.

Thanks for your thoughts! I ended up moving the other parts of the game over to use the physics engine and it already feels like the right approach. So far I'm hoping that keeping as much of my colliders circles as possible will keep performance good. Anyway so far this feels like the way to go :)

smackfu
Jun 7, 2004

I’ve been playing with a little toy SwiftUI project and I’ve been a bit surprised that random updates to the OS or XCode (not sure which) have introduced new compilation errors. Is that typical? Am I doing something wrong?

For instance, I think I had a VStack that only had one child, because I had commented out the other, and now that is a compilation error.

KidDynamite
Feb 11, 2005

smackfu posted:

I’ve been playing with a little toy SwiftUI project and I’ve been a bit surprised that random updates to the OS or XCode (not sure which) have introduced new compilation errors. Is that typical? Am I doing something wrong?

For instance, I think I had a VStack that only had one child, because I had commented out the other, and now that is a compilation error.

I don't think they've made any major changes to SwiftUI in Xcode 12.5 and this definitely isn't the actual error. SwiftUI has wonky errors sometimes that are caused by statements earlier in the View struct.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
SwiftUI is a system framework, so Xcode won’t change the API. (An updated SDK included within Xcode can though, since a new OS can include API improvements.)

On the other hand, Xcode can include a new compiler that can enable improvements to how the API is called.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

awesomeolion posted:

Thanks for your thoughts! I ended up moving the other parts of the game over to use the physics engine and it already feels like the right approach. So far I'm hoping that keeping as much of my colliders circles as possible will keep performance good. Anyway so far this feels like the way to go :)

That's probably the best approach anyway. Detecting the intersection of even simple shapes can have a surprising number or edge cases, let alone arbitrary polygons. The "cheap" method is to rasterize and check pixels which is shockingly fast on modern hardware.

Using a physics engine is both more general and relies on someone else to have solved all the tricky edge cases with good performance.

prom candy
Dec 16, 2005

Only I may dance
In Swift is there a way to say "this var should be the same type as this other var"? In typescript we use typeof, so for example:

TypeScript code:
interface Goldfish {
  name: string;
  flesh: Meat;
}

interface Cat {
  name: string;
  favouriteFood: typeof Goldfish['flesh']
}
I haven't been able to find a way to do this in Swift but I might just be googling the wrong thing.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I'm not aware of a way. Closest I can think of is a typealias.

Though I did learn something about TypeScript today so thanks!

prom candy
Dec 16, 2005

Only I may dance
Dang ok, thanks!

Typescript is really powerful with that kind of stuff, you can use ReturnType<typeof someFunc> to get the return type, or use Pick<> or Omit<> to grab other types:

TypeScript code:
interface Snake extends Omit<Animal, 'legCount'> {
  slitherSpeed: ReturnType<typeof calculateAnimalSpeed>;
}

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Are you just trying to abbreviate things, or are you trying to express some important generic relationship between the types of operations?

prom candy
Dec 16, 2005

Only I may dance
I have a viewcontroller that's getting some data coming from another viewcontroller that gets it from a model. If I can say the data is of that type then if I change the model later I don't have to change anything else.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Okay. Sounds like a good use for a typealias, then.

Stringent
Dec 22, 2004


image text goes here
I've found myself in the rather novel (for me at least) position of needing a tree in an app I'm working on. Not to get too far into the weeds about it, but I've got a picker view with seperate year, month and day components and for any given year I only want months with content to show up, and for any given month days, etc. Is there anything built in with Swift or Foundation that I should be looking at instead of rolling my own? I've googled a bit and everything comes up with ppl rolling their own, but I don't know if that's just because ppl mostly search for this for interviews or what.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
There isn't really an "etc." there, right? It's just a three-level tree of years/months/days? I wouldn't over-think this; the complication of building your own general tree data structure instead of just having, like, [Int: [[Content]]] doesn't seem worthwhile.

Stringent
Dec 22, 2004


image text goes here
etc was potentially timestamps, but that's still just an if. point taken though, i'll just nest dictionaries for the time being, thanks.

uncle blog
Nov 18, 2012

So I'm presenting a VC over another using the present method. What's the common pattern regarding dismissing it. Is there an X in corner, the horizontal bar on the top to be dragged down? And is it something built in like an accessoryItem I can easily put in?

Edit:
This is Swift, and UIKit, with all views made programatically.

Froist
Jun 6, 2004

uncle blog posted:

So I'm presenting a VC over another using the present method. What's the common pattern regarding dismissing it. Is there an X in corner, the horizontal bar on the top to be dragged down? And is it something built in like an accessoryItem I can easily put in?

Edit:
This is Swift, and UIKit, with all views made programatically.

The simplest/most native way would be to nest the view controller in a UINavigationController to present, and add a Done/Cancel button as a navigation item - which then calls to a function in the ViewController to call self.dismiss().

Since iOS 13 you also get swipe-to-dismiss for free. You can set isModalInPresentation = true on the view controller to disable this.

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

Froist posted:

The simplest/most native way would be to nest the view controller in a UINavigationController to present, and add a Done/Cancel button as a navigation item - which then calls to a function in the ViewController to call self.dismiss().

Since iOS 13 you also get swipe-to-dismiss for free. You can set isModalInPresentation = true on the view controller to disable this.

Just be aware that you may get some odd behavior with the free swipe-to-dismiss. At one point at least, if you slightly swiped down but not enough to close it, or dragged it down and then back up, viewDidAppear() would be called again. If you aren’t expecting it to be called more than once, you may get problems.

I’m trying to fill an array as fast as I can to ultimately feed into a CGContext (right now just to generate a noise image. This is mostly for my own edification and entertainment). For some reason I can’t get close to the numbers quote me in this SO post:

https://stackoverflow.com/questions/45045811/swift-array-accessors-5-times-slower-than-native-arrays-which-are-the-recommen

I know it’s SO, but even copy and pasting all the various sample code given me results that are slower by about a factor of 5-10, including the examples with unsafe mutable pointers. This is into XCode itself, not a playground, and running on a 12 pro max and a 16inch Intel MacBook Pro, much newer than the 2017 date of the SO post.

I’m wondering if I am running into an optimization level issue. I thought I set the optimization level to fastest for both debug and release but maybe I’m not doing something correct.

Edit: turns out it was an optimization issue.
I was setting Apple Clang - Code Generation - Optimization Level instead of Swift Compiler - Code Generation - Optimization Level. Not sure how they are different yet but changing the Clang level doesn’t seem to do much for my purposes.

Edit 2: I believe Clang is used as the front end for Obj-C (and I assume C, C++, etc, hence “C Language”) while Swift uses Swiftc as the front end before both are then fed into LLVM.

Pulcinella fucked around with this message at 18:52 on May 26, 2021

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
You should always expect viewDidAppear to get called more than once. It's a common mistake to start tasks in viewWill/DidAppear that should either go in viewDidLoad (which is actually called at most once unless you're doing something really odd) or should include checking that you haven't already started the task.

Another way this comes up is cancelling an interactive pop gesture on a navigation controller.

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.

Glimm
Jul 27, 2005

Time is only gonna pass you by

lord funk posted:

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.

I usually set it up in loadView and let the constraints handle sizing

prom candy
Dec 16, 2005

Only I may dance
I always put view creation in viewDidLoad and it always works for me, using AutoLayout.

Glimm
Jul 27, 2005

Time is only gonna pass you by

I think viewDidLoad is fine too, though you might be replacing the root view sometimes in which case loadView makes more sense because you've got to set the root there anyway

If I've got to muck with layout after getting size information (adjusting constraint constants) I do it in viewDidLayoutSubviews, just be careful not to create a layout cycle.

uncle blog
Nov 18, 2012

So I'm trying to make a layout programatically, but getting tripped up on how to set constraints and position things. Is there a good resource/overview for all the different terms and what rules apply in the view hierarchy?

Glimm
Jul 27, 2005

Time is only gonna pass you by

One thing that made AutoLayout a lot better to me is layout anchors and Use Your Loaf has a really good post about them:
https://useyourloaf.com/blog/pain-free-constraints-with-layout-anchors/

I haven't read through Apple's docs here in awhile but this is probably good too, though you may have already seen it:
https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/index.html

Anything specific causing you issues?

prom candy
Dec 16, 2005

Only I may dance

uncle blog posted:

So I'm trying to make a layout programatically, but getting tripped up on how to set constraints and position things. Is there a good resource/overview for all the different terms and what rules apply in the view hierarchy?

I don't know if it's the best tool for the job but I use snapkit and its api is a lot nicer than the built in one.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I use built-in layout anchors plus a couple helper methods for things like "add subview and constrain to [edges]". But I'm maybe unhelpfully allergic to dependencies.

Also, the aforelinked Use Your Loaf has an entire book on Auto Layout, it's pretty good. If that's out of your budget, read all their blog posts :)

Stringent
Dec 22, 2004


image text goes here
i've got a snippet made for this pattern

code:
private let butte: UIView = {
	let view = UIView()

	return view
}()

private lazy var butteConstraints: [NSLayoutConstraint] = {
	self.view.translatesAutoresizingMaskIntoConstraints = false

	return [
	]
}

// in viewDidWhatever
view.addSubview(butte)
NSLayoutConstraint.activate(butteConstraints)
minus the names and view type of course


i don't know where i picked this up and it may be a dumb way of doing things, but it works for me.

KidDynamite
Feb 11, 2005

Has anyone interviewed at Apple for iOS positions?

Have an all day web interview to schedule and trying to figure out how much time to give myself and what to focus on for studying.

I’m definitely weak at CoreData so that’s one place I will need to tighten up.

Fate Accomplice
Nov 30, 2006




KidDynamite posted:

Has anyone interviewed at Apple for iOS positions?

Have an all day web interview to schedule and trying to figure out how much time to give myself and what to focus on for studying.

I’m definitely weak at CoreData so that’s one place I will need to tighten up.

there will be an entire session solely dedicated to concurrency/multithreading.

source: have bombed the multithreading interview.

twice.

uncle blog
Nov 18, 2012

Glimm posted:

Anything specific causing you issues?

Yeah, I get a:
code:
Terminating app due to uncaught exception 'NSGenericException', reason: 
'Unable to activate constraint with anchors <NSLayoutYAxisAnchor:0x6000029f0440 "UIStackView:0x7fde95461c80.top"> 
and <NSLayoutYAxisAnchor:0x6000029f0500 "UIView:0x7fde85635ad0.top"> because they have no common ancestor.  
Does the constraint or its anchors reference items in different view hierarchies?  That's illegal.'
Which seems to say that the anchors I try to connect are in different view hierarchies?

This is the code:
code:
    override func viewDidLoad() {
        super.viewDidLoad()
        populateUI()
    }

    func populateUI() {
        let stack = UIStackView()
        stack.translatesAutoresizingMaskIntoConstraints = false
        stack.axis = .vertical
        stack.alignment = .leading

        NSLayoutConstraint.activate([
            stack.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
            stack.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: .normalSpacing),
            stack.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -.normalSpacing),
            stack.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
        ])
        stack.addArrangedSubview(textView)
        stack.addArrangedSubview(button)

        view.addSubview(stack)
    }
Edit:
vvv Thanks! That simple, huh.

uncle blog fucked around with this message at 11:14 on May 31, 2021

Stringent
Dec 22, 2004


image text goes here
you gotta add the subviews before you activate the constraints

Adbot
ADBOT LOVES YOU

KidDynamite
Feb 11, 2005

Fate Accomplice posted:

there will be an entire session solely dedicated to concurrency/multithreading.

source: have bombed the multithreading interview.

twice.

Well poo poo. That’s def an area I need more experience with. Can you to point at any resources you think would have made you ace the section?

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