SWIFT: Nested options in a single Guard statement

I tried to protect the conversion from string to Float to Int:

guard let v = Int (Float(" x")) else {
return -1
}

The swift 3 compiler complains:

value of optional type’Float?’ not unwrapped; did you mean to use’!’ or’?’?

Adding “?” but it did not help. And “!” would be wrong here, Isn’t it?

Is it possible to solve this problem without having to use two lines or two protection statements?

Optional map function, only for this: < p>

guard let v = Float("x").map(Int.init) else {
return nil
}

I tried to protect the conversion from string to Float to Int:

guard let v = Int (Float(" x")) else {
return -1
}

The swift 3 compiler complains:

value of optional type’Float?’ not unwrapped; did you mean to use’!’ or’?’?

Adding “?” but it did not help. And “!” would be wrong here, Isn’t it?

Is it possible to solve this problem without having to use two lines or two protection statements?

Optional map function, only used for this:

guard let v = Float("x").map(Int.init) else {
return nil
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4138 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.