FIRAuth.auth() compiling error: "Cannot use optional chaining on non optional value 'FIRAuth'" - swift

Cannot use optional chaining on non optional value 'FIRAuth'
I have tested every solutions, but always got the same error.
Even if i create a new project, when i'm using FIRAuth, i always got a compiling error.
Can someone help me please. I use Swift 2, Xcode 7, IOS9

If you are trying to add FIRAuth.auth()? try to remove (?).
FIRAuth.auth() is non optional so treating them as one might result to the error “Cannot use optional chaining on non optional value 'FIRAuth'”
Optional chaining is a process for querying and calling properties,
methods, and subscripts on an optional that might currently be nil
Check Optional Chaining

Related

How can you get the default error string used when an optional-nil error is thrown?

We're implementing our own version of the .required() method on optionals where instead of simply force-unwrapping throwing an error, you get the file, function and line number of where the offense took place as well as a dev-supplied message of what went wrong.
The message itself is optional, so if the user doesn't specify it, we want ours to share the same message as Swift's default exception for force-unwrapping a nil optional. Their default text is this...
Unexpectedly found nil while unwrapping an Optional value
When not showing our custom message, we of course want ours to show the same text for log analysis. While we can simply hard-code the above string, I was wondering if there's a way to extract it from the built-in error. Something like this...
let ourMsg = UnexpectedNilError.localizedDescription
However, not sure what goes in place of UnexpectedNilError above, or if this is even possible. Not that big a deal. Just wondering if there are standard errors we can tap into here.
After a quick search on Swift's repo, the error message is found in the file Optional.swift line 314:
_preconditionFailure(
"Unexpectedly found nil while unwrapping an Optional value",
file: StaticString(_start: _filenameStart,
utf8CodeUnitCount: _filenameLength,
isASCII: _filenameIsASCII),
line: UInt(_line))
It seems to be quite hardcoded as well, being passed directly as a parameter to _preconditionFailure, so it doesn't seem like you can get it as a string value in your code.

How to check if string is valid by checking if its value is in array

joi.string().valid(['foo', 'bar']) has been deprecated.
Error: Method no longer accepts array arguments: allow
What is the new way of achieving this?
Using spread syntax works perfectly!
joi.string().valid(...['foo', 'bar'])

Swift 1.2: <unknown>:0: error: '[Set<T>]' is not convertible to 'Hashable'

I have used xCode 6.3's convertor to convert my project to swift 1.2,
After that i was still left with many errors, but i fixed them all manually.
Now when i compile i get:
<unknown>:0: error: '[Set<T>]' is not convertible to 'Hashable'.
The only place i use Set is:
var productID:Set<NSObject> = [subscriptionId]
var productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID )
I have tried cleaning the project and also tried deleting the DerivedData folder, but that didn't help.
I have searched but i couldn't find anyone with the same problem.
Anyone know how to solve this?
This won’t be a problem with derived data. It looks like where previously you had an NSArray (probably of NSSet), you now have an Array of Set. Presumably you’re then trying to do something like use that value to key a dictionary type. In 6.3, several API calls that previously returned NSSomething now return native Swift types.
Swift Arrays aren’t hashable (because they might contain something that isn’t hashable). NSArrays are (though not always in a helpful way, depending on what they contain, so be wary).
Bear in mind, with type inference, that your explicit use of Set or Array won’t be the only places you might have a set. If you call a function that returns an array of sets, and you assign that value like so: let thing = funcThatReturnsArrayOfSets() then you will have a [Set<whatever>] even without explicitly writing that type in your code.
To fix this, you need to find the line where you’re getting the error, look at the types involved, then trace back to where those variables were declared. Option-click all the things to see what types they are.

Int extension not applied to raw negative values

My extensions to the Int type do not work for raw, negative values. I can work around it but the failure seems to be a type inference problem. Why is this not working as expected?
I first encountered this within the application development environment but I have recreated a simple form of it here on the Playground. I am using the latest version of Xcode; Version 6.2 (6C107a).
That's because - is interpreted as the minus operator applied to the integer 2, and not as part of the -2 numeric literal.
To prove that, just try this:
-(1.foo())
which generates the same error
Could not find member 'foo'
The message is probably misleading, because the error is about trying to apply the minus operator to the return value of the foo method.
I don't know if that is an intentional behavior or not, but it's how it works :)
This is likely a compiler bug (report on radar if you like). Use brackets:
println((-2).foo())

What the difference between using or not using "!" in Swift?

The ! mark is used for the optional value in Swift to extract the wrapped value of it, but the value can be extracted without the !:
var optionalString: String? = "optionalString"
println(optionalString)
another example using the !:
var optionalString: String? = "optionalString"
println(optionalString!)
both the codes above get the right value, so I wonder what's the difference between using and not using !, is it just for detect an error at runtime if the optional value is nil or something else? Thanks in advance.
As others have already stated, a really good place to start would be with the official documentation. This topic is extraordinarily well covered by the documentation.
From the official documentation:
Trying to use ! to access a non-existent optional value triggers a
runtime error. Always make sure that an optional contains a non-nil
value before using ! to force-unwrap its value.
println() is probably not the best way to test how the ! operator works. Without it, println() will either print the value or nil, with it it will either print the value or crash.
The main difference is when we're trying to assign our optional to another value or use it in an argument to a function.
Assume optionalValue is an optional integer.
let actualValue = optionalValue
Using this assignment, actualValue is now simply another optional integer. We haven't unwrapped the value at all. We have an optional rather than an integer.
Meanwhile,
let actualValue = optionalValue!
Now we're forcing the unwrap. Actual value will be an integer rather than an optional integer. However, this code will cause a runtime exception is optionalValue is nil.
Your question is answered in the book "The Swift Programming Language: iBooks
Download it and search it for "!".
You could've easily found the answer without having to ask here. For future reference, please always remember to look in the manual first.
From "The Swift Programming Language":
You can use an "if" statement to find out whether an optional contains a value. If an optional does have a value, it evaluates to "true"; if it has no value at all, it evaluates to "false".
Once you're sure that the optional does contain a value, you can access its underlying value by adding an exclamation mark (!) to the end of the optional's name. The exclamation mark effectively says, "I know that this optional definitely has a value; please use it." This is known as forced unwrapping of the optional's value.
I've never heard of Swift before now, but reading the documentation seems clear
"Using the ! operator to unwrap an optional that has a value of nil results in a runtime error."
If in your application nil is a valid and expected value in any normal circumstance and/or you want to trap and handle it in your code then I suggest that you don't use it. If you never expect it to be nil then use it as a debug aid. Runtime error suggest to me that your program will be terminated with a message reported by the OS.