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
Plorkyeran
Mar 22, 2007

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

dizzywhip posted:

Editing the file will take it out of the transient state, and it will stay open until you explicitly close it.

:psyduck:

Well I guess that explains the behavior but that's certainly not something I ever would have guessed and it's trying way too hard to be clever.

Adbot
ADBOT LOVES YOU

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

dizzywhip posted:

I think what's tripping you up is that when you first open a tab, it's in a special transient state indicated by an italic font for the title. If you open another file while a transient tab is open, it will replace the content of the transient tab rather than opening a new tab. Editing the file will take it out of the transient state, and it will stay open until you explicitly close it. You can also use the File > Open in Tab command (or ⌥⌘O) to do the same thing without having to edit the file. So I've gotten in the habit of running that command on each tab that I open when I know that I need to work with multiple files.

You can also double-click an italic tab to keep it open. I've been doing that when I know I'll need a few files to stay open.

I also tend to close all tabs when I'm done with the current task, which I inefficiently do by right-clicking a tab and choosing "Close Other Tabs" then command-W the last tab.

Also each split can have its own italic tab.

ModeSix
Mar 14, 2009

I am curious about something.

Unless I really plan to do a deep dive and want to be an Apple specific developer, is there any benefit to me learning Swift/UIKit etc. as opposed to sticking with something like React Native (Expo)?

I had done a lot of Apple development some years ago (2010-2013 maybe) and wonder if I really need to learn the Apple specific stack or if sticking with something like RN will do everything I need?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I think you hit the nail on the head, it depends on whether React Native has everything you need.

If some component is missing (e.g. iOS 15 has some new thing and RN is slow to support it), you'll be diving into SwiftUI or UIKit pretty quick. iOS-specific knowledge might help evaluate whether some random third party RN component is worth using. And it might be relevant when debugging or profiling a RN app?

All three of those circumstances seem like a decent place to start/resume learning about iOS specifics, and if they never come up then all the better!

edit: There's maybe some bits that RN doesn't support at all, like home screen widgets or watch apps? I have no idea what the story is there but it seems like it would be complicated.

KidDynamite
Feb 11, 2005

I just got owned for like 3 hours by UIStackView.removeArrangedSubview(_:)

you have to call removeFromSuperview() on the view as well to prevent it from actually appearing on the screen

I'm going to get chewed up and spit out during this Apple interview.


ModeSix posted:

I am curious about something.

Unless I really plan to do a deep dive and want to be an Apple specific developer, is there any benefit to me learning Swift/UIKit etc. as opposed to sticking with something like React Native (Expo)?

I had done a lot of Apple development some years ago (2010-2013 maybe) and wonder if I really need to learn the Apple specific stack or if sticking with something like RN will do everything I need?

Only learn as much as you need if you don't plan on being an iOS developer. tbh i feel like it's more of a pain being an iOS dev when it comes to job search time.

take boat
Jul 8, 2006
boat: TAKEN

KidDynamite posted:

I just got owned for like 3 hours by UIStackView.removeArrangedSubview(_:)

you have to call removeFromSuperview() on the view as well to prevent it from actually appearing on the screen
that's an annoying one, pretty sure I've forgotten that and also confused myself. it's called out in the method documentation at least

you don't need to call both though, calling removeFromSuperview is sufficient

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Also stack views now draw their background color. Just in case stack view trivia forms a core component of the interview gauntlet :v:

astral
Apr 26, 2004

Just a friendly heads-up that Swift is one of the languages now officially supported in the recently-updated [code=thing] tags. Enjoy!

Full list of supported languages/language aliases available here.

KidDynamite
Feb 11, 2005

got got by the concurrency question even though Fate Accomplice warned me. RIP

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

KidDynamite posted:

got got by the concurrency question even though Fate Accomplice warned me. RIP

My condolences, but also spill the beans!

I imagine I would crash and burn as well. We don’t really do any concurrency outside of the standard “REST API call on a background thread, then update the UI with the results in the main thread).”

Fate Accomplice
Nov 30, 2006




KidDynamite posted:

got got by the concurrency question even though Fate Accomplice warned me. RIP

