3
Following works fine:-   

  let parameters:[String:AnyObject] = [
            "WebKey": API.WebKey.value,
            "UID":NSUserDefaults.standardUserDefaults().integerForKey("UserId"),
            "TotalCount":myData!.count,
            "Qty":  (myData!.map {
                String($0.quantity)
                }).joinWithSeparator(",")
            ]

However, Following gives an issue:

     let parameters:[String:AnyObject] = [
        "WebKey": API.WebKey.value,
        "UID":NSUserDefaults.standardUserDefaults().integerForKey("UserId"),
        "TotalCount":myData!.count,
        "Qty":  (myData!.map {
            String($0.quantity)
            }).joinWithSeparator(","),
        "Price":  (myData!.map {
            String($0.price)
            }).joinWithSeparator(","),
        "Code":  (myData!.map {
            String($0.code)
            }).joinWithSeparator(","),
        "ReqTime":NSDate().timeFormat()
        ]

Issue : Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

Can someone please explain why compiler is giving this issue. Also suggest a elegant way to accomplish the same implementation without the same issue. (As same logical implementation is repeated 3 times instead of one )

Meet
  • 1,196
  • 12
  • 26
  • It's type inferring error, you may help by setting types in `map`/`flatMap`. like `map { (a: T) -> U in … }`, where `T` and `U` are your types. – user28434'mstep Oct 18 '16 at 11:22
  • 1
    Have you tried creating the Qty, Price and Code values in other variables and use those in the array initialization? – xpereta Oct 18 '16 at 11:25
  • 1
    @xpereta it works if i put Qty, price and code values in other variables but i don't understand why works for 1 but doesn't work for 3? Also i wanted a more readable way to solve the issue rather than assigning variables even when there is no need for it. – Meet Oct 18 '16 at 11:31
  • 2
    Please, have a look at this question: http://stackoverflow.com/questions/29707622/bizarre-swift-compiler-error-expression-too-complex-on-a-string-concatenation?rq=1 It may be a duplicate – xpereta Oct 18 '16 at 12:53

0 Answers0