iosxcodeuitableviewswift3duplicates

Swift 3: Cannot remove duplicate data from the tableView


I am trying to remove duplicates from the tableView. The data that are fetched on the tableview comes from external database. Some of the data that are fetched are repeated few times.

The data that I need to be displayed is the profile name and region i.e. Show All, North, East, South, West. Now, there can be a profile (For E.g. George's Concreting) that can appear in 3 regions. For instance North, East and West. By default, when the view loads, it shows all the businesses in all regions. On this view, I have some businesses that are repeated. Our George's Concreting profile repeats 3 times in this view, where it should only be repeated once. When I click on North/East/West the George's Concreting should appear there as well just once.

So basically, George's Concreting should only appear once in Show All although it has 3 businesses in 3 regions and when we click on the other regions, it should also appear once. Please refer to the screenshot.

Using the following code I get and error on Line, Please refer to error

Code:

class StorageSubCatagoriezTwo
{
    var nameString:String
    var idString:String
    var address:String
    var telephone:String
    var email:String
    var website:String

init(tempName:String,tempID:String,tempaddress:String,tempTelephone:String,tempEmail:String,tempWebsite:String)
{
    self.nameString = tempName.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.idString  = tempID.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.address = tempaddress.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.telephone = tempTelephone.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.email = tempEmail.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.website = tempWebsite.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
}
}

class StorageSubCatagoriezTwoNorth
{
    var nameString:String
    var idString:String
    var address:String
    var telephone:String
    var email:String
    var website:String
    
init(tempName:String,tempID:String,tempaddress:String,tempTelephone:String,tempEmail:String,tempWebsite:String)
{
    self.nameString = tempName.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.idString  = tempID.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.address = tempaddress.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.telephone = tempTelephone.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.email = tempEmail.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.website = tempWebsite.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
}
}

class StorageSubCatagoriezTwoEast
{
    var nameString:String
    var idString:String
    var address:String
    var telephone:String
    var email:String
    var website:String
    
init(tempName:String,tempID:String,tempaddress:String,tempTelephone:String,tempEmail:String,tempWebsite:String)
{
    self.nameString = tempName.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.idString  = tempID.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.address = tempaddress.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.telephone = tempTelephone.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.email = tempEmail.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.website = tempWebsite.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
}
}

class StorageSubCatagoriezTwoWest
{
    var nameString:String
    var idString:String
    var address:String
    var telephone:String
    var email:String
    var website:String
    
init(tempName:String,tempID:String,tempaddress:String,tempTelephone:String,tempEmail:String,tempWebsite:String)
{
    self.nameString = tempName.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.idString  = tempID.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.address = tempaddress.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.telephone = tempTelephone.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.email = tempEmail.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.website = tempWebsite.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)    }
}

class StorageSubCatagoriezTwoSouth
{
    var nameString:String
    var idString:String
    var address:String
    var telephone:String
    var email:String
    var website:String

init(tempName:String,tempID:String,tempaddress:String,tempTelephone:String,tempEmail:String,tempWebsite:String)
{
    self.nameString = tempName.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.idString  = tempID.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.address = tempaddress.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.telephone = tempTelephone.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.email = tempEmail.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
    self.website = tempWebsite.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
}
}

___________________________________________________________




 var subCatagorizeDataTwo = Array<StorageSubCatagoriezTwo>()
var subCatagorizeDataTwoN = Array<StorageSubCatagoriezTwoNorth>()
var subCatagorizeDataTwoE = Array<StorageSubCatagoriezTwoEast>()
var subCatagorizeDataTwoW = Array<StorageSubCatagoriezTwoWest>()
var subCatagorizeDataTwoS = Array<StorageSubCatagoriezTwoSouth>()
var SubCatagoriez3rd = Array<StorageSubCatagoriez3rd>()



