-1

I have a swift3 file which is a model.Xcode8 fails to compile this file and waits forever at compilation.If i exclude this file from my Project Target the project builds fine.It also builds fine with Xcode 7.There is no syntax issue with the file.Below is the code inside the file.

    import UIKit

    class KYCCompleteDetailRequestModel : NSObject {

    func createRequestDictionaryForAddKYC(_ completeDetails:KYCCompleteDetailModel) -> [String : AnyObject]?
{
    var parameter:[String : AnyObject]! =  [String : AnyObject]()

    let section1Details  = self.createDictionaryForSection1(completeDetails.identityDetailModel!)
    let section2Details  = self.createDictionaryForSection2(completeDetails.addressDetailModel)
    let section3Details  = self.createDictionaryForSection3(completeDetails.otherDetailModel)
    let section4Details  = self.createDictionaryForSection4(completeDetails.bankDetailModel)

    let section5Details   = self.createDictionaryForSection5(completeDetails.section5Model)

    let section6Details  = self.createDictionaryForSection6(completeDetails.section6Model)

    parameter["device_type"] = "I" as AnyObject?
    parameter["section1"] = section1Details as AnyObject?
    parameter["section2"] = section2Details as AnyObject?
    parameter["section3"] = section3Details as AnyObject?
    parameter["section4"] = section4Details as AnyObject?
    parameter["section5"] = section5Details as AnyObject?
    parameter["section6"] = section6Details as AnyObject?

    return parameter
}


//** Create dictionary for section 1
func createDictionaryForSection1(_ section1 :FSKYCIdentityDetailsModel) -> Dictionary<String,AnyObject>{

    var parameter =
    [
        "client_pan_number" :   section1.user_pan_number! ,
        "client_title"      :   section1.user_title! ,
        "client_fname"      :   section1.user_firstname! ,
        "client_mname"      :   section1.user_middlename! ,
        "client_lname"      :   section1.user_lastname! ,
        "client_phone"      :   section1.user_phone! ,
        "client_mobile"     :   section1.user_mobile! ,
        "client_email"      :   section1.user_email! ,
        "client_ucc"        :   section1.user_ucc! ,
        "client_email2"     :   section1.user_alternative_email!,
        "resiadd1"          :   section1.user_resident_addr_street1!,
        "resiadd2"          :   section1.user_resident_addr_street2!,
        "resiadd3"          :   section1.user_resident_addr_street3!,
        "rescity"           :   section1.user_resident_city!,
        "respin"            :   section1.user_resident_pincode!,
        "resstate"          :   section1.user_resident_state!,
        "rescountry"        :   section1.user_resident_country!,
        "father_fname"      :   section1.user_father_firstname!,
        "father_mname"      :   section1.user_father_middlename!,
        "father_lname"      :   section1.user_father_lastname!,
        "adharno"           :   section1.user_adhaar_number!,
        "dob"               :   section1.user_dob!,
        "status"            :   section1.user_status!,
        "gender"            :   section1.user_gender!,
        "nationality"       :   section1.user_nationality!,
        "maritalstatus"     :   section1.user_marital_status!,
        "userphoto_status"  :   section1.user_photo_checkbox!,
        "userphoto"         :   section1.user_photo!,
        "pancardphoto_status":  section1.user_pancard_photo_checkbox!,
        "pancard_photo"     :   section1.user_pancard_photo!

        ]




    return parameter as Dictionary<String, AnyObject>
}

//** Create dictionary for section 2
func createDictionaryForSection2(_ section2 :FSKYCAddressDetailsModel?) -> Dictionary<String,AnyObject>?{

    if section2 == nil{

        return nil

    }

    let parameter = [
        "peradd1"       : section2!.user_permanent_addr_street1! as AnyObject,
        "peradd2"       : section2!.user_permanent_addr_street2! as AnyObject,
        "peradd3"       : section2!.user_permanent_addr_street3! as AnyObject,
        "percity"       : section2!.user_permanent_city! as AnyObject,
        "perpin"        : section2!.user_permanent_pincode! as AnyObject,
        "perstate"      : section2!.user_permanent_state! as AnyObject,
        "percountry"    : section2!.user_permanent_country! as AnyObject,
        "addr_phone"    : section2!.user_addr_details_phone! as AnyObject,
        "addr_mobile"   : section2!.user_addr_details_mobile! as AnyObject,
        "addr_fax"      : section2!.user_addr_details_fax!,
        "addr_email"    : section2!.user_addr_details_email!,
        "addr_proof"    : section2!.user_addr_proof!,
        "perment_proof_status": section2!.user_addr_proof_file_checkbox!,
        "perment_proof" : section2!.user_addr_proof_file!
    ]

    return parameter as Dictionary<String,AnyObject>
}

//** Create dictionary for section 3
func createDictionaryForSection3(_ section3 :FSKYCOtherDetailsModel?) -> Dictionary<String,AnyObject>?{

    if section3 == nil{


        return nil
    }

    let parameter: [String : AnyObject] =
    [
        "income_range"      :section3!.user_income_range_per_annum! as AnyObject,
        "worth_date"        :section3!.user_net_worth_ondate! as AnyObject,
        "worth_amount"      :section3!.user_net_worth_ondate_rs! as AnyObject,
        "Occupation"        :section3!.user_occupation! as AnyObject,
        "pep"               :section3!.user_political_person! as AnyObject,
        "information"       :section3!.user_other_info! as AnyObject

        ]

    return parameter
}


//** Create dictionary for section 4
func createDictionaryForSection4(_ section4 :FSKYCBankDetailsModel?) -> Dictionary<String,AnyObject>?{

    if section4 == nil{

        return nil
    }

    let parameter =
    [
        "bankname"              :section4!.user_bank_name! as AnyObject,
        "bank_accno"            :section4!.user_bank_acc_number! as AnyObject,
        "bank_account_type"     :section4!.user_bank_acc_type! as AnyObject,
        "micr"                  :section4!.user_micr_number! as AnyObject,
        "ifsc"                  :section4!.user_ifsc_code! as AnyObject,
        "chequeno"              :section4!.user_cancelled_cheque_leaf_num! as AnyObject,
      "chequeimage_status"    :section4!.user_cancelled_cheque_leaf_file_checkbox! as AnyObject,
        "cancel_chequeimage"    :section4!.user_cancelled_cheque_leaf_file! as AnyObject,
        "huf_checkbox"          :section4!.partnershipfirm_checkbox! as AnyObject,
        "huf_name"              :section4!.partnershipfirm_username!,
        "huf_pan"               :section4!.partnershipfirm_pan_number!,
        "accnt_type"            :section4!.account_type!,
        "nri_foreign"           :section4!.nri_checkbox!,
        "appref_number"         :section4!.rib_apr_refer_number!,
        "appref_date"           :section4!.rib_app_refer_date!,
        "nominee_reg"           :section4!.reg_nominee_checkbox!,
        "nom_name"              :section4!.nominee_name!,
        "nom_dob"               :section4!.nominee_dob!,
        "nom_age"               :section4!.nominee_age!,
        "nom_address"           :section4!.nominee_address!,
        "nominee_minor"         :section4!.reg_minor_nominee_checkbox!,
        "minor_dob"             :section4!.minor_nominee_dob!,
        "minor_name"            :section4!.minor_nominee_name!,
        "guardian_name"         :section4!.guardian_name!,
        "guardian_rel"          :section4!.guardian_relation!,
        "guardian_city"         :section4!.guardian_city!,
        "guardian_pincode"      :section4!.guardian_pincode!,
        "guardian_state"        :section4!.guardian_state!,
        "guardian_country"      :section4!.guardian_country!,
        "guardian_teloff"       :section4!.guardian_office_number!,
        "guardian_telres"       :section4!.guardian_resi_number!,
        "guardian_fax"          :section4!.guardian_fax!,
        "guardian_mobile"       :section4!.guardian_mobile!,
        "guardian_email"        :section4!.guardian_email!
        ]

    return parameter as Dictionary<String, AnyObject>
}

//** Create dictionary for section 5
func createDictionaryForSection5(_ section5 :FSKYCSection5Model?) -> Dictionary<String,AnyObject>?{
    var section5 = section5

    if section5 == nil{
        let segmentDetails = FSKYCSection5Model()
        section5 =  segmentDetails
    }

    let parameter: [String : AnyObject] =
    [
        "istabneeded": section5!.istabNeeded! as AnyObject,
        "isdemateacc": section5!.isOpenDematAccountChecked! as AnyObject,
        "iscommodityacc":  section5!.isOpenCommodityAccountChecked! as AnyObject,
        "bankstatemnt_status"   :section5!.bankstatemnt_checkbox! as AnyObject,
        "bankstatemnt"          :section5!.bankstatemnt! as AnyObject,
        "pay_slip_status"       :section5!.payslip_checkbox! as AnyObject,
        "pay_slip"              :section5!.pay_slip! as AnyObject
        ]

    return parameter
}

//** Create dictionary for section 6
func createDictionaryForSection6(_ section6 :FSKYCSection6Model?) -> Dictionary<String,AnyObject>?{

    if section6 == nil{

        return nil
    }

    let parameter: [String : AnyObject] =
    [
        "terms&condition"   : section6!.agree_chk! as AnyObject,
        "payment_mode"      : section6!.payment_mode! as AnyObject

    ]

    return parameter
}

}

  • Perhaps you can locate the issue by commenting methods one by one until the issue is gone? – alexburtnik Oct 20 '16 at 19:39
  • The Swift compiler is known to have bugs that cause hangs like this. This blog post describes working around one of them: https://kerrick.wordpress.com/2016/09/13/how-i-escaped-a-swift-compiler-hang/ – Jim Matthews Oct 20 '16 at 19:50
  • See [**this**](https://spin.atomicobject.com/2016/04/26/swift-long-compile-time/) link. I not sure in at all...I see **too many literals** created for your parameters. I recommend you to not use too many literals. To find the issue: I suggest you delete all of them except for a parameter. Then compile again.if your code successfully compiles, then add more parameters. If not then dig deeper or just stop using too many literals – mfaani Oct 20 '16 at 20:24
  • Also see [**here**](http://stackoverflow.com/questions/25537614/why-is-swift-compile-time-so-slow) – mfaani Oct 20 '16 at 20:28
  • Thanks guys.I found the solution.Seems to be some issue with Swift.The solution is below. – Shoaib Mohammad Oct 21 '16 at 08:05

1 Answers1

0

You can try the below options:-

Option 1#

  • Open your Project Folder.
  • Find ProjectName.xcodeproj file.
  • Right-Click Copy and Paste to Safe Place.
  • Right-Click Show Package Contents.
  • Find project.xcworkspace file and delete that file.
  • Reopen Your Project and clean and Rebuild.

Option 2#

  • Open File / Preferences in Xcode
  • Click on Locations on the far right of the pop up window
  • Click on the little arrow icon next to "/Users/Mac/Library/Developer/Xcode/DerivedData"....it takes you to an Xcode folder that contains a DerivedData folder (that contains all of the derived data from your previous projects.)
  • DELETE the DerivedData folder

Option 3#

Killing the processes named 'swift' and then checking the error in xcode will give you the part of the code giving you trouble. There are some bugs in swift that needs to be circumvented.

Option 4#

If creating a dictionary like this

var dic1 = [

            "isDestination" : self.isDestination ?? false,
            "price" : self.price ?? ""

        ]

where self.price is of type Int and giving its fallback value as an empty string which screwed up the XCode compilation.

Option 5#

Instead of using dictionary like this:

var parameter =
    [
        "client_pan_number" :   section1.user_pan_number! ,
        "client_title"      :   section1.user_title! ,
        "client_fname"      :   section1.user_firstname! ,
        "client_mname"      :   section1.user_middlename! ,
        "client_lname"      :   section1.user_lastname! ,
        "client_phone"      :   section1.user_phone! ,
        "client_mobile"     :   section1.user_mobile! ,
        "client_email"      :   section1.user_email! ,
        "client_ucc"        :   section1.user_ucc! ,
        "client_email2"     :   section1.user_alternative_email!,
        "resiadd1"          :   section1.user_resident_addr_street1!,
        "resiadd2"          :   section1.user_resident_addr_street2!,
        "resiadd3"          :   section1.user_resident_addr_street3!,
        "rescity"           :   section1.user_resident_city!,
        "respin"            :   section1.user_resident_pincode!,
        "resstate"          :   section1.user_resident_state!,
        "rescountry"        :   section1.user_resident_country!,
        "father_fname"      :   section1.user_father_firstname!,
        "father_mname"      :   section1.user_father_middlename!,
        "father_lname"      :   section1.user_father_lastname!,
        "adharno"           :   section1.user_adhaar_number!,
        "dob"               :   section1.user_dob!,
        "status"            :   section1.user_status!,
        "gender"            :   section1.user_gender!,
        "nationality"       :   section1.user_nationality!,
        "maritalstatus"     :   section1.user_marital_status!,
        "userphoto_status"  :   section1.user_photo_checkbox!,
        "userphoto"         :   section1.user_photo!,
        "pancardphoto_status":  section1.user_pancard_photo_checkbox!,
        "pancard_photo"     :   section1.user_pancard_photo!

        ]

Use it like this:-

var parameter = ["client_pan_number" :   section1.user_pan_number!]
parameter["client_title"] = section1.user_title!
parameter["client_fname"] = section1.user_firstname!

so on for other key-value pairs in your parameter dictionary. This happened because of Xcode not able index long list dictionary literals.

Annie Gupta
  • 2,786
  • 15
  • 23
  • Thank you.You saved my day.There are actually two solutions.One is the way you defined to use the parameter["key"] = value.Another issue i found was that in a dictionary casting to AnyObject for some values and not for others also causes issues.Either you cast all of them or none of them. – Shoaib Mohammad Oct 21 '16 at 08:03