Dispatch Async in Swift

When going over how to handle web content related parsings it seems that there is a piece of code-part to improve your app overall parsing performance.

In the example above you will see that the main code exists of “dispatch….. ())”.
After this we tested our own piece of code which is simply to check if there are no errors and if not, we update the content in our label, self.resultLabel.text = weather.

Swipe to delete

One of the useful gestures that you want while implementing for lets say a ToDoList, is that you also want to swipe to delete an entry within your array.

Look at the code below which enables you to achieve this kind of action.

You can now implement the code you want to achieve this action, eg. indexPath.row.

Happy coding!

Hide your keyboard in swift when done typing

When you are programming in Swift (x-code) and are designing your lay-out you have to decide how you are going to handle input from your user.

If you have a input field programmed with lets say only “numbers” you have to dismiss your keyboard once the input is “done”.

This is often called the “FirstResponder”.

Lets have a look at some code-parts below.

1. You create your function by declaring “func”.
2. The name of the function is: “textFieldShouldReturnandThusDesmissIt”.
3. then you have the name “textField” of the type “UITextField” which you also unwrap with the “!”.
4. and you will return a “-> Bool”.
5. “item” refers to the name of your label which accepts input, thus the UITextField.
6. The “resignFirstResponder()” is called to resign the keyboard.
7. You return the Boolean, in this case as true, see point 4.

One important note to add is that the above mentioned code reflects to the return key once pressed when you are using the “item” “UItextField.

The below code reflects to a touch in your screen to dismiss the keyboard. This is referred to as touches began.

The code you know see is called to override a function and check for touches on your screen to dismiss the keyboard. self.view.endEditing(true) simply means that self.view is reflecting to your current viewController and is ending the editing one a touch is detected, thus touhcesBegan.

Creating a custom Slider in Swift

sliderTo change the design of a slider in Xcode, you have to use some coding because you can only customize the slider a little bit using the Interface Builder.

Use this code and place it in your viewDidLoad() section.

Change “your_slider” into your own slider control name and insert your custom images into the “yourimages” vars.


AdMob integration with Swift in Xcode

Aadmob-logo-133950569s a lot of people have transitioned from using Objective-C to Swift, meaning that also a lot of code has to change along the road as well.

Google has came up with a document that lays out all the steps necessary to implement AdMob into Xcode, but sadly this is only done for Objective-C.

After some extensive testing the code itself is quite easy to implement, but one has to know.

Some mandatory steps are needed ( see also the Google guide to using AdMob into Objective-C fot the frameworks that need to be added ).

1. Import AdMob SDK.
2. Add all the Framework dependencies that are needed ( see Google ).
3. Add a view ( Banner view ) and make it the size of the banner ( see Google ).
4. Create a new file and name it Bridging-Header.h ( see Google ).
5. Obtain a Unit Test ID for Google AdMob.

However as you also have to enable some other tiny little things, we will post a link to a Youtube video explaining this step by step.

The code needed for your project is:

In the above code please note that the BannerView added within your Main.storyboard is indeed called “bannerView”. Otherwise you will be in for some errors.


Also credits to Vea Software for the visual instructions: https://www.youtube.com/watch?v=_15_OmvJU2U

Google AdMob SDK + Code: https://developers.google.com/mobile-ads-sdk/docs/admob/ios/quick-start



(JS) Tutorial: Google Spreadsheet Auto email with template

In the previous posts I showed all kind of little snippets / parts that can be used for Google Spreadsheet and the Scripting engine.
Of course these weren’t just random posts, they are all part of a bigger script.

The result

With this script you can make an entry in a spreadsheet and use a custom menu to initiate the script. The script then uses a template you defined in another sheet to format the email with the contents of the entry you just made.
After the mailing is finished, it’ll mark it as “done”, sets the next “reference number” & “date” and continues to the next line.

This kind of scripting and workflow handling will definitely come in handy when trying to automate things!

For this example we will create a sample email like this:


We defined the name (Jennifer), the ref number (1) and the date (28 January 2015) using the script and contents of the spreadsheet file!

Also we can define the whole content of the email, we’ll get to that in a second.

Let’s get started!

1. Create a new Google Spreadsheet and enter the following lines:


Name this sheet “List“.
The second row is a “start” row. I used this to set a start number for column A which is 0 (zero). Also this is used to test the script. As you can see column F is already marked with a “x”, so if you run the script, it should skip row 2!

2. Create another sheet in this spreadsheet and call it “Email-template” with the following contents.

As you can see, we’re already defining some “key variables” which we will read and replace with contents from our sheet “List“:

keyName, keyNumber and keyDate


3. Now, scripting time!

We start with creating a custom menu, which we use to start the script inside the Spreadsheet:

In the spreadsheet go to: Tools -> Script editor

Delete everything in this file and enter the next few lines that will create the custom menu when you open the Spreadsheet.

This is pretty straightforward right? It will create the menu “Auto Mailer“, if you click on it, it’ll show a submenu with 1 option called: “Start Mailing!“.
This will call the function “startMail“.

You can test this little menu by going back to your spreadsheet and refreshing it (F5 or CMD+R). It should now appear in your menu bar on top!

4. The big function!

Go back to the Script editor and paste the following lines after your “onOpen” function which we created in step 3.

I tried to describe each line in the comments, so paste this and read the comments to learn the script, it’s pretty easy!

After changing the spreadsheet ID, you can run the script by pressing the play button in the Script Editor. The first time you run the script, you’ll need to authorize the script to use your account and perform some actions.

After that, the script will run and won’t ask for authorization again!

Of course this script can be improved, but for beginners this is easy to understand.
If you have any questions or improvements, let me know!


(JavaScript) How to insert and ready cell values in Google Spreadsheet

You’ll probably use this function often when scripting for Google Spreadsheet.
It’s pretty easy to read a value from a specific cell:

And it’s even easier to write a value in a cell!


(JavaScript) Format / get current date

I’m currently pretty active with Google Apps Script, so you’ll see probably more JavaScript snippets in the coming days.

For a Google Spreadsheet script I needed to get the current date in Dutch with custom formatting.

I needed 2 formats: 01-01-2015 and 01 januari 2015

By default you’ll get the English written month, so I created a simple if statement to change this.
There’re probably more easy or other ways to do this, but this works :)


(JavaScript) Create a custom menu Google Spreadsheet

Here’s a little code to create a custom menu in Google Spreadsheet and link it to a function:

You can create something like this:


(JavaScript) Open last changed cell or tab Google Spreadsheet

Often I receive the question from users when they open a large spreadsheet that they need to scroll down in Google Spreadsheet to the last cell they changed.

You can fix this with this little javascript code.

Open your spreadsheet, go to Tools -> Script editor (or Extra -> Script editor).
Paste the code, run the function “setTrigger” once, give the authorization and run it again.

After that you can close the spreadsheet and reopen it again to activate the script!

[UPDATE 13:17]: code updated with new API from Google

[UPDATE 14:43]: Unfortunately the code doesn’t work anymore, I’ll fix this asap!

source: quora.com

1 2