func removeDuplicate (sourceArray: [Int]) -> [Int] {
    var uniqueArray:[Int] = []
    for object in sourceArray {
        if !uniqueArray.contains(object)
        {
            uniqueArray.append(object)
        }
    }
    return uniqueArray
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        
        
    if indexPath.section == 0
    {
        let cell = self.businessTableView.dequeueReusableCell(withIdentifier: "businessCell", for: indexPath) as! BusinessCell
        
        let tableObjects:StorageSubCatagoriezTwo = subCatagorizeDataTwo[indexPath.row]
        
        //let charCheck = (tableObjects.address).replacingOccurrences(of: " ", with: "")
        
        
        if reg == "North"
        {
            cell.businessName.text = " "
            cell.addLabel.text = " "
            cell.telLabel.text = " "
            cell.emailLabel.text =  " "
            cell.webLabel.text = " "
            
            var tableObjects:StorageSubCatagoriezTwoNorth = subCatagorizeDataTwoN[indexPath.row]
            tableObjects = removeDuplicate(sourceArray: [tableObjects.nameString]) 
//**error** {Cannot convert value of type 'String' to expected element type 'Int'}
            
            
            if tableObjects.address.characters.isEmpty != true
            {
                cell.addLabel.text = tableObjects.address
            }
            else
            {
                //nothing
            }
            if tableObjects.telephone.characters.isEmpty != true
            {
                cell.telLabel.text = tableObjects.telephone
            }
            else
            {
                
            }
            if tableObjects.email.characters.isEmpty != true
            {
                cell.emailLabel.text = tableObjects.email
            }
            else
            {
                
            }
            if tableObjects.website.characters.isEmpty != true{
                cell.webLabel.text = tableObjects.website
            }
            else{
                
            }
        }
        else if reg == "East"
        {
            cell.businessName.text = " "
            let tableObjects:StorageSubCatagoriezTwoEast = subCatagorizeDataTwoE[indexPath.row]
            cell.businessName.text = tableObjects.nameString
            if tableObjects.address.characters.isEmpty != true
            {
                cell.addLabel.text = tableObjects.address
            }
            else
            {
                //nothing
            }
            if tableObjects.telephone.characters.isEmpty != true
            {
                cell.telLabel.text = tableObjects.telephone
            }
            else
            {
                
            }
            if tableObjects.email.characters.isEmpty != true
            {
                cell.emailLabel.text = tableObjects.email
            }
            else
            {
                
            }
            if tableObjects.website.characters.isEmpty != true
            {
                cell.webLabel.text = tableObjects.website
            }
            else{
                
            }
        }
        else if reg == "South"
        {
            cell.businessName.text = " "
            let tableObjects:StorageSubCatagoriezTwoSouth = subCatagorizeDataTwoS[indexPath.row]
            cell.businessName.text = tableObjects.nameString
            if tableObjects.address.characters.isEmpty != true
            {
                cell.addLabel.text = tableObjects.address
            }
            else
            {
                //nothing
            }
            if tableObjects.telephone.characters.isEmpty != true
            {
                cell.telLabel.text = tableObjects.telephone
            }
            else
            {
                
            }
            if tableObjects.email.characters.isEmpty != true
            {
                cell.emailLabel.text = tableObjects.email
            }
            else
            {
                
            }
            if tableObjects.website.characters.isEmpty != true{
                cell.webLabel.text = tableObjects.website
            }
            else{
                
            }
        }
        else if reg == "West"
        {
            cell.businessName.text = " "
            let tableObjects:StorageSubCatagoriezTwoWest = subCatagorizeDataTwoW[indexPath.row]
            cell.businessName.text = tableObjects.nameString
            if tableObjects.address.characters.isEmpty != true
            {
              cell.addLabel.text = tableObjects.address
            }
            else
            {
                //nothing
            }
            if tableObjects.telephone.characters.isEmpty != true
            {
                cell.telLabel.text = tableObjects.telephone
            }
            else
            {
                
            }
            if tableObjects.email.characters.isEmpty != true
            {
                cell.emailLabel.text = tableObjects.email
            }
            else
            {
                
            }
            if tableObjects.website.characters.isEmpty != true{
               cell.webLabel.text = tableObjects.website
            }
            
        }
        else{
            let tableObjects:StorageSubCatagoriezTwo = subCatagorizeDataTwo[indexPath.row]
            cell.businessName.text = tableObjects.nameString
            
            let charCheck = (tableObjects.address).replacingOccurrences(of: " ", with: "")
            
            cell.businessName.text = tableObjects.nameString
            cell.addLabel.text = tableObjects.address
            cell.telLabel.text = tableObjects.telephone
            cell.emailLabel.text = tableObjects.email
            cell.webLabel.text = tableObjects.website
            
        }
        
        
        return cell
    }
        
    else if indexPath.section == 1
    {
        let cell = self.businessTableView.dequeueReusableCell(withIdentifier: "businessCell2")
        cell?.textLabel?.textAlignment = .center
        switch regId
        {
        case 0:
            if subCatagorizeDataTwo.count != forAll
            {
                cell?.textLabel?.text = "Load More Data"
                cell?.textLabel?.textColor = Color.whiteColor
                cell?.backgroundColor = UIColor.darkGray
                
            }else{
                cell?.textLabel?.text = "No More Data Found"
                cell?.textLabel?.textColor = UIColor.darkGray
                cell?.backgroundColor = UIColor.gray
                cell?.selectionStyle = UITableViewCellSelectionStyle.none
            }
        case 1:
            if subCatagorizeDataTwoN.count != forN
            {
                cell?.textLabel?.text = "Load More Data"
                cell?.textLabel?.textColor = Color.whiteColor
                cell?.backgroundColor = UIColor.darkGray
                
            }else{
                cell?.textLabel?.text = "No More Data Found"
                cell?.textLabel?.textColor = UIColor.darkGray
                cell?.backgroundColor = UIColor.gray
                cell?.selectionStyle = UITableViewCellSelectionStyle.none
            }
        case 2:
            if subCatagorizeDataTwoE.count != forE
            {
                cell?.textLabel?.text = "Load More Data"
                cell?.textLabel?.textColor = Color.whiteColor
                cell?.backgroundColor = UIColor.darkGray
                
            }else{
                cell?.textLabel?.text = "No More Data Found"
                cell?.textLabel?.textColor = UIColor.darkGray
                cell?.backgroundColor = UIColor.gray
                cell?.selectionStyle = UITableViewCellSelectionStyle.none
            }
        case 3:
            if subCatagorizeDataTwoS.count != forS
            {
                cell?.textLabel?.text = "Load More Data"
                cell?.textLabel?.textColor = Color.whiteColor
                cell?.backgroundColor = UIColor.darkGray
                
            }else{
                cell?.textLabel?.text = "No More Data Found"
                cell?.textLabel?.textColor = UIColor.darkGray
                cell?.backgroundColor = UIColor.gray
                cell?.selectionStyle = UITableViewCellSelectionStyle.none
            }
        case 4:
            if subCatagorizeDataTwoW.count != forW
            {
                cell?.textLabel?.text = "Load More Data"
                cell?.textLabel?.textColor = Color.whiteColor
                cell?.backgroundColor = UIColor.darkGray
                
            }else{
                cell?.textLabel?.text = "No More Data Found"
                cell?.textLabel?.textColor = UIColor.darkGray
                cell?.backgroundColor = UIColor.gray
                cell?.selectionStyle = UITableViewCellSelectionStyle.none
            }
            
        default:break
        }
        
        return cell!
    }
    else
    {
        let tableObjects:StorageSubCatagoriez3rd = SubCatagoriez3rd[indexPath.row]
        let cell = self.businessTableView.dequeueReusableCell(withIdentifier: "businessCell3")
        cell?.textLabel?.text = tableObjects.nameString
        return cell!
        
    }
}

