Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
What's New in Swift 4 (realm.io)
71 points by astigsen on Sept 28, 2017 | hide | past | favorite | 33 comments


Swift has evolved quickly, and it has finally been large adopted by the iOS community:

https://www.tiobe.com/tiobe-index/

What’s missing is non-Apple adoption. I’m hoping Swift becomes an acceptable/competive option on other platforms.


How easy is it to build a Swift app that uses the same codebase for Mac, Windows, and Android?

What are the target environments like in non-Apple systems?


Its not terribly difficult to use swift on linux, theres a a working group trying make it easier for developers to use swift on the server [0]

[0] https://github.com/swift-server/work-group


Yes, but the main question is: what for? You can't use it even to do what it's been created for: writing iOS apps (maybe some backend modules if you're obstinate enough). There is a great choice of languages in Linux with rich libraries and vibrant communities - why on Earth should I choose Swift?


I'm an iOS developer and I use it for writing iOS apps, testing, and managing my test environments. I have the luxury of assuming a macOS host though.

I think the reason you'd pick it for a server language is because the strengths of the language and ecosystem meet your server requirements.


I agree that it currently isn’t the most productive choice for most, but Swift wasn’t created just for writing iOS apps (at the least, it targeted desktops, too, from the start), and certainly aims much wider today. https://swift.org/about/:

”The goal of the Swift project is to create the best available language for uses ranging from systems programming, to mobile and desktop apps, scaling up to cloud services”

And if “doesn’t have rich libraries and vibrant communities” were a decisive argument to not start using a new language, there never would be a new language again. I can see that, for some, using Swift on the server could be the right choice (for example because it makes it easier to share code between server and iOS apps)


Some developers use Rust for Linux libraries, I use Swift for web server on Linux. The only concern I have is working with Linux libraries can be fairly difficult as you get in Rust.


Same reason a JavaScript developer uses Node.


Something you'd have to consider is that Android has a screen/app lifecycle that Apple products don't. If you're working with ionic, you have to care about this. What ever swift library you use, it has to make these lifecycle concepts available to you.


are you referring to the lifecycle events like onResume and onPause? You can approximate those with iOS using a combination of viewWillAppear and UIApplicationWillEnterForegroundNotification


I am referring to those. If someone just tries to make Swift the platform, I think they will have to put as much thought into their tooling as xamarin, cordova, etc.


Windows isn't supported at all


I really tried couple of times to use swift in production. One of my MAS apps is pure swift. However I can't force myself to like it. Maybe I am missing some brilliant part of it that I missed but I just can't love it.


I write Swift code every day, and I can't count the number of times thats its type system has saved me, at compile time, from errors that would have otherwise shown up in QA or quite possibly production. In general, Swift makes iOS apps perform more reliably than Objective-C.


There is a quote by Jim Jannard of Red in the documentary Side by Side: "digital wasn't paying enough respect to film". That is the feeling I get when programming Swift. I really wanted an improved Objective-C or at least something that was kept some of the same conventions (selector syntax). F-Script was interesting example of a language, but didn't really have the depth. I just cannot shake the feeling that the creators of Swift looked down on Objective-C like some of the Apple folks in 98ish when they tried to foist Java on us. Its hard to use a language when your pretty sure the the designers hated one of your favorite things.

I'm programming in it daily and its uglier and has more syntax then it should. Its very much like my experience with Transact-SQL, I'll use it and gain as much proficiency as possible, but I really don't like programming in it.


What do you love? I can't love Go as a language, but love the projects, standard library, community, and have no replacement yet for the space where Go is.


I went trough C and Pascal some 30 years ago and still prefer C above anything else. Objective C obviously being close enough so I can write efficient (or at least visually pleasing code). Last straw with Swift for me was banishing of ++ operator. C has beauty and smartness to write _a lot_ of code in one line. I don't like C++ that much.

Anything that makes code beautiful works for me. Swift somehow can't be per_line_efficient and aesthetically pleasing to me.


Sounds like you like what you’re used to. What do you mean by per line efficient? C and Objective C are more verbose. Declaring non-null, implicit types, and immutable in Swift is a big plus.

let x = “Hello world”

var isDone = false

Filtering an array in one line is much nicer than a for loop:

let newList = anArray.filter(...)

No header files reduces code significantly.


For instance tight while loop with ++ increments where needed. You can't do that in Swift. Or one liner if in the middle of other code.

I am using a lot of different languages so 'what I am used to' means lots of different stuff. Ruby has some of C beauty. Python does not. Haskell is probably most beautiful of them all. All individual and from my point of view of course.


Perhaps you can be less abstract and illustrate your point with sample code. In most comparisons, Swift looks a lot nicer.

https://h4labs.wordpress.com/2016/02/09/should-i-use-objecti...

The ++ operator was removed from Swift. Haskell uses ++ for concatenation. The case where ++ to add 1 is desirable occurs much less often than a variable declaration, which is better in Swift.


For instance C copy routine:

  while (*d++ = *s++);
Or sort in Haskell:

  qsort []     = []
  qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)


