How to implement firebaseUI in IOS - ios

I new to IOS Development.I am basically android developer
I want to implement firebaseUI for login using mobile number and email
I got doc here https://firebase.google.com/docs/auth/ios/firebaseui?authuser=0. But i am getting compiletime error..below I mention
My AppDelegate file
my ViewController class
if I comment this line authUI.delegate = self above line getting wrong below I add image...

authUI is a Swift optional, which means it can be nil (null). In order to use optionals, you must unwrap them with the '?' sign. So your code can be simply fixed with:
authUI?.delegate = self
If authUI is nil, the code will do nothing, whereas in Java it would cause a null pointer exception. You may unwrap it with '!' instead, which will cause a runtime error if authUI is nil.
Tip: you can click on the red error or yellow warning icons to see and apply suggested fixes, much like Alt-Enter on Android Studio. Do not rely too much on those, sometimes the automatic fixes become a mess. :)

Related

defaultCalendarForNewEvents is defined as optional however can't use optional binding to check if it's nil

I'm adding new functionality in my app, which is the ability to add an event in the default calendar set up on the phone. I get the permission and am ready to add the event. I check to see if there is an actual default calendar, but I get the error:
Initializer for conditional binding must have Optional type, not
'EKCalendar'
Now, defaultCalendarForNewEvents is an Optional (see definition below) and it should be perfectly fine to use optional binding to check if it's nil or not. What am I missing?
defaultCalendarForNewEvents definition in EKEventStore.h:
open var defaultCalendarForNewEvents: EKCalendar? { get }
I'm using Swift 3 on iOS11.2.(Edited to correct the Swift version I'm using.)
Here's the code:
if let defaultCalendar = eventStore.defaultCalendarForNewEvents { <-- error line
newEvent.title = "Some Event Name"
newEvent.startDate = Date()
newEvent.endDate = Date()
}
I asked this question at the Swift discussion forum at swift.org and got a response. So as per the response, 'defaultCalendarForNewEvents' was marked non-optional in Swift 3 by accident and that was fixed in Swift 4. That's why there was a discrepancy: documentation showing declaration in Swift 4 but optional binding failing as I'm on Swift 3. Hope this helps someone who is having the same issue.
I was also told that this issue was not release-noted as it was a minor update.
The error is telling you that the defaultCalendarForNewEvents is not, in fact, an Optional. Perhaps there is some nil-coalescing or something else happening that is not visible to you. Regardless, if the compiler is telling you it's not optional there's no need to fight for optional binding.

ibeacon app development using swift

everyone, I am a new one to iOS app development using swift.
I am studying a ibeacon app sample code which downloaded from the https://github.com/SelimSalihovic/CityOS-iBeacon-Swift-Tutorial.
while I was running the code, there are errors in the code as shown the following page, could you help me how to solve it, please! Thanks in advance!
The first one is easily solveable by unwrapping the value (the exclamation mark)
NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D")!
Second and third error are due to the beacons array not declaring the content's type (AnyObject means it can't be any class, which is not guaranteed to have the properties the code is looking for) so just go to line 16 and make the following change
var beacons : [CLBeacon] = []
However this will still not compile because the LocationServices framework hasn't been imported in the project, to do so just add
import CoreLocation
There will be some more errors now, specifically at line 26 and 55 in BeaconTableViewController
Fix-It has the right suggestion for these, basically you need to cast note.object by adding as! [CLBeacon] and remove the unwrapping on switch proximity because the value isn't optional
The code now compiles properly for me, I'm not sure it will work because I can't test right now, but it should be a step in the right direction
Good luck with your journey in iBeacons, they're a pretty fun technology to work with

why xcode's suggested error fix (goes back and forth with no end) in these statements?

I have this line, written with Swift 1.2 using XCode 6
self.mainMenuButton.titleLabel?.font = UIFont(name: Box.fontName, size: mainMenuButton.titleLabel?.font.pointSize!)
it shows this error
operand of postfix "!" should have an optional type
it basically suggests that I change it to this
self.mainMenuButton.titleLabel?.font = UIFont(name: Box.fontName, size: mainMenuButton.titleLabel?.font.pointSize)
and when done it requires that i put the ! back like in the first line, so it loops in the suggestions without ending...
why does this happen and how to solve it?
Ahh, I have encountered this problem multiple times! Really confusing. The problems lies in the UIFont init statement:
UIFont(name: ..., size: mainMenuButton.titleLabel?.font.pointSize!)
The problem is that the UIFont initializer requires a non-optional size argument. But in your code, mainMenuButton.titleLabel?, the ? says that mainMenuButton.titleLabel?.font.pointSize! can return an optional, regardless of whether you put a ! at the end.
Solution
The solution is to change the ? behind titleLabel to a !.
Explanation for error fix going back and forth
Xcode is not smart enough to know that the ? is the root cause of the problem, it just thinks that since the expression ultimately returns pointSize, you should add a ! to ensure that pointSize is not nil. But, as shown in the documentation, pointSize is not an optional! So there's no need to unwrap it using !. That's why Xcode suggests to remove the !. But removing it causes the expression to be return an optional! And the size argument only allows non-optionals! So the Fix-It cycles back and forth...
Edit
Also, I tested it and this error going back and forth problem is fixed in Xcode 7. Compared to Xcode 7, Xcode 6 is already obsolete.
As blip explained, watch out for "?"
These typically pop up when you need to use a "!" or "?" and Xcode typically falls back to "?".
If you are trying to display something on the user's screw and it shows as optional("blah blah"), look for any "?" leading up to the code that prints the line and force unwrap it "!"