Screenshot enter image description here


Solution

  • Solution: *( I only created the 4 funcs)

      func  UpdateSubCatagorizeTwoRegNorth(_ id:String) {
        subCatagorizeDataTwo.removeAll()
        subCatagorizeDataTwoN.removeAll()
        subCatagorizeDataTwoE.removeAll()
        subCatagorizeDataTwoW.removeAll()
        subCatagorizeDataTwoS.removeAll()
        SubCatagoriez3rd.removeAll()
        self.view.isUserInteractionEnabled = false
        progress.isHidden = false
    
        let request = NSMutableURLRequest(url: urls.subCatagoriezTwoURLRegNorth as URL)
        let postString = "id="+id
        request.httpBody = postString.data(using: String.Encoding.utf8)
        request.httpMethod = "POST"
    
        let task = URLSession.shared.dataTask(with: request as URLRequest) { data,response,error in
            guard error == nil && data != nil else
            {
                self.progress.isHidden = true
                self.view.isUserInteractionEnabled = true
                self.alertMessage.alert("Error:\(error)", icon: "error", View: self)
                return
            }
    
            let httpStatus = response as? HTTPURLResponse
    
            if httpStatus!.statusCode == 200
            {
                if data?.count != 0
                {
                    let responseString = convert.contvertToDictionary(data!) as? [[String:AnyObject]]
    
                    if responseString != nil
                    {
                        for dictionary in responseString!
                        {
    
                            let id = String(describing: dictionary["id"]!)
                            let name = String(describing: dictionary["BUSINESS_NAME"]!)
                            let email = String(describing: dictionary["EMAIL"]!)
                            var streetNo = String(describing: dictionary["STREET_NO"]!)
                            var streetName = String(describing: dictionary["STREET_NAME"]!)
                            var suburbID = String(describing: dictionary["SUBURB_ID"]!)
                            var postCode = String(describing: dictionary["POSTCODE"]!)
                            // let regionID = String(describing: dictionary["REGION_ID"]!)
                            let region = String(describing: dictionary["region"]!)
                            var landline = String(describing: dictionary["PHONE_FIXED"]!)
                            var mobile = String(describing: dictionary["PHONE_MOBILE"]!)
                            let website = String(describing: dictionary["WEBURL"]!)
                            var suburbName = String(describing: dictionary["Suburb"]!)
                            let streedNoHide = String(describing: dictionary["STREET_NO_HIDDEN"]!)
                            let streetNameHide = String(describing: dictionary["STREET_NAME_HIDDEN"]!)
                            let suburbHide = String(describing: dictionary["SUBURB_HIDDEN"]!)
                            let postCodeHide = String(describing: dictionary["POSTCODE_HIDDEN"]!)
                            let mobileHide = String(describing: dictionary["PHONE_MOBILE_HIDDEN"]!)
                            let landlineHide = String(describing: dictionary["PHONE_FIXED_HIDDEN"]!)
    
                            if streedNoHide != "0"
                            {
                                streetNo = ""
                            }else{
    
                            }
    
                            if streetNameHide != "0"
                            {
                                streetName=""
                            }
                            else{
                                //nothing here
                            }
    
    
                            if suburbHide != "0"
                            {
                                suburbName = ""
                                suburbID = ""
                            }
                            else{
                                //nothing here
                            }
    
    
                            if postCodeHide != "0"
                            {
                                postCode = ""
                            }
                            else{
                                //nothing here
                            }
    
                            if mobileHide != "0"
                            {
                                mobile = ""
                            }
                            else{
                                //nothing here
                            }
                            if landlineHide != "0"
                            {
                                landline = ""
                            }else
                            {
    
                            }
                            // streetno
                            DispatchQueue.main.async
                                {
    
                                    if region == "North"
                                    {
                                        self.subCatagorizeDataTwoN.append(StorageSubCatagoriezTwoNorth(tempName: name, tempID: id, tempaddress: " "+streetNo+" "+streetName+" "+suburbName+" "+postCode, tempTelephone: landline+" "+mobile, tempEmail: email, tempWebsite: website))
                                    }
                                    self.subCatagorizeDataTwo.append(StorageSubCatagoriezTwo(tempName: name, tempID: id, tempaddress:  " "+streetNo+" "+streetName+" "+suburbName+" "+postCode, tempTelephone: landline+" "+mobile, tempEmail: email, tempWebsite: website))
                            }
    
                        }
    
                        DispatchQueue.main.async
                            {
    
                                if  self.subCatagorizeDataTwoN.count >= 10
                                {
                                    self.forN = 10
                                }
                                else
                                {
                                    self.forN = self.subCatagorizeDataTwoN.count
                                }
    
                                self.UpdateSubCatagorizeTwo1(self.catName, url: self.urls.XRef)
                        }
                    }
                    else
                    {
                        DispatchQueue.main.async
                            {
                                self.progress.isHidden = true
                                self.view.isUserInteractionEnabled = true
                                self.alertMessage.alert("Problem with Requesting! Error 404", icon: "error", View: self)
                        }
                    }
    
                }
                else
                {
                    DispatchQueue.main.async
                        {
                            self.progress.isHidden = true
                            self.view.isUserInteractionEnabled = true
                            self.alertMessage.alert("No data got from url!", icon: "error", View: self)
                    }
                }
            }
            else
            {
                DispatchQueue.main.async
                    {
                        self.progress.isHidden = true
                        self.view.isUserInteractionEnabled = true
                        self.alertMessage.alert("error httpstatus code is : \(httpStatus!.statusCode)", icon: "error", View: self)
                }
            }
        }
        task.resume()
    
    
    }
    
    func  UpdateSubCatagorizeTwoRegEast(_ id:String) {
        subCatagorizeDataTwo.removeAll()
        subCatagorizeDataTwoN.removeAll()
        subCatagorizeDataTwoE.removeAll()
        subCatagorizeDataTwoW.removeAll()
        subCatagorizeDataTwoS.removeAll()
        SubCatagoriez3rd.removeAll()
        self.view.isUserInteractionEnabled = false
        progress.isHidden = false
    
        let request = NSMutableURLRequest(url: urls.subCatagoriezTwoURLEast as URL)
        let postString = "id="+id
        request.httpBody = postString.data(using: String.Encoding.utf8)
        request.httpMethod = "POST"
    
        let task = URLSession.shared.dataTask(with: request as URLRequest) { data,response,error in
            guard error == nil && data != nil else
            {
                self.progress.isHidden = true
                self.view.isUserInteractionEnabled = true
                self.alertMessage.alert("Error:\(error)", icon: "error", View: self)
                return
            }
    
            let httpStatus = response as? HTTPURLResponse
    
            if httpStatus!.statusCode == 200
            {
                if data?.count != 0
                {
                    let responseString = convert.contvertToDictionary(data!) as? [[String:AnyObject]]
    
                    if responseString != nil
                    {
                        for dictionary in responseString!
                        {
    
                            let id = String(describing: dictionary["id"]!)
                            let name = String(describing: dictionary["BUSINESS_NAME"]!)
                            let email = String(describing: dictionary["EMAIL"]!)
                            var streetNo = String(describing: dictionary["STREET_NO"]!)
                            var streetName = String(describing: dictionary["STREET_NAME"]!)
                            var suburbID = String(describing: dictionary["SUBURB_ID"]!)
                            var postCode = String(describing: dictionary["POSTCODE"]!)
                            // let regionID = String(describing: dictionary["REGION_ID"]!)
                            let region = String(describing: dictionary["region"]!)
                            var landline = String(describing: dictionary["PHONE_FIXED"]!)
                            var mobile = String(describing: dictionary["PHONE_MOBILE"]!)
                            let website = String(describing: dictionary["WEBURL"]!)
                            var suburbName = String(describing: dictionary["Suburb"]!)
                            let streedNoHide = String(describing: dictionary["STREET_NO_HIDDEN"]!)
                            let streetNameHide = String(describing: dictionary["STREET_NAME_HIDDEN"]!)
                            let suburbHide = String(describing: dictionary["SUBURB_HIDDEN"]!)
                            let postCodeHide = String(describing: dictionary["POSTCODE_HIDDEN"]!)
                            let mobileHide = String(describing: dictionary["PHONE_MOBILE_HIDDEN"]!)
                            let landlineHide = String(describing: dictionary["PHONE_FIXED_HIDDEN"]!)
    
                            if streedNoHide != "0"
                            {
                                streetNo = ""
                            }else{
    
                            }
    
                            if streetNameHide != "0"
                            {
                                streetName=""
                            }
                            else{
                                //nothing here
                            }
    
    
                            if suburbHide != "0"
                            {
                                suburbName = ""
                                suburbID = ""
                            }
                            else{
                                //nothing here
                            }
    
    
                            if postCodeHide != "0"
                            {
                                postCode = ""
                            }
                            else{
                                //nothing here
                            }
    
                            if mobileHide != "0"
                            {
                                mobile = ""
                            }
                            else{
                                //nothing here
                            }
                            if landlineHide != "0"
                            {
                                landline = ""
                            }else
                            {
    
                            }
                            // streetno
                            DispatchQueue.main.async
                                {
    
                                    if region == "East"
                                    {
                                        self.subCatagorizeDataTwoE.append(StorageSubCatagoriezTwoEast(tempName: name, tempID: id, tempaddress: " "+streetNo+" "+streetName+" "+suburbName+" "+postCode, tempTelephone: landline+" "+mobile, tempEmail: email, tempWebsite: website))
                                    }
                                    self.subCatagorizeDataTwo.append(StorageSubCatagoriezTwo(tempName: name, tempID: id, tempaddress:  " "+streetNo+" "+streetName+" "+suburbName+" "+postCode, tempTelephone: landline+" "+mobile, tempEmail: email, tempWebsite: website))
                            }
    
                        }
    
                        DispatchQueue.main.async
                            {
    
                                if  self.subCatagorizeDataTwoE.count >= 10
                                {
                                    self.forE = 10
                                }
                                else
                                {
                                    self.forE = self.subCatagorizeDataTwoE.count
                                }
    
                                self.UpdateSubCatagorizeTwo1(self.catName, url: self.urls.XRef)
                        }
                    }
                    else
                    {
                        DispatchQueue.main.async
                            {
                                self.progress.isHidden = true
                                self.view.isUserInteractionEnabled = true
                                self.alertMessage.alert("Problem with Requesting! Error 404", icon: "error", View: self)
                        }
                    }
    
                }
                else
                {
                    DispatchQueue.main.async
                        {
                            self.progress.isHidden = true
                            self.view.isUserInteractionEnabled = true
                            self.alertMessage.alert("No data got from url!", icon: "error", View: self)
                    }
                }
            }
            else
            {
                DispatchQueue.main.async
                    {
                        self.progress.isHidden = true
                        self.view.isUserInteractionEnabled = true
                        self.alertMessage.alert("error httpstatus code is : \(httpStatus!.statusCode)", icon: "error", View: self)
                }
            }
        }
        task.resume()
    
    
    }
    
    func  UpdateSubCatagorizeTwoRegSouth(_ id:String) {
        subCatagorizeDataTwo.removeAll()
        subCatagorizeDataTwoN.removeAll()
        subCatagorizeDataTwoE.removeAll()
        subCatagorizeDataTwoW.removeAll()
        subCatagorizeDataTwoS.removeAll()
        SubCatagoriez3rd.removeAll()
        self.view.isUserInteractionEnabled = false
        progress.isHidden = false
    
        let request = NSMutableURLRequest(url: urls.subCatagoriezTwoURLRegSouth as URL)
        let postString = "id="+id
        request.httpBody = postString.data(using: String.Encoding.utf8)
        request.httpMethod = "POST"
    
        let task = URLSession.shared.dataTask(with: request as URLRequest) { data,response,error in
            guard error == nil && data != nil else
            {
                self.progress.isHidden = true
                self.view.isUserInteractionEnabled = true
                self.alertMessage.alert("Error:\(error)", icon: "error", View: self)
                return
            }
    
            let httpStatus = response as? HTTPURLResponse
    
            if httpStatus!.statusCode == 200
            {
                if data?.count != 0
                {
                    let responseString = convert.contvertToDictionary(data!) as? [[String:AnyObject]]
    
                    if responseString != nil
                    {
                        for dictionary in responseString!
                        {
    
                            let id = String(describing: dictionary["id"]!)
                            let name = String(describing: dictionary["BUSINESS_NAME"]!)
                            let email = String(describing: dictionary["EMAIL"]!)
                            var streetNo = String(describing: dictionary["STREET_NO"]!)
                            var streetName = String(describing: dictionary["STREET_NAME"]!)
                            var suburbID = String(describing: dictionary["SUBURB_ID"]!)
                            var postCode = String(describing: dictionary["POSTCODE"]!)
                            // let regionID = String(describing: dictionary["REGION_ID"]!)
                            let region = String(describing: dictionary["region"]!)
                            var landline = String(describing: dictionary["PHONE_FIXED"]!)
                            var mobile = String(describing: dictionary["PHONE_MOBILE"]!)
                            let website = String(describing: dictionary["WEBURL"]!)
                            var suburbName = String(describing: dictionary["Suburb"]!)
                            let streedNoHide = String(describing: dictionary["STREET_NO_HIDDEN"]!)
                            let streetNameHide = String(describing: dictionary["STREET_NAME_HIDDEN"]!)
                            let suburbHide = String(describing: dictionary["SUBURB_HIDDEN"]!)
                            let postCodeHide = String(describing: dictionary["POSTCODE_HIDDEN"]!)
                            let mobileHide = String(describing: dictionary["PHONE_MOBILE_HIDDEN"]!)
                            let landlineHide = String(describing: dictionary["PHONE_FIXED_HIDDEN"]!)
    
                            if streedNoHide != "0"
                            {
                                streetNo = ""
                            }else{
    
                            }
    
                            if streetNameHide != "0"
                            {
                                streetName=""
                            }
                            else{
                                //nothing here
                            }
    
    
                            if suburbHide != "0"
                            {
                                suburbName = ""
                                suburbID = ""
                            }
                            else{
                                //nothing here
                            }
    
    
                            if postCodeHide != "0"
                            {
                                postCode = ""
                            }
                            else{
                                //nothing here
                            }
    
                            if mobileHide != "0"
                            {
                                mobile = ""
                            }
                            else{
                                //nothing here
                            }
                            if landlineHide != "0"
                            {
                                landline = ""
                            }else
                            {
    
                            }
                            // streetno
                            DispatchQueue.main.async
                                {
    
                                    if region == "South"
                                    {
                                        self.subCatagorizeDataTwoS.append(StorageSubCatagoriezTwoSouth(tempName: name, tempID: id, tempaddress: " "+streetNo+" "+streetName+" "+suburbName+" "+postCode, tempTelephone: landline+" "+mobile, tempEmail: email, tempWebsite: website))
                                    }
    
                                    self.subCatagorizeDataTwo.append(StorageSubCatagoriezTwo(tempName: name, tempID: id, tempaddress:  " "+streetNo+" "+streetName+" "+suburbName+" "+postCode, tempTelephone: landline+" "+mobile, tempEmail: email, tempWebsite: website))
                            }
    
                        }
    
                        DispatchQueue.main.async
                            {
    
                                if  self.subCatagorizeDataTwoS.count >= 10
                                {
                                    self.forS = 10
                                }
                                else
                                {
                                    self.forS = self.subCatagorizeDataTwoS.count
                                }
    
                                self.UpdateSubCatagorizeTwo1(self.catName, url: self.urls.XRef)
                        }
                    }
                    else
                    {
                        DispatchQueue.main.async
                            {
                                self.progress.isHidden = true
                                self.view.isUserInteractionEnabled = true
                                self.alertMessage.alert("Problem with Requesting! Error 404", icon: "error", View: self)
                        }
                    }
    
                }
                else
                {
                    DispatchQueue.main.async
                        {
                            self.progress.isHidden = true
                            self.view.isUserInteractionEnabled = true
                            self.alertMessage.alert("No data got from url!", icon: "error", View: self)
                    }
                }
            }
            else
            {
                DispatchQueue.main.async
                    {
                        self.progress.isHidden = true
                        self.view.isUserInteractionEnabled = true
                        self.alertMessage.alert("error httpstatus code is : \(httpStatus!.statusCode)", icon: "error", View: self)
                }
            }
        }
        task.resume()
    
    
    }
    

    Please do the same thing for WEST region. and replace required.