Saturday, November 18, 2017

How To: Make an App That Uses Public API (Openweathermap.org) Using NSURLSession

I think I mentioned somewhere (and maybe everywhere) that I love JSON. I LOVE IT! JSON is basically like NSDictionary. Every entry has a key and a value. And you can go nesting too - like a dictionary of dictionary of dictionary. O_o

// this is a bird's nest

What we're going to make:
2.5MB GIF

JSON is structured and that is why many web service opts to this format for communication between a client and server. In the old days, or even now, some web service still use obscure format like user-defined text strings separated by pipes or commas (CSV). Something like:

Tuesday, November 7, 2017

More Contribution to XCode Community!

One of my friends asked me, you get a lot of revenue from writing tutorial blog? My answer is - NO. I get like 0.001 cents per day from my blog currently lol. My blog isn't famous like appcoda or raywenderlich. So why do I keep on doing it? Simple - I always view that anything I learn, is an inspiration that is meant to be shared to everyone. I do it because I love to share what I know. Often, I faced with a problem to do something in my own apps, and upon finding a solution I like to document it, because I am sure others might have the same problem or obstacle. By sharing what I found or created, we advance together.

Enough intro. Anyway this post is a short one. I just want to announce yet another contribution that I am making towards the XCode Community - MY FIRST EVER GITHUB REPO!!!! OMG! Sorry I am too excited for this.


First repo is a flexible Toolbar/Tabbar. I have added a list of my Github repo in the left bar for future reference. Well, that's about it for this blogpost. I am thinking to redo the Switchy object as a proper repo next. Stay tune. Or not. Whatever dude and dudette.

Ps. I forgot to put the link to my main GITHUB REPO: GENECODE GITHUB

Saturday, November 4, 2017

How To: Use Reusable Views Correctly (TableView, CollectionView, etc)

First, some short intro! :D My blog views has finally reached ONE MILLION!!!

Now if I get a dollar for a view. Phew! None the less, I am so happy with this view count- why? Because it means I helped quite many developers to create their apps (hopefully). And those apps will benefit mankind. Even if it's a fart app, hey, it cheers up people and that is good.

As noobs we tend to not getting the whole picture of a particular UI object. A label is simple, there is text property, you set it directly in Storyboard or programatically (label.text = @"hello";) and it shows immediately. Pretty straight forward. But for objects that uses Reusable Cells like TableView, there are multiple set ups that we need to do to use it properly and therefore prevent any weird and unwanted bugs and crashes. Anyway here's what we're gonna end up with at the end of the tutorial:


It's a 2.4MB GIF.


What does Reusable Views mean? 

It is basically a concept/method to display big amount of data in a scrollable area. In case of TableView,  the amount of cells being created by TableView is only a small quantity that is enough to fit the visible area of TableView.

For example, if you have TableView of height 300, and each cells height is 10, then at least 31 cells are created at runtime. And when you scroll down the table, the cell that is being pushed out of view

Thursday, September 7, 2017

Can you use Deprecated Functions?

Hey guys, I am making a few tutorials but all are in progress right now. Hope to publish them this weekend. Anyways, as a frequent StackOverflow visitor, I often read programmers wanting to change the functions they used that are deprecated. From their postings, I get that many programmers think that deprecated means "cut off" and therefore cannot be used indefinitely. This is, false.

Let us take a look at the meaning of the word first.


Basically, it means disapproved (or in layman terms, not advised to be used). It is not the same as totally cannot be used in which case the word is BANNED. Deprecated is not banned. It is only advisable not to use the function. BUT YOU CAN STILL USE IT.

In iOS developer terms, you can surely use a deprecated function, but you must start thinking/planning/coding of the new function to replace it in 4-5 years time. Deprecated functions normally are supported for a long time before they are removed. This is because often, Apple creates new and better frameworks for a thing. But there will be many apps that rely on that framework that are already in the App Store. So to immediately ban a function, is an act of oppression.

For example, NSURLConnection. It was introduced in iOS2.0. It's successor, the NSURLSession was introduced in iOS7.0. So since iOS7.0, NSURLConnection is therefore flagged as deprecated. But can you still use it in iOS10? YES IT STILL WORKS. In iOS11? Nobody knows (except the beta users right now). Given 3 versions of iOS has passed, you oughta change it by now.

But if it was *just* deprecated in iOS9 for example, no sweat because that function will definitely be available even in iOS11. So if you're doing a quick update of your apps, very old functions that are deprecated (like the ones intro'd in iOS2.0), should be replaced. But if the deprecation appear in iOS8 or 9, you're likely safe to leave it as it is for now.

Hope this post has been beneficial. Happy coding!


Saturday, July 8, 2017

How to: Basic of XCode Methods & Functions in Objective-C

Why ObjC?

Cause we're oldskool! :D


INTRODUCTION

When we start to code, what we need to do is write methods on top of the already available delegates (namely the View Lifecycles delegates like viewDidLoad or viewDidLayoutSubviews). A typical method that we quickly create is IBActions. These are automatically created when you drag an outlet in Storyboard to your header file.


-(IBAction)aButtonWasClicked:(id)sender {
  // your button was clicked by user
}

The aButtonWasClicked: is the name of the method. Note that I include the semicolon at the end. This indicates there is a parameter to be supplied to the method. So if you want to call this method elsewhere programatically, you need to write:

Friday, April 28, 2017

How To: Seriously Plan and Design an iOS Apps or Games

Hey whatsapp? (see what I did there? XD)

All these while we've been playing with XCode and making fun things without much care of how our app's structure looks like.



The thing about making an app/software, there are so many ways to do one thing. So many ways to code a feature. But if you are serious in making apps, you need to consider your app carefully and thoroughly, so that updating the app won't be a pain in the a$$ in the future. This is more so, when making your own app, or an app for a customer that may be requested to be updated in the future. The overall structure and back bone of the app needs to be as good and as organized as possible. Otherwise you'll end up crazy, trying to make sense of things in the app or when you want to add a new feature to the app.

So what you should do? I now will outline the necessary steps and points for you to consider when making an app.

Sunday, February 26, 2017

How To: Create Undo and Redo in a Drawing App

Hi guys.

I want to share how to create undo and redo in a drawing app. I tried using NSUndoManager for this, but it doesn't work. Why? I don't know. When something don't work, I tried for a bit, and if I have no more idea to try and work it out, I simply abandon the idea and try something else totally. There is no point lingering on something that you simply do not know.

The way to implement undo and redo is quite simple really. You just detect user's end stroke, and then save that drawn image into a MutableArray. This will eat memory a bit especially if you have a very big image. Alternatively you can simply store the drawn image in the TMP folder of your app sandbox use names like "undo0.png, undo1.png, undo2.png...". Have a global undo index variable to keep track of the undo/redo steps. When undoing, you -1 to the index, and load the image based on this index number. And when redoing, you +1 to the index, and load that image.

Something like this:


-(void)undo {
undoIndex -= 1;
NSString *imageName = [NSString stringWithFormat:@"%undold.png",undoIndex];
yourImage.image =  [self loadImageFromTMP:imageName];
}

-(void)redo {
undoIndex += 1;
NSString *imageName = [NSString stringWithFormat:@"%undold.png",undoIndex];
yourImage.image =  [self loadImageFromTMP:imageName];
}


Of course, you have to handle the undoIndex limits (>=0 and <maxUndolevel). Simple right? Kthxbai.