1

Let say I have 2 packages in common

"Basic Package" & "Advance Package".

And Two views.The first one show the current package and the other one show available packages.

Eg.Let my current plan will be Basic Package and I switched to Advance Package.So,The current package will be Advance Package and the available plans will be Basic Package.That Switch Package Async and Get Packages Process will do every time it call.Means after i clicked Switch button,it switch the package at server and then get current package status back after it success switching package for updating two views.

So,I really do have a problem,I am using picker view to show available packages.But,after switching plan and getting latest plan,it show me ["Basic Package","Advance Package"] at availablePackage.Actually it should show only one available package ["Basic Package"] after i switch to ["Advance Package"] at current view.

var basePackage : Results<PlanList>!

var availablePackage : [String] = []

func removeDuplicates(array: [String]) -> [String] {
    var encountered = Set<String>()
    var result: [String] = []
    for value in array {
        if encountered.contains(value) {
            // Do not add a duplicate element.
        }
        else {
            // Add value to the set.
            encountered.insert(value)
            // ... Append the value.
            result.append(value)
        }
    }
    return result
}

func getLatestAvailablePackages(){
    basePackage = realm.objects(PlanList).filter("currentPackage = '0'") // Current Packages 0 means inactive available packages 
    if basePlan.count > 0{
        for var i = 0 ; i < basePlan.count ; i++ { // Getting available packages and insert at switchArray to show at picker
            availablePackage.insert(basePackage[i].packageName, atIndex: i)

        }
        availablePackage = removeDuplicates(availablePackage)
    }
}

// After it complete switching plan at server,getting latest plan will do for updating the two views
func didSuccessGettingPlan(results: JSON) {
// Insertion into realm database after it get the packages of user subscribe / "0" means available package and "1" mean current subscribe package.     
//self.realmDBHelper.insertPackages(results)
     getLatestAvailablePackages()
}

The Process is clear.Is about updating two views and picker value for selections if user want to change package.

Any help?

Why my availablePackage is ["Basic Package","Advance Package"] after user switch from Basic to Advance.Actually it should be ["Basic Package"] at availablePackage array.Any help with my stupid logic?

1 Answer 1

1
func getLatestAvailablePackages() {

        availablePackage.removeAll()
        //...
}
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.