Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Edwin Vermeer
    @evermeer
    So it depends on your preference how you like to use Alamofire when posting data. You could use any of the objects .to* methods. If you don’t want all of your properties in the json data, then use the propertyMapping function to exclude properties.
    Bogdan Geleta
    @eXhausted
    This message was deleted
    Hi, I have an issue with EVManagedObject. When I tried to call toJsonString or toDictionary it always returns {} for me. I've tested on testCoreDataSmokeTest method. Just added print(person. toJsonString()) at CoreDataTests.swift:58 and it returns {}
    Edwin Vermeer
    @evermeer
    @eXhausted Hmm…. Aperently reflection does not work on a NSManagedOBject. The following line of code returns 0
    Mirror(reflecting: obj).children.count
    Which means that using the Swift Mirror function for reflecting an object structure returns zero elements.
    Since that’s the base for getting information, this means that with coredata you could create an instance, but you can’t create json objects from it.
    It looks like i have to overwrite the .toJsonData and .toJsonString and use something like this:
    NSArray keys = [[[myObject entity] attributesByName] allKeys];
    NSDictionary
    dict = [myObject dictionaryWithValuesForKeys:keys];
    but then of course the swift version :)
    Edwin Vermeer
    @evermeer
    So the Swift version will be:
        obj.dictionaryWithValues(forKeys: obj.entity.attributesByName.keys)
    Bogdan Geleta
    @eXhausted
    @evermeer got, thx
    @evermeer just FYI, attributesByName.keys doesn't return [String]
    Edwin Vermeer
    @evermeer
    @eXhausted I see, yesterday I added code for this to EVManagedObject. Now it all works like it should (I think/hope) It’s now based on this function that I added:
    open func toDictionary(_ conversionOptions: ConversionOptions = .DefaultSerialize) -> NSDictionary {
        let keys = Array(self.entity.attributesByName.keys)
        return self.dictionaryWithValues(forKeys: keys) as NSDictionary
    }
    I do have to fix one (unrelated) unittest before I can push it to GitHub.
    Edwin Vermeer
    @evermeer
    @eXhausted I have pushed the EVManagedObject fix to GitHub as version 4.17.0
    Enrique Choynowski Melgarejo
    @Enriquecm
    Hello @evermeer

    Is it possible to have more than one Date Formatter? because my service has two different date formatting.

    1 - yyyy-MM-dd'T'HH:mm:ss.SSSZ
    2 - yyyy-MM-dd'T'HH:mm:ssZ

    And I can't handle this with just one DateFormatter.

    Edwin Vermeer
    @evermeer
    @Enriquecm At this moment you can only do that by using a propertyConverter for one of those dates. It was already on my mind to think of a more flexible solution for this but since there was no demand for it yet it’s still low on my todo list. I can think of one reaslonably easy fix for tis and that is that you could specify per object if you want to overrule the default date formatter. Or do you have multiple date formats in one object? Anyway… For now you should implement a propertyConverter like this:
    override open func propertyConverters() -> [(key: String, decodeConverter: ((Any?) -> ()), encodeConverter: (() -> Any?))] {
        return [( // We want a custom converter for the field isGreat
            key: "isGreat",
            // isGreat will be true if the json says 'Sure'
            decodeConverter: { self.isGreat = ($0 as? String == "Sure") },
            // The json will say 'Sure  if isGreat is true, otherwise it will say 'Nah'
            encodeConverter: { return self.isGreat ? "Sure": "Nah"})]
    }
    But then of course while converting to and from a date instead of a boolean like this sample.
    Enrique Choynowski Melgarejo
    @Enriquecm
    @evermeer I got it.! I'll keep an eye on your repository. Anyway, thank you very much for the reply. I believe the propertyConverters will work.
    Guilherme Araújo
    @guilhermearaujo
    Hi, how can I use EVNetworkingObject when installing EVReflection via Carthage?
    I'm including the EVReflection.framework, but the compiler says Use of undeclared type 'EVNetworkingObject'
    Edwin Vermeer
    @evermeer
    @guilhermearaujo EVNetworkingObject is part of the Alamofire subspecies. Currenly there is no Carthage framework configured for that. There is only a Carthage framework for the base EVReflection.
    parkesb
    @parkesb
    Hi @everemeer, I just upgraded to swift 4 after a break and now no data gets loaded (was working in swift 3). I'm getting a "The class is not key coding compliant for the key". Keys are all basic types e.g. String. Source data is a JSON Dict. Any ideas what I'm doing wrong?
    parkesb
    @parkesb
    Found the issue @objcmembers was commented out in the cocoa pod version
    Edwin Vermeer
    @evermeer
    @guilhermearaujo I was unable to push the Swift4 version which is now on master to cocoapods because of the dependency with Moya which is still in beta for the Swift 4 version. So when you do a pod update you will get the version without @objcmembers. The moment Moya 10 is release I will push the master branch to cocoa pods.
    parkesb
    @parkesb
    Got it and thanks for the response - it's all working now.
    Hardik
    @hardikdevios
    @evermeer Hey Mate i can see that you have released the SWIFT 4 version but cocoapods still pointing to 4.19.1
    can you please please update that ?
    Edwin Vermeer 
    @evermeer_twitter
    @hardikdevios There is a problem publishing it to cocoapods because of a dependancy with Moya which does not have published its swift 4 version. If you add the gitpath in your podfile then it will be forced to the 5.0 version.
    pod 'EVReflection', :git => 'https://github.com/evermeer/EVReflection.git'
    Hardik
    @hardikdevios
    @evermeer yes i am already doing that and watching this repo since SWIFT 4 release, Regarding Moya i think they have updated with SWIFT 4 https://github.com/Moya/Moya/releases
    Edwin Vermeer 
    @evermeer_twitter
    Ah, thanks! Will have a look at it later today
    King Calculator
    @KingCalculator_twitter
    @evermeer_twitter does evreflection supports generic types? Im doing something like class SomeClass<T: EVObject> { init() { let t = T(json: somejson) }. the EVObject() init is invoked, but the values that the class behind the T generic are not valid... any idea why?
    King Calculator
    @KingCalculator_twitter
    when i print the object it prints fine, maybe it's an xcode issue
    Edwin Vermeer
    @evermeer
    @KingCalculator_twitter Yes, there is support for generics. You do have to implement 2 functions to make it work. You can find a sample in these unit tests: https://github.com/evermeer/EVReflection/blob/ec78dbae21aa30794231c516bb74447bc04d0cfe/UnitTests/EVReflectionTests/EVReflectionWorkaroundSwiftGenericsTests.swift#L123
    King Calculator
    @KingCalculator_twitter
    thanks
    King Calculator
    @KingCalculator_twitter
    @evermeer what about json data that has an array as it's root object? since array does not inherits EVObject/EVNetworkingObject it can not be used with DataResponse<T> ....
    King Calculator
    @KingCalculator_twitter
    nm, found requestArray
    amgadserry
    @amgadserry
    hey guys how can i achieve 1 to many relation with class of the same type in EVManagedObject ex.
    class Person: EVManagedObject {
    @NSManaged var name: String?
    @NSManaged var friends: [Person]?
    }
    Edwin Vermeer
    @evermeer
    @KingCalculator_twitter When the root is an array, you can just instantiate an array like this: [ MyGenericObject < NSString > ] (json : json )
    And when using Alamofire you can use the .responseArray instead of the .responseObject function
    Edwin Vermeer
    @evermeer
    @amgadserry The problem there is that EVReflection is not able to pass on the context from the Person object to the Person objects in it’s friends properties. You have have to do that yourself by implementing the ‘setvalue forKey’ function for the friends key and then create a new array of Person objects with the right context and set that to the friends property.
    amgadserry
    @amgadserry
    @evermeer well the problem is that EVManagedObject does not provide empty constructor by default to create Person instances with it needs a context and if i passed the context of my coredata instance then it will add the friends array as siblings to the original entities as well as children so how can i deal with that can u provide some example code
    Art-Cube
    @Art-Cube
    Hi, I've got a number of classes which are EVObjects and are populated via downloaded json data. I've been asked to persist the objects in Core Data. Is there a simple way to do so, or do I need to create the NSManagedObjectModel either vis Xcode or by code? I'm hoping there is some way to dynamically create the model from the objects themselves.
    Mike Manzo
    @MikeManzo
    Greetings … I am having (what I think is) a memory leak issue with class inheriting from EVObject. When I decode from serialization, I am getting a memoy leak indicator here:
    if !(value is NSNull) {
    var setValue: AnyObject? = value as AnyObject?
    try anyObject.validateValue(&setValue, forKey: key)
    anyObject.setValue(setValue, forKey: key)
    }