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
101
Oct 15, 2012


Vault Dweller

Glimm posted:

Static UITableViews? Maybe that's possible with xibs now.

SaTaMaS posted:

If you needed a customized UINavigationItem

Fair points. I've never needed to use static TableViews and do nav stuff programmatically.

Adbot
ADBOT LOVES YOU

brand engager
Mar 23, 2011

Ours has been entirely storyboard-based, don't think we have any .xibs in the repo. Each screen has it's own viewController and we use segues to go deeper into the UI flow. I don't know what the new one will use to handle any logic since swiftUI doesn't use viewControllers.

SaTaMaS
Apr 18, 2003
It sure is going to be awesome when junior developers start showing up who know SwiftUI + Combine but don't know the first thing about ViewControllers, Core Animation, or how to structure non-SwiftUI apps...:corsair:

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I don't think I've ever started a static table view that ended that way. Soon enough I want to do any sort of customization whatsoever, like hide a row sometimes, and it gets painful quick.

See also: not embedding any remotely sizeable view in a scroll view. Add a label, or "oh right small phones", and it's time to redo all your constraints but in a scroll view this time!

101
Oct 15, 2012


Vault Dweller
Still pretty confused and intimidated by scroll views. Is there any good resource that'll finally make them click?

and are the new frame and content layout guides the way to go? Seen a few different resources that mention different ways to set them up

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Start with these WWDC videos (don't mind that they're a few years old):

https://developer.apple.com/videos/play/wwdc2011/104/
https://developer.apple.com/videos/play/wwdc2012/223/
https://developer.apple.com/videos/play/wwdc2013/217/

There was also one in 2014 but the video seems to have been disappeared? https://asciiwwdc.com/2014/sessions/235

And then yep, if you're using auto layout then the newish content guides are great. https://useyourloaf.com/blog/easier-scrolling-with-layout-guides/ is a good overview.

Pulcinella
Feb 15, 2019

Pulcinella posted:

I also found this* https://developer.apple.com/forums/thread/134001?answerId=423820022#423820022

I haven’t had a chance to check but maybe the .nonAr camera mode is automatically set in the simulator and there is no error message (or documentation) to say this the case. I thought I tried on a physical device but maybe I didn’t.

* Forum tags are up
https://developer.apple.com/support/forums-tags/

I can confirm that this is the case. It works when building for a physical device, just not the simulator.

GenJoe
Sep 15, 2010


Rehabilitated?


That's just a bullshit word.

SaTaMaS posted:

It must be wonderful to not have to worry about capricious UX designers

oh my god please never let ux people touch xibs/storyboards

KidDynamite
Feb 11, 2005

SwiftUI is getting grids and stacks thank gently caress. I'm hype y'all.

https://developer.apple.com/documentation/swiftui/view-layout-and-presentation

Glimm
Jul 27, 2005

Time is only gonna pass you by

KidDynamite posted:

SwiftUI is getting grids and stacks thank gently caress. I'm hype y'all.

https://developer.apple.com/documentation/swiftui/view-layout-and-presentation