Haskell is beautiful, but it's worth mentioning out that Haskell's quicksort is not written that way, because in this case beautiful means incredibly slow (and also because that's not even quicksort, which is an algorithm defined by how it modifies data in-place). The real quicksort implementation uses mutable arrays to perform an in-place sort, and isn't beautiful at all.


C-style strcpy in Swift is a little verbose:

  func strcpySwift(_ d:UnsafeMutablePointer<CChar>,
                   _ s:UnsafeMutablePointer<CChar>) {
    for i in 0... {
      d[i] = s[i]
      if s[i] == 0 {
        return
      }
    }
  }

Haskell-style sort in Swift is pretty nice:

  func qsort<T:Comparable>(_ arr:[T]) -> [T] {
    var xs = arr[...]
    guard let x = xs.popFirst() else {
      return []
    }
    return (qsort(xs.filter{$0 <= x})) + [x] +
           (qsort(xs.filter{$0 > x}))
  }


What’s the value of the Haskell code? It’s a great language but not really supported on iOS. Would love for it to be.

Back to the one idiomatic C example. The few places where it’s terse does not make up for the many other places where it’s not. You also have memory management with malloc for additional code. If you compare nontrivial code, Swift is a more modern, safer, less verbose, etc way to develop iOS apps vs Objective C.


Swift wants to be much more than just iOS specific language so it is fair to compare its pros and cons with other general purpose languages. If you look at iOS only then there is not much to compare to, just ObjC and few JS abominations. Staying iOS specific is not what Swift wants to be.


Yeah, some are very superficial still they bother me every time. A map in lisp/python/js vs a for-loop in Go/C, for simple transformations.


You can do a filter method in Obj-C with blocks, or even plain C with function pointers.


Something like this?

https://stackoverflow.com/questions/9558335/filter-an-nsarra...

Food food1 = [Food alloc]initWithName:@"samsar" andId:@"1"];

Food food2 = [Food alloc] initWithName:@"rusaramar" andId:@"2"];

NSSarray array = [NSArray arrayWithObjects:food1, food2, nil];

[array filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary bindings) {

    return [evaluatedObject.foodName hasPrefix:searchBar.text];
}];


I haven't used it since the early days, and at the time it seemed obtuse and was also missing a lot of really basic features. I might pick it up again and see how it has changed.


> Swift 4 is the release that says, “We need to stabilize the source code.”

Stabilizing source code doesn't have any meaning that I know of. But the updates to the language and library are good!

Looking forward to what they come up with regarding ownership semantics.


Stabilizing source code doesn't have any meaning that I know of.

Programs written in Swift 4 will compile under the Swift 5 compiler, etc.


Oh, source code compatibility for real? That's super nice!


since they're keen on intervals I wonder if they'll provide interval algebra

    if a..b ∩ ..<c:




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: