Questions tagged [optional-values]
79 questions
0
votes
2 answers
Found nil while unwrapping optional value
You might think: "another post about this error".
Yes, i've been looking into this forum before writing this question and unfortunately i couldn't find something that could help, or atleast i know that this error gets on when there is a var that is…

Yxss
- 1
0
votes
0 answers
XMLPATH: Search for an OPTIONAL information in a flat structure
I got the following XML
whose…

Christian Meichsner
- 171
- 1
- 3
- 4
0
votes
2 answers
can't remove optional() from string after updating to latest xcode?
after updating xcode I simply can't remove the optional() from my string?
retrievedUsername = KeychainWrapper.stringForKey("username")!
this prints out
optional("HK")
but I need it to be
HK
I've tried
if let username =…

MrKale
- 43
- 1
- 11
0
votes
2 answers
unexpectedly found nil while unwrapping an Optional value for my UITextField
I'm having trouble passing the JSON values (I'm reading successfully) into my textfield on the next viewcontroller because of this unwrapping error, stating my text field is nil.
I'm very stuck. Here's my class that reads the JSON:
class…

Drew McCalla
- 1
- 2
0
votes
1 answer
Found nil while unwrapping an Optional value, Error
I don't know where that optional is. please help! I really need this, I haven't used optional values in my code.
import UIKit
class ViewController: UIViewController {
//this is the outlet for the sliders RGB values
@IBOutlet weak var…

Pixele9
- 422
- 8
- 25
0
votes
1 answer
Swift - Compiler warns i haven't unwrapped an optional but then forces me to unwrap using ! rather than?
I've got an error in my code where the compiler gives a warning to unwrap an optional with the message
Value of optional type 'NSDate?' not unwrapped; did you mean to use '!' or '?'?
My code is
let formatter = NSDateFormatter()
let dob =…

lozflan
- 835
- 10
- 23
0
votes
2 answers
Swift: Checking for the existence of a uitextfield
I have a controller that will have a variable number of textfields. On a button press I want to check for the existence of, whether or not its empty, and check the character count of the input.
I'm trying the following, which works fine if homePhone…

Sam Luther
- 1,170
- 3
- 18
- 38
0
votes
1 answer
Can't find fatal error: unexpectedly found nil while unwrapping an Optional value
It was working last night, but when I run my code, now I am receiving a:
fatal error: unexpectedly found nil while unwrapping an Optional value.
Can someone help me locate this error?
import UIKit
class UserRegistration: UIViewController,…

Michael Westbrooks II
- 145
- 1
- 2
- 10
0
votes
1 answer
How do I convert a contained forced value to a contained optional value?
Converting an optional value to a forced value works fairly simply:
var aString: String? = "Hello"
var anotherString: String = aString!
And it's even more simple in the opposite direction, because there's no unwrapping:
var myString:…

Andrew
- 7,693
- 11
- 43
- 81
0
votes
3 answers
Error while unwrapping an Optional value after testing it in Swift
I have a strange error this morning running my code.
fatal error: unexpectedly found nil while unwrapping an Optional value
Here is my simple object:
class FQ {
var rating: Float?
var phone: String?
init(rating: Float?, phone:…

maxwell2022
- 2,818
- 5
- 41
- 60
0
votes
2 answers
Swift Optional values out of an NSSet
Self.vertices is an NSSet. I'm having trouble getting the Vertex value out of the optional
The code below crashes in playgrounds.
func getVertex (x: Double, y: Double,z: Double) -> Vertex?
{
for v : Vertex! in self.vertices {
if…

Justin Milo
- 575
- 4
- 15
0
votes
2 answers
Using ? (optionals) in Swift variables
What exactly is the difference between a property definition in Swift of:
var window: UIWindow?
vs
var window: UIWindow
I've read it's basically an "optional" but I don't understand what it's for.
This is creating a class property called window…

Woodstock
- 22,184
- 15
- 80
- 118
0
votes
1 answer
mysql REPLACE INTO and optional values IFNULL
I'm trying to do something like this inside of a stored procedure:
REPLACE INTO mytable
SET myid = `IDvalue`, mytitle = `sMyTitle`, myoptionalvalue = IFNULL(`sMyOptValue`, myoptionalvalue);
But not seems to work, any idea how to do this?
Thanks!

Santiago
- 2,190
- 10
- 30
- 59
0
votes
1 answer
Hibernate: optional attribute in composite natural primary key
I'm experiencing an issue with Hibernate. I have an Entity mapped to a table with a natural composite primary key. The primary key consists of a mandatory code and either an optional Date or Period ID, so date and period_id are mutual exclusive. I…

dr jerry
- 9,768
- 24
- 79
- 122
-1
votes
2 answers
How to handle an Unwrap optional value
if messages[i].header == nil || messages[i].header.sender == nil || messages[i].header.sender.displayName == nil{
snd = "No Name"
}
else
{ snd = …

farhan ahmed
- 1
- 5