David Seek
David Seek

Reputation: 17132

Swift / Backendless / Use of unresolved identifier

I'm trying to use the backendless API for registering a user. I did everything step by step needed to correctly import the framework.

The AppDelegate.swift is accepting the framework.

    func application(application: UIApplication, didFinishLaunchingWithOptions
    launchOptions: [NSObject: AnyObject]?) -> Bool {
    backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
//    DebLog.isActive = true
    backendless.hostURL = "https://api.backendless.com"
    backendless.initApp(APP_ID, secret: SECRET_KEY, version: VERSION_NUM)
    return true
    }

But as soon as I use backendless in my ViewController, I receive an error.

@IBAction func rememberMe(sender: AnyObject) {
    backendless.userService.stayLoggedIn = sender.on
}

Use of unresolved identifier 'backendless'

I started the project and the import 3-4 times and did it exactly like explained in the documentation, but I always receive this error. I appreciate every help.

Upvotes: 0

Views: 1135

Answers (2)

Vivek
Vivek

Reputation: 5213

  1. Create a new project in Xcode as you normally would, then close the project.

  2. Open a Terminal window, and change the current directory to be the project's directory.

  3. Run the following command in the Terminal window, which will create a file with the name Podfile.

    pod init

  4. Open the created Podfile using a text editor and add the following text inside of the target block:

    pod 'Backendless', '4.0b2'

  5. Save Podfile, return to the Terminal window and run the following command:

    $ pod install

Don't forgot pod update $ pod update

  1. Once the pod is downloaded, Xcode project workspace file will be created. This should be the file you use to open the project in Xcode.

  2. If you develop with Swift, you will need to add a Swift bridging header. To do that, click the root node in the Project Structure and select the Build Settings section. Locate the Swift Compiler - General section. Enter the following value into the Objective-C Bridging Header field:

    Pods/Backendless/SDK/ios/backendless/include/Backendless-Bridging-Header.h

  3. Open .xcworkspace file to launch your project, and build it.

For more detail Please open below link https://backendless.com/docs/ios/doc.html#setup

Upvotes: 2

Paulw11
Paulw11

Reputation: 114875

If you look towards the top of the AppDelegate.swift file you will see

var backendless = Backendless.sharedInstance()

This sets the backendless instance variable to the shared instance of the Backendless framework, but this instance variable is local to the AppDelegate instance. You need this same line in your ViewController.swift otherwise the compiler doesn't know what backendless is - it is an unresolved identifier

Upvotes: 0

Related Questions