Xcode 8 waits at compilation for ever - ios

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

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.

Related

Can't log multiple items in Analytics Events E-commerce

I need to log items in carts but I can't figure out how to do that. In Swift it is not allowed to use append() function, so I tried to create a dictionary inside an array but with this method it does not work properly, I got an error in Firebase Debugview. Here is my codes: (Swift, iOS)
func logViewCart(items: [CartItem]){
var itemList : [[String : Any]] = []
for item in items{
var itemParams : [String : Any] = [
"item_id": item.id,
"item_name": item.product?.name,
"item_category": item.product.category,
"price": item.price
]
itemList.append(itemParams)
}
var itemTest : [String : Any] = [:]
for i in itemList {
itemTest[AnalyticsParameterItems] = [i]
}
Analytics.logEvent("view_cart", parameters: [
"items": [itemTest]
])
}
Thanks in advance
There's several ways for the error you are getting, you can start by typing the log message or the behaviour.
I'll go first for the basics on login an event, make sure you have this property set -FIRAnalyticsDebugEnabled on your scheme like so
With that should popUp like in 3~6 seconds on the debug viewer, then make sure you have the parameters right.
I found the solution. Instead of declaring a dictionary inside an array, declaring another array variable with [Any] type solve the problem.
var itemList : [Any] = []
for item in items{
let variantIndex = item.product?.attributes?[1].listValueLabel?.count ?? 1
var itemParams : [String : Any] = [
"item_id": item.itemID,
"item_name": item.product?.name
]
itemList.append(itemParams)
}
Analytics.logEvent("view_cart", parameters: [
AnalyticsParameterItems: itemList
])

how to add an object into a NSDictionary with respect to a key

I have NSDictionary, now I am trying to add an object in a particular key.How can I do that ? below is my code.
let businessPhoneDic = ["locationname" : "",
"area" : "",
"number" : "",
"type" : "",
];
let emailDic:NSMutableDictionary? = ["email" : "",];
let businessPhoneDic2 = ["locationname" : "hello",
"area" : "",
"phonenumber" : "",
"type" : "",
];
var mainDictionary = ["businessPhone" : businessPhoneDic as AnyObject,"email" : emailDic as AnyObject,
];
Now I want to add "businessPhoneDic2" into mainDictionary for key "businessPhone".How can I do that into Swift 3
By definition, you can't have two values mapped to the same key. The following code will replace the old key:
Swift 3
mainDictionary["businessPhone"] = businessPhoneDic2
Just use a new key if you need both values in your dictionary, or maybe store an array of dictionaries as values as such:
var mainDictionary : [String : [NSDictionary]] = ["businessPhone" : [businessPhoneDic]]
Then:
mainDictionary["businessPhone"]?.append(businessPhoneDic2)
First of all do not use MSMutable... collection types in Swift.
Use native Swift Dictionary
let emailDic = ["email" : ""]
Second of all annotate a dictionary with different types as [String:Any]
var mainDictionary : [String:Any] = ["businessPhone" : businessPhoneDic, "email" : emailDic]
If the value for key businessPhone is an array you can append the value. If it's a single dictionary you have to create an array.
This code considers both cases:
let businessPhone = mainDictionary["businessPhone"]
if var phone = businessPhone as? [[String:Any]] {
phone.append(businessPhoneDic2)
mainDictionary["businessPhone"] = phone
} else if let phone = businessPhone as? [String:Any] {
mainDictionary["businessPhone"] = [phone, businessPhoneDic2]
}
Try this :
mainDictionary["your key"] = businessPhoneDic2 as AnyObject // cast as per suggestions
Swift 3.x
// Initialize the Dictionary
var dict = ["name": "Foo", "surname": "Bar"]
// Add a new key with a value
dict["email"] = "foo.bar#email.com"
print(dict)

Slow compiling swift source file - Xcode 8 swift 3

I have just updated my project to Xcode 8 and Swift 3.
My problem is that my app is very very slow to compile a specific class, the following:
var dict: Dictionary<String, AnyObject> {
return [
"book_key": book_key as AnyObject,
"book_title": book_title as AnyObject,
"book_author": book_author as AnyObject,
"book_price": book_price as AnyObject,
"book_publisher" : book_publisher as AnyObject,
"page_count": page_count as AnyObject,
"book_description": book_description as AnyObject,
"book_urlImage" : book_urlImage as AnyObject,
"book_urlImage2": book_urlImage2 as AnyObject,
"user_key": user_key as AnyObject,
"user_name": user_name as AnyObject,
"user_tag_login" : user_tag_login as AnyObject,
"onGoingNegotiations" : onGoingNegotiations as AnyObject,
"other_user_key": other_user_key as AnyObject,
"other_tag_login": other_tag_login as AnyObject,
"book_condition": book_condition as AnyObject,
"timestamp": timestamp! as AnyObject
]
}
How can I resolve my problem? Thanks for the help.
The method is so slowly and so I have found the solution.
The timestamp NSNumber will be cast as String and so the method works perfectly again.
var dict: Dictionary<String, String> {
return [
"book_key": book_key,
"book_title": book_title,
"book_author": book_author,
"book_price": book_price,
"book_publisher" : book_publisher,
"page_count": page_count,
"book_description": book_description,
"book_urlImage" : book_urlImage,
"book_urlImage2": book_urlImage2,
"user_key": user_key,
"user_name": user_name,
"user_tag_login" : user_tag_login,
"onGoingNegotiations" : onGoingNegotiations,
"other_user_key": other_user_key,
"other_tag_login": other_tag_login,
"book_condition": book_condition,
"timestamp": timestamp
]
}
Thanks all for the help
Swift 3 like this:
if it is of several types
var dict: [String: Any] = [
"book_key": true,
"book_title": "Yannick",
"book_author": "Test",
"book_price": 123
]
Or if you return lot of String like this
var dict: [String: String] = [
"book_key": "true",
"book_author": "Yannick",
"book_price": "123",
"book_publisher": "Yannick",
"page_count": "123"
]

