Posts

Showing posts from December, 2017

Swift: Codable

Image
From  https://hackernoon.com/everything-about-codable-in-swift-4-97d0e18a2999 As we are all aware, to support encoding and decoding of instances in iOS, a class must adopt the  NSCoding  protocol and implement its methods: init(coder:) β€” Returns an object initialized from data in a given unarchiver. encode(with:) β€” Encodes the receiver using a given archiver. Example: Code Snippet β€” 1 init(coder:)  and  encode(with:)  must contain the code for each property that needs to be encoded or decoded. 😲 Well, it seems that you have to write so much of redundant code πŸ˜– only with the property name changes.  Copy Paste..Copy Paste..!!!πŸ˜•πŸ˜΄ But why should I do that? πŸ™‡β€β™€οΈ If the property names are same as the key names and I don’t have any specific requirements, why don’t  NSCoding  handle everything at its own end? πŸ€·β€β™€οΈ Why do I have to write so much code? Noooooo..!!! 😼 OMG..!!! Another problem πŸ€¦β€β™€οΈ. It doesn’t even ...

Python: pickle and copyreg

multiprocessing must pickle things to sling them among processes, and bound methods are not picklable. The workaround (whether you consider it "easy" or not;-) is to add the infrastructure to your program to allow such methods to be pickled, registering it with the  copy_reg standard library method. Following is from the python doc The  copyreg  module offers a way to define functions used while pickling specific objects. The  pickle  and  copy  modules use those functions when pickling/copying those objects. The module provides configuration information about object constructors which are not classes. Such constructors may be factory functions or class instances. copyreg . constructor ( object ) Declares  object  to be a valid constructor. If  object  is not callable (and hence not valid as a constructor), raises  TypeError . copyreg . pickle ( type ,  function ,  constructor=None ) Declares that  ...