rough!


Pulcinella posted:

My condolences, but also spill the beans!

I imagine I would crash and burn as well. We don’t really do any concurrency outside of the standard “REST API call on a background thread, then update the UI with the results in the main thread).”


it boggles the mind that a) people clearly still get jobs at apple writing iOS and b) no one is able to point to a single resource to learn this stuff practically than https://developer.apple.com/library.../uid/TP40008091

smackfu
Jun 7, 2004

You would think Apple would hire good developers and then train them in iOS details vs expecting people to be iOS experts in areas that no one outside Apple is too concerned about.

I guess everyone wants to work for Apple though so you can hire whoever you want.

Vesi
Jan 12, 2005

pikachu looking at?

smackfu posted:

You would think Apple would hire good developers and then train them in iOS details vs expecting people to be iOS experts in areas that no one outside Apple is too concerned about.

I guess everyone wants to work for Apple though so you can hire whoever you want.

maybe it's like with those exclusive clubs, you have to know someone who's already in (to give you hints on what gotchas to look out for)

or you end up repeating the process so many times the sunk cost will make you appreciate the job more and demand less

KidDynamite
Feb 11, 2005

ask was to design a function that accepts closures as the arguments and will execute up to 5 of them on concurrently and store any others to execute them as the closures complete.

Stringent
Dec 22, 2004


image text goes here

KidDynamite posted:

ask was to design a function that accepts closures as the arguments and will execute up to 5 of them on concurrently and store any others to execute them as the closures complete.

i guess that's expecting you to know about DispatchGroups, which i would totally have to reach for the manual for, i don't think i've ever had to use them in anger. reasonably well documented tho, afaik.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Sounds like OperationQueue to me. Set the max concurrent operations property and toss BlockOperations on to the queue.

(Guessing the next question would be "ok pretend you don't have OperationQueue", at which point I think to myself "ah, because we're working on the Apple platform that doesn't have Foundation available".)

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
They’re probably not expecting you to know specific concurrency APIs, just to have some idea of what it takes to do those things.

Plorkyeran
Mar 22, 2007

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

pokeyman posted:

Sounds like OperationQueue to me. Set the max concurrent operations property and toss BlockOperations on to the queue.

(Guessing the next question would be "ok pretend you don't have OperationQueue", at which point I think to myself "ah, because we're working on the Apple platform that doesn't have Foundation available".)

Or because they're hiring you to work on OperationQueue.

Even if the position is for just normal iOS app development, a decent rule of thumb is that you should be reasonably familiar with one level of abstraction below the one where you're working. Modern computing is way too complicated for anyone to master the entire stack that we build applications on, but the layer that you're building on top of is inevitably going to have bugs and quirks that you need to deal with. It's a lot easier to understand how to use an OperationQueue correctly if you know enough to be able to implement a naive version of it yourself using lower-level threading APIs.

I don't have any particular insight into what Apple specifically is looking for, but one thing I've observed in both developing iOS apps and in looking at code that our customers send to us is that benign concurrency related bugs are nigh omnipresent. It's very rare to look at some code using GCD and not spot at least one race condition, usually because they don't actually matter in that specific scenario. If there's a one in a billion chance of an app displaying the wrong text in a cell for a few frames, that's just not a bug worth thinking about. However, this means that it's possible to write a great app that makes heavy use of GCD where concurrency-related bugs aren't causing problems for users, but still not have a great grasp on how to write correct concurrent code (if anyone can truly be said to be great at that). I suspect that Apple thinks they need those developers who have a decent shot at writing correct threaded code rather than threaded code which is merely free of important bugs.

It could also just be a dumb question where they think that people good at threading must be good at everything that matters, of course.

KidDynamite
Feb 11, 2005

The way I understood it is that an Apple iOS dev isn’t programming with the same rules as regular iOS devs. You have access to more background and low level apis and also be writing your own so they want to see how you think about concurrency because you will be writing daemons that get used by more than just your app.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Plorkyeran posted:

Or because they're hiring you to work on OperationQueue.

Yeah I know. It'd still be my first answer!

