manuege / alamofirecoredata Goto Github PK
View Code? Open in Web Editor NEWSerialize responses from Alamofire and insert the responses in CoreData using Groot
License: MIT License
Serialize responses from Alamofire and insert the responses in CoreData using Groot
License: MIT License
Hi,
I'm trying to use this great pod but got an issue. Every value are nil;
Here my class News
extension News {
@nonobjc public class func fetchRequest() -> NSFetchRequest<News> {
return NSFetchRequest<News>(entityName: "News")
}
@NSManaged public var content: String?
@NSManaged public var created_at: NSDate?
@NSManaged public var date_pub_beg: NSDate?
@NSManaged public var date_pub_end: NSDate?
@NSManaged public var id: Int16
@NSManaged public var results: Bool
@NSManaged public var rotation: Bool
@NSManaged public var summary: String?
@NSManaged public var title: String?
@NSManaged public var updated_at: NSDate?
}
In my swift file I do
private var appDelegate = UIApplication.shared.delegate as! AppDelegate
private let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
func getNews(url: String, completion: @escaping (Bool) -> Void) {
Alamofire.request(url).responseInsert(context: context, type: Many<News>.self) { response in
switch response.result {
case let .success(news):
print (news)
completion(true)
case .failure:
// handle error
completion(false)
print("Erreur")
}
}
}
Calling my func print this in console log
[<News: 0x60800009fef0> (entity: News; id: 0x60800003c880 <x-coredata:///News/tBB28D896-033A-4084-807A-6A31993B8F2F2> ; data: {
content = nil;
"created_at" = nil;
"date_pub_beg" = nil;
"date_pub_end" = nil;
id = 0;
results = nil;
rotation = nil;
summary = nil;
title = nil;
"updated_at" = nil;
}), <News: 0x608000282170> (entity: News; id: 0x60800003ba00 <x-coredata:///News/tBB28D896-033A-4084-807A-6A31993B8F2F3> ; data: {
content = nil;
"created_at" = nil;
"date_pub_beg" = nil;
"date_pub_end" = nil;
id = 0;
results = nil;
rotation = nil;
summary = nil;
title = nil;
"updated_at" = nil;
})]
Here what my API sent
[
{
id: 1,
title: "Test d'article",
date_pub_beg: "2017-09-05",
date_pub_end: "2017-09-06",
summary: "Ceci est un test, AH BON ?",
content: "<div><strong>Petit test pour voir !</strong></div><ul><li>test 1</li><li>test 2</li><li>test 3</li></ul><div><br><a href="/attachments/6445bed34e1b29499ed49d7d6b84ab87c145b124/store/529632a6d060f7eb51c12ee5f7e66f8e02bd9b76092d50179f5c8f99537e/stephane.jpg" data-trix-attachment="{"contentType":"image/jpeg","filename":"stephane.jpg","filesize":38987,"height":308,"href":"/attachments/6445bed34e1b29499ed49d7d6b84ab87c145b124/store/529632a6d060f7eb51c12ee5f7e66f8e02bd9b76092d50179f5c8f99537e/stephane.jpg","image_id":"529632a6d060f7eb51c12ee5f7e66f8e02bd9b76092d50179f5c8f99537e","url":"/attachments/6445bed34e1b29499ed49d7d6b84ab87c145b124/store/529632a6d060f7eb51c12ee5f7e66f8e02bd9b76092d50179f5c8f99537e/stephane.jpg","width":308}" data-trix-content-type="image/jpeg"><figure class="attachment attachment--preview attachment--jpg"><img src="/attachments/6445bed34e1b29499ed49d7d6b84ab87c145b124/store/529632a6d060f7eb51c12ee5f7e66f8e02bd9b76092d50179f5c8f99537e/stephane.jpg" width="308" height="308"><figcaption class="attachment__caption"><span class="attachment__name">stephane.jpg</span> <span class="attachment__size">38.07 KB</span></figcaption></figure></a></div>",
created_at: "2017-09-05T07:43:18.011Z",
updated_at: "2017-09-07T02:50:35.414Z",
results: false,
rotation: false
},
{
id: 2,
title: "Victoire de la France",
date_pub_beg: "2017-11-27",
date_pub_end: "2017-12-31",
summary: "La France remporte la Coupe Davis.",
content: "<div>Au terme du dernier match, la France remporte la <strong>Coupe Davis.</strong></div>",
created_at: "2017-11-27T14:18:07.527Z",
updated_at: "2017-11-27T14:18:07.527Z",
results: false,
rotation: false
}
]
Everything seems to be ok, don't understand why those nil values.
Any idea ?
Thanks a lot
Hi there,
first of all, good repository, we are using AlamofireCoreData for a while since last year, and we are really happy with that. Thanks for sharing this.
I'm having an issue compiling iOS 12 with Xcode 10, the folloging issue appears:
//
// Operator.swift
// Alamofire+CoreData
...
public func <- <T: Insertable>( left: inout T!, right: MapValue?) {
Do you want me to send a PR on this? or you guys are working right now to fix the issue?
Thanks again,
Javier.
I am trying to create one function for different types and requests.
In your call a Many.self when ist's an Array of objects.
How can i realism to get the Object, so the NSManagedObject out of the variables?
So I end up with something like:
Alamofire.request(url)
.responseInsert(context: context, type: Many<VARIABLE>.self) { response in
switch response.result {
case let .success(user):
// The user object is already inserted in your context!
case .failure:
// handle error
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.