Still no backport :(

I really didn’t expect one, but drat it is frustrating.

Fate Accomplice
Nov 30, 2006




What are good/important/useful in daily programming life things I should know about NSRunLoop / CFRunLoop, and does anyone have good sources on where to learn such things?

Fate Accomplice fucked around with this message at 02:09 on Jun 23, 2020

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?
Depends on the layer where most of your work takes place. Most developers shouldn’t have to care about more than processing an event involving a single turn of the run loop.

Since I’ve implemented daemons and servers and stuff, I’ve had to care more; there I’ve mostly needed to know:

1. The main thread’s event processing autorelease pool is drained when the run loop is turned.

2. Asking for a run loop on a thread that doesn’t have one will create one. So don’t do it in something executed via dispatch.

3. A CFRunLoop underlies an NSRunLoop, in lower-level code you may need to interact with the underlying CFRunLoop.

4. If you’re implementing your own event processing, you can use a run loop source to put it together. Be sure to have some way to stop the run loop from outside, e.g. a -terminate method on your equivalent to NSApp.

There’s also subtleties around processing blocks submitted to the main queue and on the main run loop; for the stuff I work on we have an abstraction that means I don’t have to worry about the distinction, so I don’t remember what it is offhand.

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?
Oh yeah, if you’re given a choice between dispatch- and runloop-based API in new code, use the dispatch-based API. If you’re creating API, prefer dispatch-based API.

101
Oct 15, 2012


Vault Dweller

pokeyman posted:

Start with these WWDC videos (don't mind that they're a few years old):

https://developer.apple.com/videos/play/wwdc2011/104/
https://developer.apple.com/videos/play/wwdc2012/223/
https://developer.apple.com/videos/play/wwdc2013/217/

There was also one in 2014 but the video seems to have been disappeared? https://asciiwwdc.com/2014/sessions/235

And then yep, if you're using auto layout then the newish content guides are great. https://useyourloaf.com/blog/easier-scrolling-with-layout-guides/ is a good overview.

Thanks! I'll check them out when I get some time

Fate Accomplice
Nov 30, 2006





thanks for this, reading through it helped a lot.

Glimm
Jul 27, 2005

Time is only gonna pass you by

Is there a discord where goon mobile developers hang out?

I love following what folks on the forums are working on and would be really sad to see this community disappear, though it is pretty quiet these days.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I joined the CoC and YOSPOS discords, mostly as a backup plan and to find out if people move to some other forum en mass.

Glimm
Jul 27, 2005

Time is only gonna pass you by

pokeyman posted:

I joined the CoC and YOSPOS discords, mostly as a backup plan and to find out if people move to some other forum en mass.

Nice, I've just joined those as well

Froist
Jun 6, 2004

I found the YOSPOS one here but can’t find the CoC one? I don’t post here that often but I’ve lurked this thread daily for years, will be a shame if all this gets burned down :(

Pulcinella
Feb 15, 2019

pokeyman posted:

There was also one in 2014 but the video seems to have been disappeared? https://asciiwwdc.com/2014/sessions/235

For some reason a lot of the 2014 WWDC videos were taken down earlier this year. They should still be downloadable from the server if you can find a link.

Glimm
Jul 27, 2005

Time is only gonna pass you by

Froist posted:

I found the YOSPOS one here but can’t find the CoC one? I don’t post here that often but I’ve lurked this thread daily for years, will be a shame if all this gets burned down :(

I found Goon Discord Network in a GBS post. It has a link to the CoC Discord (https://discord.gg/JFwAarN).

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

ketchup vs catsup posted:

thanks for this, reading through it helped a lot.

Run loop sources use the info field to identify themselves so if you don’t fill it out with a unique value all but one of your sources will be ignored and not added to the run loop.

Use of run loop modes can allow re-entrant processing which is a blessing and a curse. A blessing because sometimes you can’t control dependencies and it lets you avoid deadlocks, especially across processes. A curse because seriously WHAT THE gently caress.

As eschaton says don’t mix run loops and dispatch. You’ll be sorry.

But you can submit blocks to a run loop you own - or any work really. Create a run loop signaling source you add to the loop, enqueue whatever work you have for the loop, signal the source, then wake the loop (all from some other thread or dispatch queue).

frogbs
May 5, 2004
Well well well
I’m completely new to iOS development and have a simple app I want to try to make. In 2020, is starting with SwiftUI my best bet? I’ll be honest, it’s a little confusing figuring out the differences between AppKIt, Uikit, Catalyst and SwiftUI, but I think I’m starting to get it.

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

frogbs posted:

I’m completely new to iOS development and have a simple app I want to try to make. In 2020, is starting with SwiftUI my best bet? I’ll be honest, it’s a little confusing figuring out the differences between AppKIt, Uikit, Catalyst and SwiftUI, but I think I’m starting to get it.

Yes I would start with SwiftUI.

TheReverend
Jun 21, 2005

Simulated posted:

Yes I would start with SwiftUI.

For iOS.
Ignore app kit.

SwiftUI is the future but if this interests you as a career at all I'd say go with UIKit because almost every codebase will be UIKit.

Pulcinella
Feb 15, 2019

frogbs posted:

I’m completely new to iOS development and have a simple app I want to try to make. In 2020, is starting with SwiftUI my best bet? I’ll be honest, it’s a little confusing figuring out the differences between AppKIt, Uikit, Catalyst and SwiftUI, but I think I’m starting to get it.

AppKit: The previous, long running way of making native Mac apps. Not deprecated or anything (at least not yet), but it’s probably not a good use of your time trying to learn it.

UIKit: The previous, long running way of making native iOS apps. Still going strong and Apple continues to develop it, but it’s not the latest UI framework.

Catalyst: A way of running UIKit apps on the Mac. (Basically running an iPad app on the Mac). Nice if you already have an iPad app that you also want release for the Mac. If you are starting from scratch though catalyst was obsoleted by SwiftUI pretty much as soon as it was released.

SwiftUI: Apple’s latest UI framework that can be used to write iPhone, iPad, Mac, Watch, and tvOS apps. Still somewhat in it’s early days but it’s where the future is. Definitely start with it if you are just learning and want to make a simple app. Just know that most iOS apps are still UIKit apps.

brand engager
Mar 23, 2011

I had an annoying timewaster where I didn't know why stuff wrapped in AnyView wouldn't show up. Like this would compile but not have anything visible:
code:
AnyView {
    Text("aaaa")
}
I had to dig through the .swiftinterface to find the init declarations for it. Anyview has these two
code:
init<V>(_ v: V)
init?(_ v: Any)
closures can be Any, so passing it a closure like you would with other swiftUI views will compile but the initialiser will fail. The way that works is to call it like
code:
AnyView(Text("aaaa"))

frogbs
May 5, 2004
Well well well

Pulcinella posted:

AppKit: The previous, long running way of making native Mac apps. Not deprecated or anything (at least not yet), but it’s probably not a good use of your time trying to learn it.

UIKit: The previous, long running way of making native iOS apps. Still going strong and Apple continues to develop it, but it’s not the latest UI framework.

Catalyst: A way of running UIKit apps on the Mac. (Basically running an iPad app on the Mac). Nice if you already have an iPad app that you also want release for the Mac. If you are starting from scratch though catalyst was obsoleted by SwiftUI pretty much as soon as it was released.

SwiftUI: Apple’s latest UI framework that can be used to write iPhone, iPad, Mac, Watch, and tvOS apps. Still somewhat in it’s early days but it’s where the future is. Definitely start with it if you are just learning and want to make a simple app. Just know that most iOS apps are still UIKit apps.

This clarifies things so much, thank you! Will start with SwiftUI.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

brand engager posted:

I had an annoying timewaster where I didn't know why stuff wrapped in AnyView wouldn't show up.

Oof, that's a rough one.

frogbs posted:

I’m completely new to iOS development and have a simple app I want to try to make. In 2020, is starting with SwiftUI my best bet? I’ll be honest, it’s a little confusing figuring out the differences between AppKIt, Uikit, Catalyst and SwiftUI, but I think I’m starting to get it.

SwiftUI is a good place to start. UIKit is there for anything you need that's missing from SwiftUI, and the SwiftUI tutorial even covers how to do that. You can ignore AppKit and Catalyst.

It's true that you won't see many SwiftUI codebases out in the world, so if your goal is to get a job or something then maybe app number two or three should be UIKit? No need to worry about it in the beginning though.

frogbs
May 5, 2004
Well well well
Anyone else unable to get previews to load in the XCode 12 beta? I get "Cannot preview in this file - failed to launch *app*", the erro in diagnostics reads "HumanReadableNSError: The operation couldn’t be completed. (OSStatus error -10825.)". I tried a completely blank app, as well as this guy's SwiftUI sample and got the same thing: https://github.com/jordansinger/mail-swiftui-sample.git

I'm not a 2012 Mac Mini on Catalina with 16gb of ram, which i'd imagine is just about the lowest end thing that could run XCode at this point, so maybe that's my problem...

Edit: I think I figured out what I was doing wrong, his example code for that app won't run on something that isn't running Big Sur and isn't multiplatform. The blank test app I was making also wasn't targeted to my MacOS version, so it failed.

If I target any of the iOS simulators with a blank app things work fine! I also tried this multiplatform SwiftUI example and it works well on simulators: https://github.com/jordansinger/messages-multiplatform-swiftui-sample

frogbs fucked around with this message at 00:34 on Jul 1, 2020

mrbass21
Feb 1, 2009
I know this isn't completely on topic, but I'm trying to do Swift work on an Ubuntu install with VSCode (algorithms and data structures practice really), and everything works great except debugging. I've installed the most common lldb extension (CodeLLDB) and filled out the launch json. It launches, I can set breakpoints and step, etc, but I don't get variable information the way I expect.

For instance the following code is a really simple example

let myVar = 5

print("Hello, world!")

All I want to be able to do is look in the variable window and see the value in the locals, or watch window, but it looks like the only name that it finds is some mangled name. When I type `p myVar` in the debug console in VS, it returns as though it has no value.

I compiled the file with the -g switch, and if I load the file in lldb directly, I can print out the value of myVar. I'm just at a loss as to why I can't seem to get variable information through VS Code and the lldb extension.

I've tried multiple versions of Swift, and Ubuntu. Worst case I can just get good with command line lldb, which is probably a really useful skill to have that I don't currently have, but for ease, I'd really like to get VS Codes debugger working. Does anyone have any hints or thoughts as to what might be wrong or something I could try?

Thanks!

mrbass21 fucked around with this message at 19:46 on Jul 4, 2020

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
If it works in the command-line lldb, the problem’s probably at the VSCode extension layer.

mrbass21
Feb 1, 2009

rjmccall posted:

If it works in the command-line lldb, the problem’s probably at the VSCode extension layer.

Thanks for the reply. That was my suspicion too.

I just thought maybe I was doing something wrong. I see guide after guide setting things up the exact way I did and saying it works (I even tried Ubuntu 18.04 and Swift 5.0, which is exactly what another guide used), so unless VSCode made some update that broke it or the authors never actually tested that it worked, I figured I was doing something incorrectly.

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?

frogbs posted:

Edit: I think I figured out what I was doing wrong, his example code for that app won't run on something that isn't running Big Sur and isn't multiplatform. The blank test app I was making also wasn't targeted to my MacOS version, so it failed.

That’s exactly the case: New SwiftUI APIs are part of the operating system, not the compiler, so you can only preview them if you’re running the OS that has them (either natively in the case of macOS, or via a Simulator in the case of iOS/tvOS/watchOS).

limaCAT
Dec 22, 2007

il pistone e male
Slippery Tilde
Is there a way to associate a constant or a series of constant variables to an enum, like you can do in Java with the private enum constructors?

I would like to avoid making giant switch blocks like this:

code:
enum Suit {

  case spades, hearts, diamonds, clubs
  func simpleDescription() -> String {
    switch self {
    case .spades:
      return "spades"
    case .hearts:
      return "hearts"
    case .diamonds:
      return "diamonds"
    case .clubs:
      return "clubs"
    }
  }

  func color() -> Color {
    switch self {
    case .spades:
      return Color.black
    case .hearts:
      return Color.red
    case .diamonds:
      return Color.red
    case .clubs:
      return Color.black
    }
  }

}
edit: Nevermind, I found this workaround. I just hope it's idiomatic...

code:
enum SuitDefinition {

  case spades, hearts, diamonds, clubs

}

struct Suit {

  var description: String
  var myColor: Color
  init(
    _ input: SuitDefinition
  ) {
    switch input {
    case .spades:
      description = "spades"
      myColor = Color.black
    case .hearts:
      description = "hearts"
      myColor = Color.red
    case .diamonds:
      description = "diamonds"
      myColor = Color.red
    case .clubs:
      description = "clubs"
      myColor = Color.black
    }
  }

  func simpleDescription() -> String {
    return description
  }

  func color() -> Color {
    return myColor
  }

}

limaCAT fucked around with this message at 10:38 on Jul 7, 2020

Froist
Jun 6, 2004

For that exact example (playing card suits) this is how I would define it:

code:
enum Suit: String {
  case hearts = "hearts"
  case spades = "spades"
  case diamonds = "diamonds"
  case clubs = "clubs"

  func simpleDescription() -> String {
    return self.rawValue
  }

  func color() -> UIColor {
    switch self {
    case .spades, .clubs:
      return UIColor.black
    case .hearts, .diamonds:
      return UIColor.red
    }
  }
}
It makes more sense to group all the constants for a given property inside a function (like color here) rather than defining them per-enum value in a giant initialiser.

Say you wanted to add a new property (e.g. royalCardFacesDirection): this way you can define another encapsulated function to handle it, whereas the init way you'd add 4 new lines intersperced through the initialiser.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

limaCAT posted:

Is there a way to associate a constant or a series of constant variables to an enum, like you can do in Java with the private enum constructors?

I'm not sure whether it's idiomatic, but this is another approach to consider:

code:
struct Suit {

  static let spades = Suit("spades", .black)
  static let hearts = Suit("hearts", .red)
  static let diamonds = Suit("diamonds", .red)
  static let clubs = Suit("clubs", .black)

  let description: String
  let color: Color

  private init(
    _ description: String,
    _ color: Color
  ) {
    self.description = description
    self.color = color
  }
}
If I start making an enum with a bunch of computed properties that all take the form switch self {…}, I will change it to the above. Call sites are identical. CaseIterable won't implement itself and you won't get switch statement exhaustion checks, so those can be good reasons to stick with an enum.

All that said, for something like card suits that seems unlikely to gain new cases, I would go with an enum. This struct approach can be nice when you have some common or default values as static vars, but also want to make the initializer nonprivate to allow for new instances as desired.

Fate Accomplice
Nov 30, 2006




Last week I interviewed at a company for an iOS position, and one of the technical interviews was:

A method in objective c was posted into coder pad, that dispatches to various queues, some threads performing some simple calculations and other threads printing out results.

Next the interviewer posted a rudimentary test harness and said “QA says these tests are failing because x occurs” where x is some kind of unexpected result or the code never returns.

The interviewer told me I could ask any questions I wanted, and he would give me QA’s response if I was making a code change, or talk through my logic for debugging.

I don’t know how many situations like this he had ready to go, but in 50 minutes I solved the first one and with help had gotten to the end of the second.

I didn’t get the job, which is legit, cause I don’t have experience doing this kinda stuff.

My question is, if I want to get better at debugging multithreading bugs like this without being able to use instruments, how can I do that? What can I study for it?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Thread Sanitizer is your best friend whenever threads are involved. Otherwise, it's tricky because a lot of issues are hard to recognize without a more complete understanding of concurrency. If a system seems to have stopped responding — either the UI has locked up or some internal system doesn't seem to ever respond to queries — something has probably deadlocked. If things aren't happening in a reliable order, you probably have a race, and there's something earlier that's supposed to make sure they happen in order. If some object looks like it's not fully initialized, but you're sure the code set it up right, you might have a memory-ordering problem.

Adbot
ADBOT LOVES YOU

lord funk
Feb 16, 2004

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

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

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

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

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