Well, no, my first answer would be "can we not?" and run the blocks synchronously with a lock because that's "up to five".

uncle blog
Nov 18, 2012

I'm trying to do something that my webdev brain thinks should be really simple, but somehow I'm not sure how best to do this. I want to pass a function from a vc to a child vc as a paramter when initialising the child vc.

I want to use it like this
code:
class ParentVC: UIViewController {
	...
	@objc func apiCall() {}

	let childVC = ChildVC(message: "Some text", action: apiCall)
	self.present(childVC)
	...
}
And I assumed I could do something like this in the child VC:
code:
class ChildVC: UIViewController {
	let message: String
	let action: () -> Void

	let actionButton = Button()

	init(message: String, action: () -> Void) {
		self.message = message
		self.action = action
		super.init()
	}

	override func viewDidLoad() {
	       	super.viewDidLoad()
		actionButton.addTarget(self, action: #selector(action), forControlEvents: .TouchUpInside)
	}
}
But I guess this is not the way to do it?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I would expect that to work. Are you getting an error?

The child doesn't have an objc-visible method called action, so maybe the button isn't doing anything?

Finally, be careful about a strong reference cycle, as the parent passing in action is actually passing in self.action. You're ok here so long as the child gets dismissed somehow, but it's the kind of thing I've messed up many times so I thought I'd mention it :).

101
Oct 15, 2012


Vault Dweller
Made a few changes to make it build

Swift code:
class ParentVC: UIViewController {
	
	@objc func apiCall() {}
	
	func test() {
		
		let childVC = ChildVC(message: "Some text", action: apiCall)
		self.present(childVC, animated: true)
	}
}
Swift code:
class ChildVC: UIViewController {
	
	let message: String
	@objc let action: () -> Void
	
	let actionButton = UIButton()
	
	init(message: String, action: @escaping () -> Void) {
		
		self.message = message
		self.action = action
		
		super.init()
	}
	
	required init?(coder: NSCoder) {
		fatalError("init(coder:) has not been implemented")
	}
	
	override func viewDidLoad() {
		super.viewDidLoad()
		
		actionButton.addTarget(self, action: #selector(getter: action), for: .touchUpInside)
	}
}
Not sure if that'll work for you but hopefully it does.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Either I've been missing out or that button action still won't do anything. Gotta make a method that calls the passed-in block.

101
Oct 15, 2012


Vault Dweller

pokeyman posted:

Either I've been missing out or that button action still won't do anything. Gotta make a method that calls the passed-in block.

Yeah I just quickly mocked it up with some xibs and you'll need something like

Swift code:
@objc func btnPressed() {
        
        action()
}
in the ChildVC

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?
Yeah, one of the fundamentals of Cocoa’s target-action model is using a method for the action rather than a closure; it lets you loosely rather than tightly couple actions, and allow “the same” commands to be used easily with multiple code paths via the responder chain.

This probably seems weird to people who insist on doing things the hard way and using code for everything, since we designed everything to be used with Interface Builder from practically day one (Bill Parkhurst and Jean-Marie Hullot worked together on the AppKit-IB design at NeXT).

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
iPadOS 14.2's focus stuff changed the responder chain when Full Keyboard Access is enabled and it made me mad because I was trying to use the responder chain like a good boy. No idea if this was an intentional change. FB8944717 if anyone is curious.

Glimm
Jul 27, 2005

Time is only gonna pass you by

eschaton posted:

This probably seems weird to people who insist on doing things the hard way and using code for everything

Fwiw I've spent a lot of time doing it both ways and laying out in code is easier over the long term imo.

Now most of our new stuff is SwiftUI which is even easier but also still code.

Pulcinella
Feb 15, 2019
Probation
Can't post for 10 days!
Is there a good primer to C++/Metal Shading Language syntax for someone largely used to Swift style syntax? Trying to learn Metal but reading C++ is a pain. Also, mandatory semicolons were a mistake.

Doc Block
Apr 15, 2003
Fun Shoe
The Metal Shading Language from Apple

Also try Metal by Example

Also Apple’s Metal sample code.

uncle blog
Nov 18, 2012

I have structs which include variable which is enum of a new struct. I would like to filter out instances with a certain enum.

This is a simplified example of the struct:
code:
struct Application: Hashable {
	let id: String
	let title: String
	let state: State

