Code Monkey home page Code Monkey logo

alamofirecoredata's Issues

nil; value

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="{&quot;contentType&quot;:&quot;image/jpeg&quot;,&quot;filename&quot;:&quot;stephane.jpg&quot;,&quot;filesize&quot;:38987,&quot;height&quot;:308,&quot;href&quot;:&quot;/attachments/6445bed34e1b29499ed49d7d6b84ab87c145b124/store/529632a6d060f7eb51c12ee5f7e66f8e02bd9b76092d50179f5c8f99537e/stephane.jpg&quot;,&quot;image_id&quot;:&quot;529632a6d060f7eb51c12ee5f7e66f8e02bd9b76092d50179f5c8f99537e&quot;,&quot;url&quot;:&quot;/attachments/6445bed34e1b29499ed49d7d6b84ab87c145b124/store/529632a6d060f7eb51c12ee5f7e66f8e02bd9b76092d50179f5c8f99537e/stephane.jpg&quot;,&quot;width&quot;: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

Xcode 10 + iOS 12

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:

  • Invalid redeclaration of '<-'
//
//  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.

trying to refactor the request method

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.