How to send array of dictionarys in swift by using alamafire(Post method)

I am running with an issue where my server is expecting an array of dictionarys from the app side. Please suggest where I'm going wrong here, code below
{
let param : [String : AnyObject] =
["trf_id" : Constant.constantVariables.trfID,
"mode" : Constant.modeValues.createMode,
"to_city" : Constant.constantVariables.to_city,
"from_city" : Constant.constantVariables.from_city,
"description" : Constant.constantVariables.descrption,
"request_type" : Constant.constantVariables.request_type,
"to_date" : Constant.constantVariables.to_date!,
"from_date" : Constant.constantVariables.from_date!,
"travel_configs" : ["Config_id" : "9","values" : "train",
"Config_id" : "10","values" : "bus"]]
print(param)
}
Where travel_configs is array of dictionaries
I have to send it like this because of server exceptions
trf_id:37
mode:1
request_type:0
from_city:sdfsd
to_city:qws
from_date:2016-08-17
to_date:2016-08-26
description:sdfsdf
travel_configs:[
{"config_id":"11","values":"1"}
,{"config_id":"2","values":"Flight"}]
Finally i got answer after 3 days of struggling
just send your array of dictionary into this
class func JSONStringify(value: AnyObject,prettyPrinted:Bool = false) -> String{
let options = prettyPrinted ? NSJSONWritingOptions.PrettyPrinted : NSJSONWritingOptions(rawValue: 0)
if NSJSONSerialization.isValidJSONObject(value) {
do{
let data = try NSJSONSerialization.dataWithJSONObject(value, options: options)
if let string = NSString(data: data, encoding: NSUTF8StringEncoding) {
return string as String
}
}catch {
print("error")
//Access error here
}
}
return ""
}
Hope this will help some one else Thank you..
First, it might come from the capital "C" instead of "c" in "config_id" ?
Secondary, you are actually missing [], your code should look like this :
let param : [String : AnyObject] =
["trf_id" : Constant.constantVariables.trfID,
"mode" : Constant.modeValues.createMode,
"to_city" : Constant.constantVariables.to_city,
"from_city" : Constant.constantVariables.from_city,
"description" : Constant.constantVariables.descrption,
"request_type" : Constant.constantVariables.request_type,
"to_date" : Constant.constantVariables.to_date!,
"from_date" : Constant.constantVariables.from_date!,
"travel_configs" : [["Config_id" : "9","values" : "train",
"Config_id" : "10","values" : "bus"]]]
Why?
Because your server is expecting an array of dictionary, and you are sending only a dictionary ;)

Using NSPredicate to filter an NSArray of objects based on a property which is an NSDictionary

I have an NSArray of objects with the following properties
#objc class Dummy: NSObject {
let propertyOne: Int
let propertyTwo: Int
let propertyThree: NSDictionary
}
In propertyThree, it will have certain key values pairs such as
keyOne => valueOne
keyTwo => valueTwo
keyThree => valueThree
I want to filter through my NSArray of Dummy Objects based off of keyOne of the NSDictionary that is a property of the Dummy object.
How would I go about doing this? I looked through:
Using NSPredicate to filter an NSArray based on NSDictionary keys
Filtering NSArray of NSDictionary objects using NSPredicate
But it doesn't seem applicable.
You don't provide any code about you're using NSPredicate, so I wrote a simple example. Maybe this will help you.
#objc class Dummy: NSObject {
let propertyOne: Int = 1
let propertyTwo: Int = 1
let propertyThree: NSDictionary
init(dict: NSDictionary) {
propertyThree = dict
super.init()
}
}
let arr: NSArray = [
Dummy(dict: ["keyOne" : "one"]),
Dummy(dict: ["keyOne" : "two"]),
Dummy(dict: ["keyOne" : "three"]),
Dummy(dict: ["keyOne" : "one"]),
Dummy(dict: ["keyOne" : "five"])
]
let predicate = NSPredicate(format: "SELF.propertyThree.keyOne == 'one'")
let results = arr.filteredArrayUsingPredicate(predicate)
print(results)
In Objective-C:
[array filteredArrayUsingPredicate:[NSPredicate
predicateWithFormat:#"propertyThree.keyOne = %#", value]];
In Swift you could use the adaptation of that but, as Kametrixom suggests, it'd be more normal to use filter and a closure; that's the mechanism that removes the dynamic key-value coding step.
Here you go, using real Swift:
class Dummy {
let propertyOne: Int = 1
let dict: [String : String]
init(dict: [String : String]) {
self.dict = dict
}
}
let arr = [
Dummy(dict: ["keyOne" : "one"]),
Dummy(dict: ["keyOne" : "two"]),
Dummy(dict: ["keyOne" : "three"]),
Dummy(dict: ["keyOne" : "one"]),
Dummy(dict: ["keyOne" : "five"])
]
let result = arr.filter { $0.dict["keyOne"] == "one" }
Few notes:
You don't need your classes to inherit from NSObject in Swift, if they do though, the #objc attribute is implicitly applied anyways
Use [NSObject : AnyObject] instead of NSDictionary as it's equivalent. I used [String : String] here because that's obviously what it is
Using the filter method, you can filter your array in a typesafe way, also it's faster

Resources