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.
 
  • Locked thread
pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Doh004 posted:

Perhaps that wasn't the best example ever. I guess I'm more curious to people's thoughts as to when enums should own responsibility of more than just their values.

I'm struggling to come up with a convincing reason for the enum to have anything unrelated to its value. You can certainly have methods, computed properties, and so on, but I reckon they shouldn't involve much beyond the enum itself.

Adbot
ADBOT LOVES YOU

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

rjmccall posted:

In this matter, I counsel patience.

So excited. Have an awesome week.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Doctor w-rw-rw- posted:

Any chance that we can get swift code formatting support (a la clang-format)? I like being sloppy with my spaces, and lament its loss.

In the meantime, there's SwiftLint, which doesn't do quite what you want but might give you some ideas if you get antsy.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

lord funk posted:

Is it possible to store an array of class types? I have a group of classes that conform to a protocol which declares a static variable.

code:
protocol ThingConforming {
    static var aThing: String { get }
}

class Foo: ThingConforming {
    static var aThing: String = "FooThing"
}

class Bar: ThingConforming {
    static var aThing: String = "BarThing"
}
...

What I would like to have is an array that holds the class types themselves, so I can iterate over all the classes and check their static variable:

code:
let classes = [Foo, Bar]
for class in classes {
    //check aThing
}

Does let classes = [Foo.self, Bar.self] work?

Doh004 posted:

The more Swift we do, the less and less I'm willing to allow force unwraps to make it through code reviews. Is that completely misguided or is having lots of if lets what we do with Swift?

Use them where crashing is reasonable behaviour. The file manager can't give you back your App Support path? You're hosed, crash it. You're pretty sure this array is nonempty but you can't be arsed to check? Try harder.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Could use a struct.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I suppose. Though a struct also lets you choose not to forward certain operations at your option. Dividing grams by grams may not make sense.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Kallikrates posted:

It's simplistic to say that you should never check if error is set to see if an error occurred.

Good thing that's not the rule! The rule is "check the return value to see if an error occurred". Which is exactly as simple as it should be.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
xctool links against private Xcode frameworks, so I believe you'll want to rebuild/reinstall it whenever you xcode-select to some other version (and whenever you update Xcode). Maybe you can build separate copies as xctool6 and xctool7?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Sooo cool! It's not that I didn't believe it would happen, but you just never know until it does. Congrats!

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Toady posted:

As an opposing view, I'm burned out from the verbosity of Objective-C APIs and find it a real chore at times.

