Nick Walter Swift 5 Course - Part 4 (lectures 25 to 26)
Cool! Now I have some closure (pun unintended!) on Nick's last, very complex, challenge, I am moving on with 'what's new in Swift 5'...
Start Time - 13:15
This will be very recent information.
ABI Stability
ABI is how Swift interacts with the computer. What are the benefits here?
Every Swift app (whatever the device is) it comes with a run time with whatever Swift version you have
Now, with S5 and ABI stability, any device will already have Swift there so this will shrink app sizes. Frameworks in Swift also shrink in size, app load times reducing...cool! As you'll have different versions of Swift on different apps etc. it will now speed things up.
Stability part - From Swift 1 to 2 there were MASSIVE changes. Each new Swift has resulted in small changes. This is good news as it means you don't have to RELEARN the language! Cool!
This is also great as you can go ahead with using what you know with Swift 5, knowing it's not going to change so much.
So to be honest, not much else on this one other than Nick demonstrating file sizes not being so big. OK got it!
Coding Challenges!
Yes! Here we go - the actual code! I think this is going to be some examples of the new code then some challenges...
Raw Strings
These can take in more objects inside the string including slashes.
OK new thing - with the raw strings you put hashtags at the start and end of the string and then EVERYTHING including e.g. slashes for quotes will be shown.
So putting in quotes within the string can now be done with speech marks, using the hashtag of course.
IF you were using the hashtag within the string, then you would need to put in an extra one to stop crashing the code. OK!
String Interpolation
All of this is following along with Nick. Basically, you have the option now to extend the string interpolation so that includes a custom type's properties. Yes that is me putting this into my own words! Cool!
You can pass multiple things into the parameter...lots of options!
Back to raw strings...you can do string interpolation with it but it will take exactly the input so will include the slash and brackets! You can get around that by putting in extra hash tag...

Result Type
This is to do with error types.
So you can include a string with an explanation to show why the error is there.

Start Time - 13:15
This will be very recent information.
ABI Stability
ABI is how Swift interacts with the computer. What are the benefits here?
Every Swift app (whatever the device is) it comes with a run time with whatever Swift version you have
Now, with S5 and ABI stability, any device will already have Swift there so this will shrink app sizes. Frameworks in Swift also shrink in size, app load times reducing...cool! As you'll have different versions of Swift on different apps etc. it will now speed things up.
Stability part - From Swift 1 to 2 there were MASSIVE changes. Each new Swift has resulted in small changes. This is good news as it means you don't have to RELEARN the language! Cool!
This is also great as you can go ahead with using what you know with Swift 5, knowing it's not going to change so much.
So to be honest, not much else on this one other than Nick demonstrating file sizes not being so big. OK got it!
Coding Challenges!
Yes! Here we go - the actual code! I think this is going to be some examples of the new code then some challenges...
Raw Strings
These can take in more objects inside the string including slashes.
OK new thing - with the raw strings you put hashtags at the start and end of the string and then EVERYTHING including e.g. slashes for quotes will be shown.
So putting in quotes within the string can now be done with speech marks, using the hashtag of course.
IF you were using the hashtag within the string, then you would need to put in an extra one to stop crashing the code. OK!
String Interpolation
class Dog {
var age = 0
var name = ""
}
extension String.StringInterpolation {
mutating func appendInterpolation(_ dog: Dog) {
appendInterpolation("\(dog.name) - \(dog.age) years old")
}
}
var myDog = Dog()
myDog.age = 7
myDog.name = "George"
print("First place is \(myDog)")
All of this is following along with Nick. Basically, you have the option now to extend the string interpolation so that includes a custom type's properties. Yes that is me putting this into my own words! Cool!
You can pass multiple things into the parameter...lots of options!
Back to raw strings...you can do string interpolation with it but it will take exactly the input so will include the slash and brackets! You can get around that by putting in extra hash tag...

Result Type
This is to do with error types.
So you can include a string with an explanation to show why the error is there.

enum APIError: Error {
case badURL
case rateLimitHit
case other(reason: String)
}
func hitUpAPI() -> Result<String, Error> {
return .success("It works!")
}
This is cool! So an enum was created to show a custom error type. Then a function created with specifically result mentioned and String, Error as the two type to see if it were a success of failure.
return .failure(APIError.badURL)
You can only have one return type - by putting in String, Error, Xcode knows that the success must be string and failure the error. That makes sense.
Set and Dictionary Order
I'm not too sure what point Nick is making here. Something to do with some Sets having random order when printed.
Compact Map Values
let dogsYoungerThanTen = allDogs.mapValues { (age) -> Int? in
if age < 10 {
return age
}
return nil
}
So this would be using the map function on sets with a closure - see above. What's the new way...
let dogsYoungerThanTen = allDogs.mapValues { $0 < 10 ? $0 : nil }
Wow that's much better!
*Correction, this was based on a dictionary not a set!
let allDogs = ["Fido":8,"Sarah":13,"Judlah":6]
Enum fix
This is what you used to do for variadic (could go on forever values) -
enum Food {
case friedRice
case milkshake
case pizza(toppings: [String]...)
}
Food.pizza(toppings: "Pepperoni","Cheese","Olives")
Now you have an array for these...
enum Food {
case friedRice
case milkshake
case pizza(toppings: [String])
}
Food.pizza(toppings: ["Pepperoni","Cheese","Olives"])
Future Enums
let lunch = Food.friedRice
switch lunch {
case .friedRice:
print("Cool lunch fam")
case .milkshake:
print("Is this really a meal?")
case .pizza(let toppings):
print("Your toppings: \(toppings)")
}
So this is exhaustive. But if you had another item which wasn't then accounted for in the switch statement, you could use the @unknown keyword before default, then a yellow warning would come up - code would still execute but you'd have to manually find what the case is that hasn't been accounted for.
Optionals Simplified
OK....
Is Multiple Of
A new way of finding is it a multiple of! So no need to create a function or the % operator. Modulo!
345.isMultiple(of: 5)
Finish Time - 14:13
So a near hour exploring these features. And great! All made perfect sense! A couple more lectures I'll do next time before the iPhone app!
Comments
Post a Comment