FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Is OCMapper thread-safe? · Issue #48 · aryaxt/OCMapper · GitHub

Repository navigation

Is OCMapper thread-safe? #48

Open
Open

Description

Hi,

I've been using OCMapper for several weeks now and I'm a big fan! While there's a few things I'd love to see improved - in general it was the best JSON <-> Object library I could find for iOS.

However, every once and a while I noticed my app is crashing and the stack trace points inside of OCMapper. It's very difficult to reproduce which makes the crash even worse in my mind.

But, my theory is that OCMapper isn't thread-safe. We have a thread pool handling responses from the server and OCMapper processes everything as a singleton.

Is this a known limitation? I can handle the results in a single thread to be safe as well but wanted to know if it's supposed to be thread-safe and the issue is elsewhere in my code.

@interface ObjectMapper()
@property (nonatomic, strong) NSMutableArray *commonDateFormaters;
@property (nonatomic, strong) NSMutableDictionary *mappedClassNames;
@property (nonatomic, strong) NSMutableDictionary *mappedPropertyNames;
@property (nonatomic, strong) NSMutableArray *instanceProviders;
@end

Activity

  1. aryaxt commented on Apr 19, 2016

    Owner

    Hi @jpage4500
    I've never had any issues with threading. I'm using OCMapper in my current app that has 100k sessions, millions of HTTP requests a day. OCMapper is always running on the global queue. I'll write some tests and try to map object on as many threads as possible to be sure, but I doubt that threading is your issue.

    Do you happen to have the crash logs?

  2. aryaxt commented on Apr 19, 2016

    Owner

    I have something similar to this

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
       guard let json = json else { 
          dispatch_async(dispatch_get_main_queue()) {
               completeWithError(NetworkErrorType.UnexpectedEmptyResponse) 
          }
          return
       }
    
       let convertedObject = ObjectMapper.sharedInstance().objectFromSource(json, toInstanceOfClass: type) as? T
    
       dispatch_async(dispatch_get_main_queue()) {
            completion(SingleNetworkResponse<T>(data: convertedObject, response: response))
       }
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL