-
Notifications
You must be signed in to change notification settings - Fork 0
Objective-C Classes for Haskell Programmers (with primary focus on the iPhone SDK)
License
rocketnik/objc4hs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This project is a collection of Objective-C Classes that come in handy for Haskell programmers that are interested in developing with the iPhone SDK ... and other programmers with a functional background. For procedural programmers they should also be an enrichment as you can save writing unnecessary code. If you like the ideas here please have a look at a functional language as doing so will shurely enlighten your view on programming. Status of the project: Some functions were written (with care) but not tested. While this does usually work good for Haskell it often fails for less abstract languages like Objective-C. Be warned and make shure your code works as expected. A last word on this project: You are welcome to get involved or give feedback of any kind. You can use the mail form at http://n-mayr.de/ . Put "objc4hs" in the "Betreff" (=Subject) for extra speedy responses. Lets dive right in. The Class extenstions 'OHMapZipCategories' contains some friends of the "makeObjectsPerformSelector:"-Method that Apple failed to put in. People already familiar with the 'map', 'zip' and 'zipWith' functions will know what these Methods do and will find the right type for their needs. You should be able to write much less loops by hand. But beware that the compiler does not check if a selector can be performed by any object. If you misspell a name you will encounter the problem at runtime. Fortunately this kind of error is easy to fix as the debug message upon crash will tell you exactly where the problem lies. Here are some examples: (1) NSArray *results = [someArray mapSel:@selector(someSelector)]; (2) NSArray *results = [someArray mapSel:@selector(someSelector) obj:someObject]; (3) NSArray *results = [someObject mapSel:@selector(someSelector) arr:someArray; (4) NSArray *zippedArrays = [someArray zip:anotherArray]; (5) NSArray *zippedArrays = [someArray zipWith:@selector(someSelector arr:anotherArray]; Method (1) does indeed differ form "makeObjectsPerformSelector:". It does not only perform the selector it also collects the results and returns it as an (NSArray *). (2) As you might have guessed, there is also a correspondent for "makeObjectsPerformSelector:withObjects:". There are also methods (3) that work on one object and performs one of its selectors with an array of objects. (4) "zip:" will create an OHTupel which is just an Object representing a Tuple. The new NSArray has the length of the shorter of the given arrays. (5) "zipWith:" will call the selector on an object of the first array with the corresponding object of the second array. The results are returned. All Methods exist in a variant that returns (void) - if you are just interested in the side effects. Of course "makeObjectsPerformSelector:" is not reimplemented. Use it instead. Note that when using the variant that returns a (NSArray *) with a selector that usually returns an object but returns a nil in a particular case a NSNull object is stored in the resulting array. What more is available? OHHelper contains some macros. (min,max,min3,max3,fitRange <- on opened and closed intervals) OHTuple is like (a,b) but not type save ;) - it just stores two objects that can be retrieved by calling 'fst' or 'snd'. OHFunction lets you store a Methode call in an object for later execution. OHFunctionCatImageGetter lets you store a Method that will load an image at a later time. OHLazyObject Initialized with an OHFunction it will create an object when it is requested and cache it for later use. On a memory warning the cache is cleared. OHLazyMutableArray Using LazyObjects internally it just behaves like a normal array except that you initialize it with OHFunctions. Upon request of an object the object is generated behind the scenes. On a memory warning the object gets released again - so if you have the object retained elsewhere, in order to free up the memory, release it there too (if possible). OHVector I dont know why but Apple has forgotten to add simple operations on vectors (CGPoint) ... or I was just unable to find them. Here there are a few. Please have more FUN with Objective-C!
About
Objective-C Classes for Haskell Programmers (with primary focus on the iPhone SDK)
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published