2016-04-14 6 views
0

私は迅速で、いくつかのCoreDataをAzureにアップロードしようとするのが新しいです。私は、アプリケーションのCoreData部分が正しく動作していること、そして紺色のアップロードが正しく機能していることを知っています。私はそれらを個別にテストしました。私はフェッチされたイベントをAzureに送るのに苦労している。私は強制ダウンキャスティングに関連していると思う。ここでフェッチされたCoreDataをAzure Mobile Servicesにアップロードする方法を教えてください。

は私のコードです:

@IBAction func sync(sender: UIButton) { 
    let client = AppDelegate().client //reference to the Azure client 
    let itemTable:MSTable = client.tableWithName("Events")//create a local Azure table to use in upload 

    let fetchRequest = NSFetchRequest(entityName: "Events")//create a new fetch request that fetches all information in Events 
    do { 
     let fetchedEvents = try self.managedObjectContext.executeFetchRequest(fetchRequest) as! [NSManagedObject] 
     let itemToInsert:NSDictionary = ["buttonColor": fetchedEvents.buttonColor, "eventTime": fetchedEvents.eventTime] //need to insert the buttonColor and eventTime atributes from the fetched CoreData 
     itemTable.insert(itemToInsert as! [NSObject : AnyObject], //send itemToInsert to azure 
         completion: { 
          insertedItem, error in 
          if (error != nil){ 
           print("error: \(error)") 
          } 
          else{ 
           print("Success!") 
          } 
      } 
     ) 
    } catch let error as NSError { 
     print("Could not fetch \(error), \(error.userInfo)") 
    } 
} 

私はNSManagedObject以外のものとしてfetchedEventsをキャストダウンべきか?

答えて

0

モバイルデータでコアデータを使用する場合は、コアデータを直接使用するオフライン同期機能を検討する必要があります。 Get Started with Offline Data Sync in Mobile Servicesを参照してください。

そうしないと、辞書とコアデータオブジェクトの間で変換が必要になります。 MSTable.insertの場合は、NSManagedObjectではなくNSDictionaryを渡す必要があります。 https://azure.microsoft.com/en-us/documentation/articles/mobile-services-ios-how-to-use-client-library/#insertingを参照してください。

関連する問題