Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

JP Tomberlin
JP Tomberlin
14,317 Points

NetworkOperation

So I'm getting an error if I don't put () after NSURL for the constant queryURL. The error is "Expected member name or constructor call after type name". I'm using Xcode 7.2.1, Swift 2.0

import Foundation

class NetworkOperation {

    lazy var config: NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
    lazy var session: NSURLSession = NSURLSession(configuration: self.config)
    let queryURL = NSURL() // If I don't use () after NSURL here I get error

    init(url: NSURL) {
        self.queryURL = url
    }

}

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey JP Tomberlin,

You are getting that error because you have to initialize the variable with a value when using the assignment operator. When you write NSURL() you are constructing an instance of NSURL and assigning it to that variable.

If you don't want to assign an instance, you use a semicolon and declare NSURL as the type of that variable.

let queryURL: NSURL

I'm guessing this is what you wanted to do because you have queryURL defined as a constant. This means once you initialize it the value cannot be mutated again. Therefore, the initializer you are creating under it would never be able to be used.

Good Luck