Declaration is only valid at file scope (extension)

The error message is quite clear. You cannot declare an extension inside of anything – inside a class declaration, inside a struct declaration, etc. It must be outside of everything, at the top level of the containing file. There must be no curly braces around it. You have not shown the context in which you are declaring this extension, but clearly there are curly … Read more

How does String substring work in Swift

All of the following examples use Swift 4 Strings got a pretty big overhaul in Swift 4. When you get some substring from a String now, you get a Substring type back rather than a String. Why is this? Strings are value types in Swift. That means if you use one String to make a new one, then … Read more

What does “Fatal error: Unexpectedly found nil while unwrapping an Optional value” mean?

Background: What’s an Optional? In Swift, Optional<Wrapped> is an option type: it can contain any value from the original (“Wrapped”) type, or no value at all (the special value nil). An optional value must be unwrapped before it can be used. Optional is a generic type, which means that Optional<Int> and Optional<String> are distinct types — the type inside <> is called the Wrapped type. Under the hood, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)