![]() The values in a Swift tuple can be of any type and don't have to be the same type as each other. A tuple lets you group multiple elements into a single compound variable. Strings can also be used in switch statements.ĩ. Most notably, you can concatenate strings easily using "+=" and compare strings using "=" instead of the more cumbersome "isEqualToString:". ![]() Swift handles strings more easily. If string handling drives you mad in Objective-C, then you'll love Swift, as the way you deal with strings in the new language is much simpler. ![]() ![]() In some cases, the contents might be integers in other cases, floating point numbers.Ĩ. For example, a function that adds up the contents of an array. Much like Templates in C++, Generics are functions that can be reused with different variable types without being rewritten for each type. That's fine until you have a function that you want to work in different circumstances with different types.Įnter Generics. Swift introduces Generics. In static typing, when you write a function, you have to declare the types of the function's parameters. Plus, thanks to smart optimizations, your code should run faster.ħ. Coders don't need to spend time annotating variables with type information and risk making mistakes in most cases, the compiler can infer the type from the value that a variable is being set with.Īs a result, you can expect to find fewer type-related bugs hiding in your code. Swift offers type inference. Like Scala, Opa and other programming languages on the rise, Swift carries out type inference. Other Playground features include the capability to "watch" the value of a variable, typing its name on a separate line in the code and seeing its current value displayed in a side bar, as well as a set of "Quick Look" buttons that display images, strings and other content intended for graphical display.Ħ. This tool lets you see the effects of changes or additions to code as you type, without going through the time-consuming rigmarole of running the code through the compiler and executing it. You can experiment with Swift code in "Playgrounds."One of Swift's most interesting features is an interactive environment called a Playground. And don't forget: Apple's app stores won't accept apps built with Swift until it first releases Yosemite and iOS 8.ĥ. While it may well be worth coding in Swift to familiarize yourself with the language, to do so you'll need to use Xcode 6 beta and the iOS 8 SDK (also in beta). Apple is still working on it, and it's highly likely that new features will be added over the coming months. Swift is incomplete. The language that's available today isn't the finished product. There will inevitably be performance differences, as the two languages aren't identical after all, but don't expect significant differences.Ĥ. Although the two languages are different, they're not that different both target the same Cocoa and Cocoa Touch APIs (for OS X and iOS, respectively), both are statically typed languages and both use the same LLVM compiler as well. Swift isn't that fast. Despite the name, Swift is unlikely to result in applications that run much faster than applications written in Objective-C. This guarantees that something will run at the end of the statement even if none of the possibilities in the statement are satisfied.ģ. In addition, switch statements must include a default statement. For starters, programmers must include brace brackets to open and close "If" statements, which prevents bugs such as the SSL "goto fail" error. Swift should be a safe(r) language. Apple has made an effort to make Swift safe in a variety of subtle ways. That may make Swift attractive if you've already built a considerable skill base in Objective-C, too.Ģ. There's no problem with writing new modules in Swift that interoperate with existing Objective-C code bases. That said, Swift is compatible with existing Objective-C libraries.
0 Comments
Leave a Reply. |