Agreed. I'm happy not to feel the need to add a bunch of newlines in my method calls and line up the precious colons. Most Swift calls fit nicely on one line.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
That's when I add print() everywhere and recompile.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
A struct with var properties is still immutable.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I only noticed today that the Swift Package Manager will generate you an Xcode project (as of a month and a half ago, I'm slow ok). You do that, flip your toolchain in Xcode preferences, and now you've got a real nice autocompleting environment for your Swift development needs.

Definitely curious to see how Xcode 8 interacts with SPM. I'm tentatively excited to never use CocoaPods again.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Doesn't solve that directly (though I'm seeing much snappier autocomplete with the trunk toolset). What it solves for me is good editor support for making things using the Swift Package Manager.

edit: previously it was just editing like a single file in Xcode outside of a project, you don't get any compiler-assisted autocomplete or inline errors.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
The Advanced Swift book from the-decreasingly-well-named objc.io sounds like it might be a good fit. Spends most of its time talking about things Swift does (well) that objc doesn't (do as well). It's up-to-date for Swift 2.2, which is nice because there's a lot of excited material out there talking about code that doesn't compile anymore.

Then it spends the rest of its time talking about things that are trivially not a problem in objc. You can probably skip those parts if you're not interested.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Doctor w-rw-rw- posted:

While that would indeed be glorious, React's popularity makes a syntax for inline component hierarchy definition a prerequisite for that. I think Apple (and others) underestimate the value in doing so.

Maybe I'm misunderstanding what "a syntax for inline component hierarchy definition" is, but why don't Swift enums fit that bill?

Why do you think people are underestimating the value of a syntax for inline component hierarchy definition?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Doctor w-rw-rw- posted:

Am I missing something? Enums can't be subclassed, and enums can't have arrays for default values. Not to mention that components can still be kind of stateful in some corner cases. I can't envision it being cleaner than Objective-C (with the C++ part for cleaner inline syntax).

No, they can't be subclassed, but I figured one could deal with that using protocols. I don't know ComponentKit beyond page one of the tutorial though so I'm probably wrong about its suitability in Swift. And sure, without the syntax dickery possible in newer C++ it probably wouldn't be cleaner in Swift, but I bet you could get close.

quote:

It sounds to me like Apple teams (aside from devtools/compilers) struggle to push software meaningfully forward in a way other than line items in a slide on Apple's next hardware unveiling. Even if an engineer wanted to support a dramatically different but proven model for building UIs, they'd face a lot of institutional pressure against it. Some ex-Apple engineers I've talked to have expressed similar disappointments, though to be fair, them being ex-Apple, the likelihood of that is higher.

For others, I imagine it's lack of experience with the ideas, association with Javascript (though inline XML has been a thing in PHP for longer than it has in JS, and Scala does it too), and overinvestment in the wrong technology (i.e. autolayout).

Neither JS nor PHP have XML literals though? I'm not really sure what your point is here, with that or with the grousing about Apple dev teams' management. What part of ComponentKit, or React, or whatever is fundamentally untenable in Swift today?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

smackfu posted:

It's interesting to see all this heated Swift debate coming up now. Wonder what triggered it?

Seems to go in waves. Often a :airquote: Respected Member of the Community :airquote: will write a variously dismissive thing that sets everyone off.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

HaB posted:

So if I am creating an extension on say - String. What magic must I perform to keep that in its own file?

I'd like to be able to use it on ALL strings in my app, so I don't want it in just one class or whatever.

I don't understand. The usual access modifiers (private, internal, public) should do it for you?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

TheReverend posted:

Am I doing something dumb? Why is String.hash returning Int? Shouldn't it be UInt?

Pretty sure that's because Swift imports NSUInteger as Int.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Start interviewing now, learn up on whatever you encounter.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Guess: trying to run objc in a swift context. Try sticking some -l objc++ after your command (e.g. expr -l objc++).

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
open as the next access modifier after public? Wish I'd thought of that. So simple. So obvious.

Congrats on exiting your own lil personal hell rjmccall :toot:

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I will have to remember that! I have noticed the SourceKit service tends to poo poo a brick when I start typing a lazy property initializer.

I seem to bounce between "hiding all that setup inside the lazy property block is nice and convenient I should do this as much as possible" and "these plain old unadorned properties sure are tidy I should do this as much as possible". That might make it easier.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

eschaton posted:

In case you missed it, Chris is a guest on the Accidental Tech Podcast and he talks about all sorts of stuff.

This is great stuff. If you normally don't care for the hosts, listen anyway, it's like two hours of good questions and thoughtful answers.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
If anything included directly or indirectly in your bridging header pulls in a deprecation attribute you'll see exactly that issue. Any external libraries in our bridging header that in turn include AddressBook?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
It's a textbook example of the bike shed problem.

I hadn't considered the "promotes bad programmer tendencies" aspect before. As someone who dgaf I that argument persuasive.

And yeah, the migrator making everything fileprivate was an unforced error.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Why can't I do this?
Swift code:
protocol P {
    var maybe: Int? { get }
}

class C: P {
    let maybe: Int = 5
}
I get:
code:
error: type 'C' does not conform to protocol 'P'
class C: P {
      ^

note: candidate has non-matching type 'Int'
    let maybe: Int = 5
        ^
which is fair enough, but Swift promotes T to T? seemingly everywhere else. Is this case different enough from the others that it can't/shouldn't be done? Or is it feasible and nobody's gotten around to implementing it yet?

I feel like this must have come up on swift-evolution or in JIRA but I cannot find anything. It is kinda hard to search for because as soon as you put "optional" and "protocol" in a sentence you get optional protocol methods which is a different thing entirely.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Cool, I'll open a ticket.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Everything I can think of is on the roadmap with the possible exception of iOS support, which might not be an explicit goal but certainly seems to be am implicit goal.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Doh004 posted:

Uhh, why?

I just meant I don't remember seeing anyone say "SPM will for sure support iOS and it'll happen on this date". But I do remember seeing more broad "we want to support all platforms where Swift officially runs" statements.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Haven't tried it but
Swift code:

usa.states.flatMap { $0.cities ?? [] }

Adbot
ADBOT LOVES YOU

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

TheReverend posted:

Yeah, all this optional stuff is making it difficult.

This is just an abstraction of a problem I'm facing where the model objects contain obj-c NSArrays.
Would it be advisable then to not use .map and .flatmap functions when the data originates from obj-c and is nullable?

Coming from objc isn’t really the problem if the properties are helpfully modelled and annotated.

It’s quite possible that juggling optional arrays makes flatMap too painful. Partly this is due to both Array.flatMap and Optional.flatMap existing, which can confuse you the programmer and occasionally the compiler too.

There’s no shame in good ol' for loops if that’s the clearest way to model your problem. I like map and flatMap but it’s just one tool of many.

  • Locked thread