Stanford Calculator app keeps crashing
I am stuck at that part of the course too!
I think that apple recently made changes to NSNumberFormatter's numberFromString method. Because when I printed out display.text!, there was nothing wrong. In other words, it does not found nil while unwrapping that part.
Another part we are unwrapping is here, at the second ! mark, we unwrap only this part:
NSNumberFormatter().numberFromString(display.text!)
But we have an error out of this, so numberFromString should be returning nil.
But in the videos, it doesn't. It perfectly turns floating point number strings (such as "36.0") to NSNumber, then to Double.
And since your question was asked on May 20th and I could not find any "old" questions, I think Apple had changed the code on numberFromString.
Edit: I did something crazy and used Find & Replace (command + F) to replace all "Double"s to "Int"s in my code. The multiplication part works well now, I think the problem is about the "." part on Doubles.
Edit 2: I solved it. Some countries such as US use "." to separate decimals and some others such as Turkey use "," to do it. It works on video because he's doing it on US.
NSNumberFormatter has a property called decimalSeparator. We have to set it to ".". I did the following changed to my code and it worked perfect.
var displayValue: Double {
get {
var formatter = NSNumberFormatter()
formatter.decimalSeparator = "."
return (formatter.numberFromString(display.text!)!.doubleValue)
}
set {
display.text = "\(newValue)"
userIsInTheMiddleOfTypingNumber = false
}
}
IOS Dev Stanford Homework #1 Calculator, can't start
Usually that error means you defined an IBOutlet, then hooked it up in IB, and then deleted that ivar. Check that all the IBOutlets are synthesized and defined in the class.
Make NSNumberformatter().numberFromString return an optional
No need to make it return an optional. You can use the nil coalescing operator to return 0 in case of nil as follow:
return (NSNumberFormatter().numberFromString(display.text) as? Double) ?? 0
iOS 8 Swift CS193P Calculator Bug Switch Operation
Your code looks fine, it looks like you accidentally placed a breakpoint in your code, see that blue-looking arrow to the left of the green-highlighted line?
Do one of the following:
- Go ahead and right click that and click Delete Breakpoint
- Drag and drop that breakpoint into your view controller
When you do one of the following listed, your program will run smoothly
Don't worry, you'll start to catch onto these simple fixes and you will be able to get to more coding.
Check this out for more information about Adding, Disabling, and Deleting Breakpoints.
Stanford CS193p Assignment 2 - Entering variables into RPN calculator
In this assignment, you can just run the variable-include program by using Test Buttons(Task 3). Maybe the follow assignment will require implementing the "set" and "run" function.
iOS - app crashes on provisioned iPad, works ok in simulator
To get a better idea of the error and it's root cause add an exception breakpoint to get the line of code causing the error. Select the breakpoints and in the bottom left of the Xcode window select the "+" and click on "Add Exception Breakpoint". Click through the following alerts. This works best with Xcode 4.5.1.
Related Topics
Updated Approach to Reauthenticate a User
Custom Cell with Uitableview Inside Uicollectionviewcell
How Does One Use Nsdateformatter's Islenient Option
"Ambiguous Use of 'Children'" When Trying to Use Nstreecontroller.Arrangedobjects in Swift 3.0
Accessing Actor Properties Synchronously from Task-Less Context
Tableview Accessories Don't Load Correctly
Parse.Com Pfquery Order by Time (Swift)
Error While Using Property 'Cgrectgetwidth', It Says It Was Replaced with 'Cgrect.Width'
How to Call Swiftui Navigationlink Conditionally
Swift 2: Multiline Mkpointannotation
Ios13 Uialertcontroller with Custom View & Preferredstyle as Actionsheet Grayscale All Colors
Swift Deleting Table View Cell When Timer Expires
Why Does the Compiler Not See the Default Code in a Protocol
Use Huge Numbers in Apple Swift