Questions tagged [forceunwrap]

5 questions
2
votes
3 answers

Any? incorect semantics

I was playing around with some code in swift and encountered one interesting case. Lets start with a little preamble: suppose you create some optional variables: let a: String? = "abcd"; let b: Int? = 4 print( "Type of \(a) is \(type(of: a))"…
oneWayTicket
  • 101
  • 6
2
votes
1 answer

Why optional is not giving warning or asking for force unwraping?

struct SomeStruct { var optVar : String? var nonOptVar : String = "Hello" var optvar2 : String! } let obj2 = SomeStruct(optVar: "a", nonOptVar: "b", optvar2: "c") let a = obj2.optVar // why it is not asking for force unwraping let b =…
iGagan Kumar
  • 406
  • 8
  • 26
1
vote
2 answers

UIGraphicsGetImageFromCurrentImageContext() is giving me a chain reaction of forced unwrapped optionals I don't want in Swift

I'm confused about using UIGraphicsGetImageFromCurrentImageContext() in Swift, making me force unwrap it, even though it is defined with let. Adding in the ? or ! is making my code look messy and making me change everything after it. I'd like to not…
Chewie The Chorkie
  • 4,896
  • 9
  • 46
  • 90
-1
votes
2 answers

How to safely force unwrap time in dictionary

I have an issue. I have a dictionary type [String: Any] my code that works is dict["start"] = "\(start.hour!):\(start.minute!)" if let end = end { dict["end"] = "\(end.hour!):\(end.minute!)" } But as I use swiftlint it throws me an error for…
Jkrist
  • 748
  • 1
  • 6
  • 24
-1
votes
2 answers

Best way to remove force unwrapping

var recorder : Recorder? = nil func startAudioRecording() { if recorder == nil { recorder = Recorder() } if !recorder!.isRunning() { recorder?.startRecording({ [weak self] audioData in …
Sanoj Kashyap
  • 5,020
  • 4
  • 49
  • 75