iosswiftswift3passcode

Passcode with TouchiD Error "Type is ambiguous without more context"


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)
    }
}

Solution

  • 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.