Skip to main content

All Questions

Tagged with
-1 votes
1 answer
92 views

How to force non-optional type (for array element) on compile time in Swift? [closed]

struct MyStruct { @ArrayOfNonOptionalElements var arr: [SomeNonOptionalType] } where @ArrayOfNonOptionalElements is a propertyWrapper. So, how to force non-optionality for the type inside? Is it ...
Roman's user avatar
  • 1,485
2 votes
2 answers
90 views

Swift, Why are the memory sizes of 'String' and 'String?' the same?

Case Int, Int? I realized that in the case of optional variables, a bit is needed to check if nil, so it comes out 1 byte larger. But why is the memory size of String and String? the same? Not only ...
Kyxxn's user avatar
  • 21
-2 votes
1 answer
195 views

How to fix this force cast in swift

I am facing this below issue in my project, kindly help me to fix this issue. Force Cast Violation: Force casts should be avoided. (force_cast) var guestNetworks: [WanNetworks] { for result in ...
B.Saravana Kumar's user avatar
1 vote
3 answers
263 views

guard/if let in Java - declare a property or an object if it can be unwrapped

In swift there is the guard let / if let pattern allowing us to declare an object or a property only if it can be unwrapped. it works a follow: func getMeaningOfLife() -> Int? { 42 } func ...
Cublax's user avatar
  • 1,349
-1 votes
1 answer
45 views

meaning of this code: return self.desk[number]![alpha]

please help me understand this part of the code. Why is ! located between two brackets []![] in this expression: self.desk[number]![alpha]? class GameDesk { var desk : [Int: [String: Chessman]] = [...
PLUXVR's user avatar
  • 1
0 votes
1 answer
131 views

Initializer for conditional binding must have Optional type, not 'Float' Error in swift

Given: var conv_factor: String? var standard_rate_in_usd: Double? now I need a Float value var floatVal: Float? if let priceVal = Float(indexData.standard_rate_in_usd!), let convVal = Float((...
swift doubts's user avatar
0 votes
0 answers
50 views

Binding an optional object from one view to be changed in another in SwiftUI [duplicate]

I have a top-level object Estate, which is changed throughout the app. And this object has an optional object Meter, which can also be changed by adding Reading. The binding of the Estate is possible ...
Roman R's user avatar
  • 49
0 votes
1 answer
101 views

I tried to get the index of an element from Core Data, but it shows an error even I force unwrapped the value of the index

I try to use a function to sorted the data in the Core Data, and get the firstIndex of the first element base on the predicate, but when I used .firstIndex, it shows: Value of type '((Filedetails) -&...
Pakpak's user avatar
  • 3
0 votes
1 answer
409 views

extension for Optional Task

Can we make an extension of Optional type where wrapped type is async Task which is generic struct itself? I al so need to use Task underlying types inside. Example of what I need (which is not ...
bodich's user avatar
  • 2,143
-1 votes
2 answers
83 views

How to do optional with an or conditions in Swift?

i am trying to do following:- var isSomeThingTrue = checkSomeThing() if (let someOptional = getSomeOptional(), let anotherOptional = getAnotherOptional(withSomeOptional: someOptional)) || ...
Ashish P's user avatar
  • 1,473
0 votes
2 answers
95 views

Why call func from protocol instead of struct

protocol Readable {} extension Readable { func text() -> String? { "in protocol" } } struct Book: Readable { func text() -> String { "in struct" ...
xjliu's user avatar
  • 9
0 votes
1 answer
439 views

Swift error with change from string to double (why String type number becomes nil?)

I'm trying to make my own toy project to study Swift. But I got a problem with converting string to double. Please refer to the following codes first. //MARK: - ExchangeManagerDelegate extension ...
Hoyeon Lee's user avatar
0 votes
0 answers
96 views

fetch boolean core data and filter using if statement

in my swift code below the goal is to fetch a boolean value from core data. Once that value is fetched it should be filtered using a if statement. If the value is true is should display a image on the ...
Mos VIN's user avatar
0 votes
1 answer
153 views

Error to use a shorter spelling to unwrap a value

in Swift documentation at https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html, there are examples about usage of optionals and unwrapping them. When I try the examples on my Macbook, I got an ...
Oğuzhan Bölükbaş's user avatar
0 votes
0 answers
166 views

fetch Boolean values from core data

In my swift code below the goal is to fetch a series of Boolean values. It should fetch multiple values. Something along the lines of false, false, true etc. Right now I am having issues in my base ...
Mos VIN's user avatar

15 30 50 per page
1
2 3 4 5
89