Skip to content

Instantly share code, notes, and snippets.

View between40and2's full-sized avatar

Juguang XIAO between40and2

  • London & Beijing
View GitHub Profile
Ugliness of iOS Programming
First of all, i love iOS and iOS development ecosystem.
However, after I quick learnt Ruby on Rails, I found how messy iOS Programming Frameworks are. Apple guys must feel innocent on this. They have worked hard to make the frameworks easy to use, powerful yet flexible.
one end is, "there is more than one way to do a thing". I first heard it from Perl, which they are proud of that.. However, the downside of this is there is no conversion or culture.
There is no so-called application framework for iOS officially from Apple. After rough understanding on UIKit and Foundation, the developers need a further direction on how to improve the productivity on iOS development.
@between40and2
between40and2 / WelcomeToBlockWorld
Last active December 10, 2015 07:58
WelcomeToBlockWorld. get habit to use block-based, rather than old-style return-based invocation.
WelcomeToBlockWorld
http://www.cocoawithlove.com/2009/10/ugly-side-of-blocks-explicit.html
@between40and2
between40and2 / gist:5194810
Last active December 15, 2015 03:29
iOS & RoR
iOS & RoR
Wired combination? In my past 12 years, I have used more than these technologies on GUI and Web. Finally I fell in these 2.
One feature charms me in RoR is the feature of metaprogramming. Ruby supports it and Rails fully uses it. It sucks me into deeper thought on metaphysics of programming. Why are we (as programmers) here? What can machine (software) facilitates men (programmers) ? I would like to share some of my ideas.
Before iOS, I was working intensively with Adobe Flex. The beauty of Flex's flexible architecture attacks me, plus its UI expressiveness. I was my dream back in 2005, to present fancier UI on Web via programmable Flash. In 2010, the year I came to meet iOS, there was the debate on whether Flash should be run on iOS, I was wondering whether I should go for iOS. I became so determined after I realised the depth and width of iOS technologies are much greater than of Flash/Flex. Another obviously plus on iOS is, I can carry on my program anywhere I go.
@between40and2
between40and2 / gist:5194833
Last active December 15, 2015 03:29
rails plugin migration
http://stackoverflow.com/questions/4974039/rails-project-organization-with-many-models
http://stackoverflow.com/questions/6550103/in-which-folder-should-i-put-global-shared-partial-templates
http://stackoverflow.com/questions/6550103/in-which-folder-should-i-put-global-shared-partial-templates
<pre><code>$ cd your_repo_root/repo_name
$ git fetch origin
$ git checkout gh-pages
@between40and2
between40and2 / JXZip
Last active December 16, 2015 09:18
JXZip, hopefully easy to use to zip/unzip in iOS
I was in somehow confused to use ZipArchive.
First of all, I do not know which one is the "official" version of it.
https://github.com/mattconnolly/ZipArchive
Or
http://code.google.com/p/ziparchive/
@between40and2
between40and2 / iOS-Callback
Last active December 16, 2015 13:29
iOS-Callback
Here is my sum on which callback mechanism should be used for which cases.
- for UIView and UIVC, use delegate
- for model change, use NSNotification or KVO. However, KVO is not designed for communicating "events", therefore NSNotif is the preferred.
- for Data Access, use block.
for UIControl subclass, use target-action.
Bye Delegate, Hello Block
@between40and2
between40and2 / scm-svn-git
Last active December 16, 2015 13:38
favorite links for SCM, SVN, Git. etc.
http://svnbook.red-bean.com/en/1.0/index.html
After 3 years of iOS development practice, finally I have chance to fully work with the soft keyboard. I found the Apple official docs is far from enough to deal with every cases of iOS soft keyboard. Then online 3rd party docs are helpful but not complete either. I can understand it since everyone is busy, very few people to write a complete guide for any specific topics.
Then I come to this. I have to do trial and error to grasp this piece of knowledge. One problem I was facing is when device is in landscape, you cannot use keyboard's height to adjust textview/tableview's contentInsets, since the height actually seems as its "width". UIWindow is mounted always in portrait mode, and keyboard frame goes with it. When device and UI is in landscape, the keyboard frame is still measured as it is in portrait. The solution:
CGRect frameEnd = [[notif.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
frameEnd = [self.view convertRect: frameEnd fromView: nil];
@between40and2
between40and2 / ios-object-attribute-access
Last active December 25, 2015 04:09
Given an Objective-C object and an attribute name, how can you access (read/write) it?
return [self.object valueForKey: attrName];
--
SEL getterSEL = NSSelectorFromString( attrName);
@between40and2
between40and2 / class_addIvar-useless
Created October 24, 2013 09:45
class_addIvar, in Objective-C runtime, is useless
class_addIvar, in Objective-C runtime, is useless, because it does not support to add ivar in an EXISTING class.
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/c/func/class_addIvar
You can use the concept of idInfo (see id-ego-superego), to add run-time generated objects' property.