Source code available at https://github.com/Zoosk/ZSFoundation.
Compiled framework is available on that page via the Downloads link.
See LICENSE for licensing information
This library is intended to be a collection of sample code that can be used in its entirely, or piecewise. Components should be usable on an individual basis, given that any inclusions are also included.
###ZSImageCache This class is useful if your application requires significant numbers of images, fetched from the network. It maintains a disk-backed cache of those images, and also keeps a fixed number in memory on an least recently used (LRU) basis to alleviate thrashing. These options are configurable.
###ZSLRUQueueCache This class is useful for maintaining a disk-backed cache of NSCoding compliant objects. These items will be ejected from memory and disk based on user-specified constraints, on a least recently used (LRU) basis. This class can be EXPENSIVE, and should be used only in situations where high performance is not necessary.
###ZSBool, ZSFloat, ZSInteger, ZSUInteger These classes warrant some explanation. For one, Cocoa already has BOOL, CGFloat, NSInteger and NSUInteger. Why not just use those? There are a few problems.
-
Native data types are not first-class citizens in Objective C. They can't be stored in Object-oriented data structures (NSArray, NSSet, etc).
-
nil cannot be represented. The convention in Cocoa for representing "no value" for native data types is to use the defined value NSNotFound. This is defined to be the same as NSIntegerMax. This is technically incorrect, since NSIntegerMax is a valid value for most situations where it is used to represent a "nil" or "null" value. It can also lead to problems if other programmers are not aware of the convention, and echo values out to the UI.
-
NSNumber is not statically typed. The Cocoa frameworks offer a stop-gap solution by providing NSNumber. The problem is that NSNumber is not statically typed, so there is no clear indication to the compiler, or to users of your code what the intended type is. There are a wide variety of issues with this. For example, comparing an NSNumber that wraps an integer with an NSNumber that wraps a float may have unexpected behavior. Other developers will have to rely on your documentation to avoid this pitfall.
So, the solution we've arrived at in ZSFoundation is to use statically typed wrappers for the more common native data types, in places where it makes sense. This creates a slight memory overhead, which should be taken into account in high-performance scenarios, or when system constraints are of concern.
NOTE - ZSFloat has some unique issues. It is provided in order to offer some representative for floating point numbers. Please read the source code's associated commentary and warnings about the pitfalls of comparing floating point numbers with methods like compare: and isEqual:.
###ZSLowMemoryPool The reason for creating this class, is that I often found myself creating little static objects like lookup dictionaries. I would create these lazily, but I wanted to keep them around for performance reasons.
Often, when you use these types of little helper methods, you use them in bursts. Maybe a dozen times at once and then not again for a while. Each successive call may not know if it is the last one though, so it would be a bad idea to release these static collections.
By using this "low memory pool", you can register pointers to pointers and, when a low memory condition arises, it will go through and release all those objects, and set their pointers to nil. This is also handy in that it saves every class you write from having to set up to listen for this notification. It can just register the appropriate pointers with the pool and forget about it.
ZSFoundation used to have scripts to build a Framework, but I find that just importing the project as a dependency makes maintenance and debugging easier. So as of now, I recommend that you:
- Import this project as a project dependency.
- Add it to the Target Dependency build phase of your main project.
- Add libZSFoundation.a to the Link Binary With Libraries build phase of your main project.
- Import ZSFoundation.h where needed, or individual classes on demand.
-
ZSFoundation. Builds the project into a static library (libZSFoundation.a).
-
ZSFoundationUnitTests. Runs the unit test suite for the project.