67 questions
-1
votes
1
answer
79
views
Can I safely assign a non-nil value to a non-optional nil object in Swift?
If you bridge C or Objective-C to Swift, you can misuse _Nonnull to falsely make a guarantee to Swift that a value never holds nil.
However, suppose I have this situation in Swift:
var nonoptional: ...
1
vote
1
answer
71
views
Firebase login setup failure: "Initializer for conditional binding must have Optional type, not 'String'" [duplicate]
When I run my code I receive this error:
/Users/ayaangrover/Documents/Github/waffle/Waffle/Waffle/ContentView.swift:46:19 Initializer for conditional binding must have Optional type, not 'String'.
...
-1
votes
1
answer
78
views
Checking if Optional<Int> is nil
Help me understand this weird nil-check.
I have a variable of the type Int? and I need to switch on nil.
This makes sense:
buildFrameId is 3 and not equal to nil
This does not:
buildFrameId is nil ...
1
vote
1
answer
159
views
Getting a compiler error trying to write a complicated Predicate - Scenario 2
This is an additional scenario for the question and answer covered here.
Sample code is available here.
Original problem was related to this predicate:
let aPred = #Predicate<Event> {
...
1
vote
2
answers
421
views
How can we have "one source of truth" when SwiftUI doesn't support optionals?
I need to display and allow the editing of a class whose members are mostly optional. This does not appear to be a scenario that SwiftUI envisions, despite Apple propagating the "single source of ...
0
votes
1
answer
38
views
Code works on iOS simulator (iPhone 13mini) chrashes on real iPhone 13mini: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Can anyone help: The code works on iOS simulator (iPhone 13mini) chrashes on real iPhone 13mini: Fatal error: Unexpectedly found nil while unwrapping an Optional value.
I don't understand how "...
1
vote
1
answer
99
views
Getting error with previously supported Optional type requirements on a function declaration (same-type, error in Swift 6)
This currently works, but in xcode-beta it is now showing a warning:
Same-type requirement makes generic parameter 'Value' non-generic; this is an error in Swift 6
func getUDValue<Value, R>(_ ...
0
votes
2
answers
795
views
Swift WKwebView.evaluateJavaScript Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
I want to execute javascript in an external screen's webview. In my main view I'm trying to call the pop() function in the External View like this:
let ex = ExternalDisplayViewController()
ex.pop(str: ...
0
votes
1
answer
148
views
Getting nil from Enum Swift
I have created a class
class NewTabContainerModal {
var newContainerDate = Date()
var newContainerSelectedFilter : NewAllErrorFIlter = .Yearly
func resetModal () {
newContainerSelectedFilter = ....
0
votes
0
answers
58
views
How do I access data in a nested json in Swift(while using optionals in my data model) [duplicate]
I have my struct as:
struct CategoryViewModel2: Codable {
let data: [Datum2]?
}
// MARK: - Datum
struct Datum2: Codable {
let the0: Int?
let the1, the2: String?
let the3, the4, id: ...
0
votes
0
answers
28
views
"Unexpectedly found nil while implicitly unwrapping an Optional value" using the Date() structure, then transitioning to another storyboard [duplicate]
I created a label to show the current date when the view loads, but when I transition to another view, I get the: Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional ...
1
vote
1
answer
483
views
Swift - Sort array by optionals [duplicate]
So if have an array of ToDos and the Todo objects have the properties due(Bool) which has the info if the ToDo has a due date; dueDate(Date) which is an optional so if due is true dueDate != nil, if ...
0
votes
1
answer
419
views
Generic decoding json into object with optionals
I wrote an extension to Decodable with the hopes of having a generic constructor for objects from json strings, it looks like this:
extension Decodable {
init?(with dictionary: [String: Any]) {
...
1
vote
1
answer
6k
views
Why is 'Fatal error: Unexpectedly found nil while unwrapping an Optional value' showing despite no nil values being present?
I've been investigating this error for a while and I am still struggling to find an answer.
I understand the concept behind this error yet I don't understand why it is still notifying me even though I ...
0
votes
1
answer
134
views
Using if let... don't understand where data is coming from
I am following the Stanford CS193 SwiftUI iOS Development Course on YouTube and I am having a very difficult time comprehending how a certain piece of the code is working.
import Foundation
struct ...
1
vote
1
answer
515
views
How do I access an outlet from another View Controller? (Swift)
I am new to Swift programming and am trying to make a simple app that presents a Challenge which you can then complete by pressing a button. Then in a separate view controller you unlock images when ...
0
votes
1
answer
179
views
Swift: How to use optional in ternary check for disabling button
I have a simple task for JS, and I have no idea how to make it using Swift. Help me please to understand and make this.
I need just check if state value is or not nil, and disable the button.
Button(...
1
vote
1
answer
239
views
Swift safe unwrapping optional a Class Constant without redundancy
I am trying to get more Structure into my code so I am implementing this UserDefaultsService:
class UserDefaultsService {
let defaults = UserDefaults(suiteName: UserDefaults.Keys.groupKey)
...
-1
votes
1
answer
44
views
Why the if != nil works only sometimes during the app being used?
I'm stuck with an issue and need your help. I'm working on an app to manage events and when app loads, all the posts are displayed as expected both with or without images into the post. If I add a new ...
1
vote
2
answers
571
views
How do I unwrap a printed returned optional in a function (exercise)
Hi I'm trying to learn Swift using Apples Fundamentals of Swift book.
There has been a similar post in the past but I have some problems with the answer provided that I would like clarified.
The post ...
-1
votes
1
answer
550
views
Unwrapped URLRequest is always nil
I'm trying to detect clicks on links in a WKWebView and load the corresponding URLs in another WKWebView.
I'm able to get the URL of the click and create a URL request but loading the URLRequest ...
-2
votes
1
answer
56
views
How do I check an array for no entry and a companion array for an entry?
I am moving a card game written in Objective-C to Swift. I have 2 arrays in my Hand class, both of size 3, one holding the 3 side-by-side down cards and the other holding the up cards that are on top ...
-1
votes
2
answers
850
views
Could not cast value of type 'NSNull' to 'NSString' and then the app crashes
We are trying to make a function to get JSON from an API..We know that this is giving us NIL but we dont know why the error is occuring. The exact error message that we got was
[]
2020-08-01 16:29:26....
0
votes
2
answers
721
views
Swift Extension - Optional
I'm trying to extend optionals into something readable, and achieved this so far:
@discardableResult
func isNotNil(_ handler: (Wrapped) -> Void) -> Optional {
switch self {
...
0
votes
2
answers
720
views
CompactMapValues not working on this simple dictionary
I have a model that looks like:
public struct Profile {
public let bio: String?
public let company: String
public let createdDate: Date
public let department: String
public let email: ...