Posts

Showing posts from 2013

A hint for when you are setting up the Android SDK on IntelliJ IDEA

​When trying to set up an Android SDK, you might be presented with the following error: "the selected directory is not a valid home for sdk" Just make sure that you are running IntelliJ as an Administrator. The other thing to check for is if one of the folders in the path is hidden, which can happen if you selected to only install the Android SDK for the current user. Just unhide the folder. (A Windows specific issue) This might also be applicable to Android Studio, I'm not sure. There ya go :)

Comparing NSDecimalNumbers in Objective-C

​So ran into this issue when checking if an NSDecimalNumber variable is less than zero: if(myNSDecimalNumberVariable < 0) {        <the then code block> } else {        <the else code block> } and it was always going to the else, regardless of the value of my variable. Apparently what is happening is that pointer addresses are being compared. If I was comparing two NSDecimalNumbers I would have similar "strange" behaviour. I'm guessing to someone who grew up on a language familiar with pointers, that this would have been obvious. However, I was not that fortunate. The correct way to do a comparison is to use the "compare" instance method: if([myNSDecimalNumberVariable compare:[NSDecimalNumber zero]] == NSOrderedDescending) ....<the rest of if statement> This is something to keep in mind with a lot of the Objective-C types. Dave at  innerexception  showed me the light...

Querying an NSSet from CoreData

So... for entities that have a to-many relationship you get an NSSet property. When querying this property you can use the ANY and ALL operators. Scenario: {     You have entity A that has a to-many relationship with entity B.     Entity B has two rows. One having a property that is set to FALSE, the second row has that same property set to TRUE.     Entity A has two rows. The first having a link to the FALSE row, the second having a link to both TRUE & FALSE rows. } Selecting rows from entity A where "ANY" of the rows from entity B has the property set to FALSE, will return both rows. Selecting rows from entity A where "ALL" of the rows from entity B has the property set to FALSE, will return only row one from entity A. As this is the only row where ALL the links are FALSE. THE PROBLEM: The "ALL" operator doesn't work! It will crash your application. You will get the following error: Terminating app due to uncaught exception 'N

Tracking service call durations and times on Fiddler

Here's some scripts for custom columns that I use on a daily basis. Helps me a lot to keep track of when webservice calls were made and how long they took: This method gives you a column with the duration of a web call, formatted into a time:        public static BindUIColumn ( "Duration" )        function CalcDurationCol (oS : Session )           {               var sResult = String .Empty ;               if ((oS .Timers .ServerDoneResponse > oS .Timers .ClientDoneRequest ))               {                      sResult = String .Format ( "{0:H:mm:ssss.ffff}" , (oS .Timers .ServerDoneResponse - oS .Timers .ClientDoneRequest ));               }               return sResult ;        } This method gives you a column with the time that the request was started:        public static BindUIColumn ( "RequestTime" )        function CalcRequestTimeCol (oS : Session ){               if ( null != oS .oRequest )                     

Searching for resources in XCode

Unfortunately you can't search for resources used in XCode, it sucks. If you are using AppCode you do not have this problem. Example: images used in .xib files won't be found in search. One would think that this very basic and common task that should be easy to do. Not. Using the Search Navigator would only give you results in the .h & .m files. But, what about references in a xib/storyboard/plist etc? To get around this, open terminal and use this nifty grep command  (add whatever extensions you want to search for in the curly brackets) : grep -i -r --include=*.{xib,m,h} "filenamewithoutextention" /the/location/to/search/in

Super Awesome Secret Emulator Tip: How to enable your computer's keyboard on the Windows Phone emulator

All other emulators allow you to type in using your PC's keyboard, right off the bat. Apparently there's a super (and very, very) secret way to get your keyboard to work for the Windows Phone emulator. Press the Pause/Break key on your keyboard.   It will toggle between using the emulator’s on-screen keyboard, and your physical one. Who knew?... Accidentally stumbled upon this after years of working with the emulator:  jeffblankenburg (Many thanks to this guy)

A better way to do NSLogging

There is much better way to do logging in your iOS apps than using NSLog directly. The problem with that is that you have to go to every NSLog statement you have in your entire codebase whenever you want to make a change to them or want them out of your current build, etc. etc. You would always want to remove your NSLog's before doing a release build and this could be an extremely tedious task. Also, many people don't know that NSLog's can be very bad for performance. So whenever you would want to test whether logging is causing your performance issues and you just quickly want to remove them, you would also want a quick way to just switch logging off. I came across this macro in a project that I was working on. It is just awesome. #ifdef DEBUG #   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #else #   define DLog(...) #endif Using this DLog macro your logs will automatically include the method

Bitwise operators for options

There's a very useful technique that is available to developers that hardly anyone knows about these days. Bitwise operators! Basically what you are doing is manipulating the individual bits within a variable. Personally where I have found this extremely useful is for having a bunch of options and passing them around in a single integer variable. For example, let's look at the orientation options of a mobile application: Portrait for the first bit, LandscapeRight for the second bit, LandscapeLeft for the third bit, PortraitUpsideDown for the fourth bit We can represent an application that can only be in portrait mode, regardless if the device is upside down with the following: 1001 which equals an integer value of nine (9) or the sum of one (for the first bit) and eight (for the fourth bit) To get this you could do the following: int options; options += 1 << 0;   //Portrait                      // 0001    // integer value of 1 options += 1 << 3;

Singletons in Obj-C

Came across this pattern the other day: static dispatch_once_t onceToken; dispatch_once (&onceToken, ^{ // Do some work that happens once }); This is the better way to implement a singleton in Obj-C. Reduces the code needed from the normal way of coding it out yourself, and guarantees that your object will only be instantiated once. Some nice reading on the matter at  bignerdranch  and at  stackoverflow