r/swift • • Jun 04 '19

Me on swiftUI "Draw a shape" tutorial...

Post image
431 Upvotes

29 comments sorted by

14

u/[deleted] Jun 04 '19

in wwdc when they showed how that huge code sample could be shortened to 5 lines everyone clapped but i just died inside. how do u even begin to learn how to shorten and write code that concise.

25

u/Rednaxila Jun 04 '19

I think you’re referring to the massive-ass UITableViewController they showed a quick glimpse of. For something so commonly used in a ton of apps, the code necessary to create a simple UITableView (up until now) has been waaaay overly complicated. I understand that they were coming from the Objective-C template; however, I was surprised to see it brought over into Swift as a near-exact translation.

It really didn’t need to be as complex as it has been for all these years (unless you’re creating a table with complex features, appearances and/or purposes). TableViews should be an easy, intro lesson for beginners – not an intermediate, 4-hour teaching seminar. Go look up any of the Objective-C and Swift tutorials for TableViews currently out there and the guides will have far too many steps, with far too many places to go wrong. The comments are filled with errors received by users who got lost in the complexity of it all.

This should hopefully make things a lot easier for people to get started. This was the intention of Swift.

5

u/[deleted] Jun 04 '19

Totally for it and the way they've managed to simplify the code is obviously beautiful and good in the long run.

1

u/kys1116123 Jun 05 '19

I agree with my husband.

1

u/Kish_v Jun 06 '19

Wait you're married??? Since when! Edit: Having thought about this a lot recently it's probably for the best if we end our little fling, you go take care of your 3 kids.

1

u/kys1116123 Jun 06 '19

That's right you dumb slut, you weren't invited, go drown in a sea of liquor after your 8th divorce, people like you never change and Paul and I felt compelled to exclude you from the ceremony because we just knew you'd make it a big scene.

Tldr- eat shit and die

1

u/[deleted] Jun 06 '19

sorry who are you? this sub is for coding, not kink shaming. if you wanna get "schwifty" this isnt the correct sub.

0

u/john_alan iOS + OS X Jun 05 '19 edited Jun 05 '19

OK question for you as you're a guy who gets it.

I'm a person who is comfortable coding tableViews by hand in a ViewController, completely in code.

Will I now have all my async calls nested inside that H-Stack/V-Stack? It's like their coupling controller and view.

We can't do everything in a react style, and I don't understand why they want to couple view and controller logic.

1

u/jNSKkK Jun 05 '19

No.

The view code displays information from your model. Elements in your UI are binded to properties on your model, causing the element to update when the property changes.

Your asynchronous code could be wherever you like - when it’s triggered and time to update your model, you update it. The elements update because they are binded to properties on the model that will presumably be updated by your asynchronous code.

Either that, or you can manually declare that your model has been updated by conforming to the protocol they also mentioned in the state of the union keynote - BindableObject, from memory. You provide an array of items for your UI code to display, then the UI will be automatically updated when the models change.

Neat, hey?

1

u/john_alan iOS + OS X Jun 05 '19

Thanks my friend, yes indeed, that is pretty neat.

So we will still have UIViewControllers to write?

2

u/lgcyan Jun 27 '19

No, looks like view controllers are out. Haven’t seen any mention of them. Your question is a good one. It seems they expect controller logic to be in functions inside views and model-specific logic in the model. The views in SwiftUI are more like controllers than views as the actual views are still rendered by the standard UIKit/AppKit/etc classes. Seems a bit messy from an abstraction point of view.

1

u/jNSKkK Jun 05 '19

Yep, I’d say so.

Think of the declarative syntax as being a way to declare the views for your view controller.

42

u/Maystackcb Jun 04 '19

Start coding.

1

u/jeremr Jun 04 '19

Practice

0

u/s73v3r Jun 05 '19

Practice.

0

u/[deleted] Jun 04 '19

[deleted]

15

u/[deleted] Jun 04 '19

Nah this years wwdc showcasing swift ui.

5

u/iFlexicon Jun 04 '19

Well the whole idea is that it's less code because SwiftUI is built from the ground up to allow you to craft UI's entirely in code. Which UIKit was really never intended to do, hence why it's so much more verbose.

1

u/[deleted] Jun 04 '19

Nah ik its a good thing

4

u/mynewromantica Jun 04 '19

I'm planning on going through some of those tutorials today. This does not give me hope

2

u/rennarda Jun 05 '19

I think the hard part is not learning Swift UI, but unlearning UIKit/AppKit.

I’m reading those tutorials thinks “oh look, a UITableView. A UIScrollView. A UICollectionView” and yet it’s *none of those things. *

I understand why the branding of WWDC this year was 🤯

1

u/certainly123 Jun 05 '19
  1. swiftUI

  2. UIKIT

0

u/[deleted] Jun 05 '19

[deleted]

3

u/psycho-inked-alien Jun 05 '19

Hi, this a joke refering the Drawing Paths and Shapes section where we draw the Badge element. The tutorial are pretty cool for an introduction actually. One think that I would like to be better explained is how state is shared/passed between views (the environment part).

0

u/[deleted] Jun 04 '19

[deleted]

5

u/Lispomatic Jun 04 '19

Try generative!

0

u/[deleted] Jun 04 '19

[deleted]

5

u/nrith Jun 04 '19

Correct. Like /u/sneeden says, you can run it on earlier versions, but you won't get the live view, and without the live view, the tutorials aren't terribly helpful.

2

u/theswifty7 Jun 04 '19

You can use playground on Xcode 11 beta on Mojave too.

2

u/sneeden Jun 04 '19

I'm on Mojave. The live preview doesn't work for first beta, but you can run it like normal