0

I am using some code off of github and trying to convert it to Swift 3.0. I have done everything up until now, but I am getting this one error on 3 lines in the code:

Type of expression is ambiguous without more context

Below I have marked the lines that are labeled by this error. How do I go about fixing this? Everything else works that I know of. I just can't test the demo itself until this is fixed.

//
//  PasscodeSettingsViewController.swift
//  PasscodeLockDemo
//
//  Created by Yanko Dimitrov on 8/29/15.
//  Copyright © 2015 Yanko Dimitrov. All rights reserved.
//

import UIKit
import PasscodeLock

class PasscodeSettingsViewController: UIViewController {
    @IBOutlet weak var passcodeSwitch: UISwitch!
    @IBOutlet weak var changePasscodeButton: UIButton!
    @IBOutlet weak var testTextField: UITextField!
    @IBOutlet weak var testActivityButton: UIButton!

    fileprivate let configuration: PasscodeLockConfigurationType

    init(configuration: PasscodeLockConfigurationType) {
        self.configuration = configuration

        super.init(nibName: nil, bundle: nil)
    }

    @IBAction func passcodeSwitchValueChange(_ sender: UISwitch) {
        let passcodeVC: PasscodeLockViewController

        if passcodeSwitch.isOn {
            // Error on next line
            passcodeVC = PasscodeLockViewController(state: .SetPasscode, configuration: configuration)
        } else {

            // Error on next line
            passcodeVC = PasscodeLockViewController(state: .RemovePasscode, configuration: configuration)

            passcodeVC.successCallback = { lock in

                lock.repository.deletePasscode()
            }
        }

        present(passcodeVC, animated: true, completion: nil)
    }

    @IBAction func changePasscodeButtonTap(_ sender: UIButton) {
        let repo = UserDefaultsPasscodeRepository()
        let config = PasscodeLockConfiguration(repository: repo)

        let passcodeLock = PasscodeLockViewController(state: .ChangePasscode, configuration: config) 

        // Error on next line
        presentViewController(passcodeLock, animated: true, completion: nil)
    }
}
3
  • 1
    Provide PasscodeLockViewController's definition or give the link to GitHub repo. Commented Aug 10, 2017 at 2:31
  • @nayem sorry for the delay. Here's the link github.com/yankodimitrov/SwiftPasscodeLock Commented Aug 10, 2017 at 19:04
  • The master branch of the repo contains previous version of Swift. So you need to do a lot of work for converting them to latest version of Swift. I recommend you checking out to this specific commit which contains conversion of the implementation part. You just need to modify the demo part / use the latest syntax for your personal case. Commented Aug 11, 2017 at 9:31

1 Answer 1

0

The master branch of the repo contains previous version of Swift. After automatic conversion (when you first clone the project and open with Xcode and Xcode prompts you to convert to Current Swift Syntax) the LockState enum inside PasscodeLockViewController class becomes:

public enum LockState {
    case enterPasscode
    case setPasscode
    case changePasscode
    case removePasscode

    func getState() -> PasscodeLockStateType {

        switch self {
        case .enterPasscode: return EnterPasscodeState()
        case .setPasscode: return SetPasscodeState()
        case .changePasscode: return ChangePasscodeState()
        case .removePasscode: return EnterPasscodeState(allowCancellation: true)
        }
    }
}

In the demo project where you are instantiating you are using: (Here the enumeration case is Uppercased as .SetPasscode)

passcodeVC = PasscodeLockViewController(state: .SetPasscode, configuration: configuration)

You have to change this initialization to:

passcodeVC = PasscodeLockViewController(state: .setPasscode, configuration: configuration)

And for other recurring same type error in Xcode, you have to change them respectively.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.