Questions tagged [optional-variables]

36 questions
0
votes
2 answers

Swift: Why all my optional variable looks like "Optional(305.502)"

I've just start learning swift. And I am a little be confused with optional types. I have some variable var theOptVar: Float? it can be nil so I make it optional with ?. But when I'd like to get it somewhere at UI I see Optional(305.502). Is there…
user3742622
  • 1,037
  • 3
  • 22
  • 40
0
votes
2 answers

How to unwrap NSMutableDictionary.allkeys in optional String Array

I am trying to get all the key values of NSMutableDictionary as String Array. I am using this myNSMutableDictionary.allkeys to get the values as an Array but I cannot find a way to unwrap the key values. This is what I have tried so far: for (key,…
Tal Zion
  • 6,308
  • 3
  • 50
  • 73
0
votes
0 answers

Swift: how to check responds to and assign var declared in protocol as optional

protocol declaration: @objc protocol LeftSideMenuViewControllerProtocol { var containerShouldPerformContentSegueWithIdentifier:((segueIdentifier: String, object: AnyObject!) -> Void)! {set get} optional var…
iiFreeman
  • 5,165
  • 2
  • 29
  • 42
0
votes
2 answers

Working with optionals in Swift programming language

As far as I know the recommended way to use optionals (Int in this example) is the following: var one:Int? if var maybe = one { println(maybe) } Is it possible to use a shorter way to do something like the following? var one:Int? var…
Linus
  • 4,643
  • 8
  • 49
  • 74
-2
votes
1 answer

Uwrapping optionals - Swift 1.2 Xcode 6.4

I still got problems with optionals, examples made by Apple are not clear to me. I understood that: 1 - optional is a Type of data, so Int? or String? are optionals, not Int or String 2 - optional can be a variable, not a constant, that as far as…
biggreentree
  • 1,633
  • 3
  • 20
  • 35
-4
votes
4 answers

Swift optional downcasting as Any

If we are trying access optional object property can we do like this - var obj: Person var str = obj.name? as Any is this the right way to handle a nil case in swift3?
srus2017
  • 394
  • 2
  • 14
1 2
3