I
I
Ivan Vasilich2017-06-04 17:38:52
Swift
Ivan Vasilich, 2017-06-04 17:38:52

How to determine the type of a variable in swift?

Good afternoon / evening everyone, I’m studying swift and in parallel with the perfect soft framework, the question arose,
I want to move the variable to a function so as not to duplicate the code. in general, everything looks like this.

func setCookies () -> HTTPCookie {
  var iLoveMyCookie = HTTPCookie(
    name: "PerfectCookie",
    value: "Perfect is awesome",
    domain: "localhost",
    expires: .relativeSeconds(60),
    path: "/",
    secure: false,
    httpOnly: false
  ) 
return  iLoveMyCookie
}

the problem is that I don't understand what the function should return. I have specified HTTPCookie but it gives an error (HTTPCookie is a structure)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Gorb, 2017-06-07
@AntonGorb

func setCookies() -> HTTPCookie? {
        let cookieProperties: [HTTPCookiePropertyKey : Any] = [HTTPCookiePropertyKey.name:   "PerfectCookie",
                                                               HTTPCookiePropertyKey.value:  "Perfect is awesome",
                                                               HTTPCookiePropertyKey.domain: "localhost",
                                                               HTTPCookiePropertyKey.secure:  false]
        return  HTTPCookie(properties: cookieProperties)
    }

S
Stanislav Korolevskiy, 2017-06-04
@korolevsky_s

You have indicated

return iLoveMyCookie
. That's why the iLoveMyCookie function returns.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question