Code Snippets

Dispatch an async task in iOS

This will probably be the most simpel async code snippet you will find (use it wisely 😉 ):
[cc lang=”objc” escaped=”true” width=”90%” theme=”default” line_numbers=”on”]
dispatch_async(dispatch_get_main_queue(), ^{
SwitchOutlet.on = YES;
});

Core data the basic snippets

Let’s start
[cc lang=”objc” escaped=”true” width=”90%” theme=”default” line_numbers=”on”]
#import <CoreData/CoreData.h>

READ MORE

Getting a time based greeting in PHP

Sometimes, all you need is a small function
[cc lang=”php” escaped=”true” width=”90%” theme=”default” line_numbers=”on”]
function getGreeting(){
date_default_timezone_set(‘Europe/Amsterdam’);
// 24-hour format of an hour without leading zeros
$Hour = date(‘G’);
if ( $Hour >= 5 && $Hour <= 11 ) { return "Good Morning"; } else if ( $Hour >= 12 && $Hour <= 18 ) { return "Good Afternoon"; } else if ( $Hour >= 19 || $Hours <= 4 ) { return "Good Evening"; } }

Handling a remote XML in PHP

In this example the status of every object will be printed to the screen.

[cc lang=”php” escaped=”true” width=”90%” theme=”default” line_numbers=”on”]
$url = “https://example.com/yourxml.xml”;
$xml = simplexml_load_file($url);
foreach($xml->Object as $XMLOBject)
{
$status =(string) $XMLOBject->Status;
echo $status.’
‘;
}

Updating data when push message is recieved in iOS

Setting up the NSNotification in the Appdelagate.m