Stanford calculator app crashes with error "unexpectedly found nil"

I'm new to programming and I've started taking the stanford course on iTunes U for making an iPhone 8 app. They're using Xcode 6 and Swift 1 while I'm in El Capitan using Xcode 7 and Swift 2. I've found a few differences in code that Xcode has been able to pick up on and help me correct ("println" is now "print" for example), but I'm getting tripped up on one particular part of the code:
var displayValue: Double {
get {
return NSNumberFormatter().numberFromString(display.text!)!.doubleValue
}
set {
display.text = "\(newValue)"
userIsInTheMiddleOfTypingANumber = false
}
}
I've double checked several times to make sure this is exactly how the teacher wrote it. His built correctly and functioned correctly, while mine builds correctly, but shows this fatal error when I try to operate it, "unexpectedly found nil while unwrapping an Optional value" (see screenshot for all the details).
Screenshot of the error
I've been looking around the internet and found a few similar examples, including one on this site (Stanford Calculator app keeps crashing), but after trying everything that was suggested I concluded that something must be unique in my system or I'm operating in a new Xcode/Swift environment than the others that had this problem. None of the solutions have resolved the problem, and all of them added errors of their own.
In responding to someone else's question someone suggested that we use this code to ensure that if "nil" is returned by "display" that it will provide "0" instead:
return (NSNumberFormatter().numberFromString(display.text) as? Double) ?? 0
I tried this, but it only gave me more errors, some seem to be related to Swift 2 (it required a comma after double, wanted me to unwrap display.text, and complained that there was an expected expression missing—maybe the suggested code was good in Swift 1??).
I've double checked several times to make sure this is exactly how the teacher wrote it. His built correctly and functioned correctly, while mine builds correctly, but shows this fatal error when I try to operate it, "unexpectedly found nil while unwrapping an Optional value"
I suspect that display is an IBOutlet property that needs to be connected to something in the user interface, probably a text field. If it's not connected, then even though your code is exactly the same, you'll get nil when you try to use its text property, and unwrapping that will cause the error you're seeing.
Whether or not the advice above actually solves your problem, what you really need to do is to set a breakpoint a line or two before the spot where the crash occurs and step through the code. Look at the variables involved and figure out where that nil value is coming from. You can work backward from there and figure out why the thing that you expect not to be nil is, in fact, nil. Learning to work that way will help you work out these kinds of problems when they occur (and they will occur again).
Not sure if you've found the answer or not by now, but I ran into a similar problem this morning and thought I'd share what I found.
While debugging, I entered two console logs to a simplified version of my operate like so:
case "x": if operandStack.count >= 2 {
print(" display before popping is: \(display.text!) ")
displayValue = operandStack.removeLast() * operandStack.removeLast()
print(" display after popping is: \(display.text!) ")
enter()
}
Display after popping came up as "newValue". I couldn't figure out what that meant at first, but realized that my issue is the setter. newValue is an optional that should be unwrapped i.e. "(newValue)!"
P.S. I opted to return:
return (display.text! as NSString).doubleValue
in my get.
Also, since newValue is unwrapped, keep in mind it will crash if display is set to nil.

EXC_BAD_ACCESS when updating Swift dictionary after using it for evaluate NSExpression

I'm using a dictionary to evaluate an expression, when the expression has variables and the dictionary is actually used by NSExpression, something happens and I get EXC_BAD_ACCESS when trying to update the dictionary, this only happens when debugging in an iPhone6, not in the simulator and not in an iPhone 4S.
let strExpression = "a+b+20"
let exp = NSExpression(format:strExpression)
self.dictionary = ["a":10.0, "b":15.0, "c":25.0]
let value:AnyObject = exp.expressionValueWithObject(self.dictionary, context: nil)
let doubleValue = value as Double
self.dictionary.updateValue(doubleValue, forKey: "c")
Something really weird is that if i add this line just after creating the dictionary, then it woks fine:
let newDic = self.dictionary
I,m using iOS 8.1. Thanks in advance!
With #bensarz comment, I thought it might be helpful for others searching for answers if I put the response into an actual answer instead of a comment.
Per #LeeWhitney's response on a similar post:
Looks like a compiler bug.
Have you tried switching between Release and Debug then rebuilding? If debug works but not release it can be an indication of a compiler/optimizer bug.
Does it happen in the simulator also?
Your code works for me on iOS 8.1 with XCode 6.1.
Solution:
The issue seems to be solved by changing the 'Optimization Level' under the 'Swift Compiler - Code Generation' to 'None'. The issue seems to be with the 'Fastest' Compiler optimization level.
Also, a work around that I've found original before the compiler change:
If you use a let statement prior to assigning values in the dictionary, it seems to alleviate the issue. More information found at link below:
EXC_BAD_ACCESS on iOS 8.1 with Dictionary

Resources