	struct Pending: Hashable {
		requestedAt: Date
	}

	struct Approved: Hashable {
		approvedAt: Date
	}

	enum State: Hashable {
		case pending(Pending)
		case approved(Approved)
	}
}
I have an array of instances, where I'd like to filter out the ones with the approved state:
code:
	let applications = [application1, application2, application3, application4, ...]

	let approvedApplications = applications.filter {
		$0.state == Application.State.Approved.Type // or something?
	}
So I'm not sure of the syntax in the filter closure to get this to work.

VVVV
Well that works, so thanks!

uncle blog fucked around with this message at 18:18 on Jul 28, 2021

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

uncle blog posted:

I have structs which include variable which is enum of a new struct. I would like to filter out instances with a certain enum.

This is a simplified example of the struct:
code:
struct Application: Hashable {
	let id: String
	let title: String
	let state: State

	struct Pending: Hashable {
		requestedAt: Date
	}

	struct Approved: Hashable {
		approvedAt: Date
	}

	enum State: Hashable {
		case pending(Pending)
		case approved(Approved)
	}
}
I have an array of instances, where I'd like to filter out the ones with the approved state:
code:
	let applications = [application1, application2, application3, application4, ...]

	let approvedApplications = applications.filter {
		$0.state == Application.State.Approved.Type // or something?
	}
So I'm not sure of the syntax in the filter closure to get this to work.

I think you're stuck with an if case or a switch, e.g.
Swift code:
applications.filter {
  switch $0.state {
    case .approved: return true
    case .pending: return false
  }
}
but I'm curious if anyone has something nicer!

dc3k
Feb 18, 2003

what.
If you only care about state:
code:
let approvedApplications = applications.filter {
    if case .approved = $0.state { 
        return true
    }
    
    return false
}
If you care about the approvedAt value:
code:
let someOtherDate = Date() // or whatever
let approvedApplications = applications.filter {
    if case let .approved(approved) = $0.state, approved.approvedAt < someOtherDate {
        return true
    }
    
    return false
}

commie kong
Mar 7, 2019

Does anyone know of a way to overcome this Xcode13 error without adjusting the target version? It appears to have been immediately closed as wontfix and I'm stumped.

From googling, it seems to have caught people by surprise.

https://bugs.swift.org/browse/SR-14878 posted:

Enum cases with associated values cannot be marked potentially unavailable with '@available'

Code that uses @available for enum cases that have associated values no longer compiles:

code:
enum Foo {
@available(iOS 13.0, *)
case bar(Int)
case baz
}
This code compiled fine in Xcode12, but doesn't in Xcode 13 (both beta 1 and 2)

awesomeolion
Nov 5, 2007

"Hi, I'm awesomeolion."

Anyone have ideas for how to prep for an iOS system design interview? My
ideas so far are going through the objc io architecture book and reading random medium articles that show up when i google ios system design interview.

Centrist Committee
Aug 6, 2019
I created a new universal SwiftUI app, Xcode gave me iOS and MacOS folders with separate Info.plist files. Is there a way to share values between them, or do I need to add to both?

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?
You need to add to both, as iOS and macOS use different underlying UI frameworks (UIKit and AppKit).

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?
With Xcode 13, there’s Info.plist generation, so you can put stuff to share between them in the project’s build settings or in an xcconfig file (for supported Info.plist keys, it’s not an open-ended system).

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

eschaton posted:

With Xcode 13, there’s Info.plist generation, so you can put stuff to share between them in the project’s build settings or in an xcconfig file (for supported Info.plist keys, it’s not an open-ended system).

Is interpolation via $(…) no longer recommended? Works well if you're ok specifying the key everywhere, as you can define the value once in a project-wide build setting.

OP, you can also run the C preprocessor over your Info.plist but that is kinda gross.

Adbot
ADBOT LOVES YOU

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?
You can do interpolation via $() as well, it can be useful in an Info.plist source file used with just the non-build setting keys

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