2016-09-18 4 views
1

Ich habe gerade mein Projekt auf Xcode 8 und Swift 3 aktualisiert. Mein Problem ist, dass mein app sehr, sehr langsam ist, eine bestimmte Klasse, die folgenden kompilieren:Langsame Kompilierung der Swift-Quelldatei - Xcode 8 swift 3

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

Wie kann ich mein Problem lösen? Danke für die Hilfe.

+0

Konvertieren Sie Ihr Wörterbuch in eine Klasse (Objekt) könnte einfacher sein, da Sie all diese Eigenschaften haben (book_key, book_title ... etc) –

+0

verwenden 'ObjectMapper': nur ein Vorschlag –

+0

Danke @PeterLee, Es ist besser. Mit Xcode 7 war es schneller als jetzt – Carlo

Antwort

1

Die Methode ist so langsam und so habe ich die Lösung gefunden. Die timestamp NSNummer wird als String gecastet und so funktioniert die Methode wieder einwandfrei.

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

Dank alle für die Hilfe

0

Swift 3 wie folgt aus:

wenn es von mehreren Arten

var dict: [String: Any] = [ 
       "book_key": true, 
       "book_title": "Yannick", 
       "book_author": "Test", 
       "book_price": 123 
      ] 

ist oder wenn Sie viel String zurückgeben wie diese

var dict: [String: String] = [ 
       "book_key":  "true", 
       "book_author": "Yannick", 
       "book_price":  "123", 
       "book_publisher": "Yannick", 
       "page_count":  "123" 
      ] 
Verwandte Themen