How to tweak the Volume HUD in iOS?

iOS volume change HUD is a big freaking non interactable rounded rectangle pop up. This obstructs the UI for good 2-3 seconds. This irritates me. So if there are any media apps to be developed use this technique to customize volume change feedback UI.

Now if you are developing an app and need very less irritated users or frustrated users, then never ever use feedback HUDs right in the center of the screen and that too for more than 2-3 seconds.

Now one default such HUD is Volume HUD which comes over all the applications. But good thing is you can customize it.

You need to add just 3 things in your view controller:

  1. Apple’s MediaPlayer framework
  2. A dummy instance of MPVolumeViewadded as a subview of your view
  3. An observer to AVSystemController_AudioVolumeNotificationParameterThe below linked youtube video guides you on how to implment this in your project:

https://www.youtube.com/watch?v=tq49LUKbRLY

The source code to the sample mentioned in the video is available on Github:

https://github.com/itsdamslife/iOS-Custom-Volume-UI

Share your feedback in here or below the youtube video.

Happy coding ūüėČ


Damodar Shenoy's DEV Profile

Advertisements

Open Terminal from Xcode

I love Xcode as an IDE for macOS and iOS development. But it has its own set of limitations. One feature I miss a lot is Opening a Terminal window from the Xcode into the same directory of the project. This will save lots of time.

Every time you want to run a git command or cocoapods or say any xcode build command – Opening a Terminal manually and changing the directory to the project directory takes at the least 30 seconds to a minute. Now what if I say you can do this

Now, What if I say you can open a Terminal window and get to the project directory  in 1 second or say with a shortcut key?

YES! One shortcut.

This is how you do it. It’s a one time setup.

1. Create a 2 line shell script and give the file execute permission.
2. Go to Xcode Preferences.
3. Add a Behavior in Xcode. Name it and give a shortcut key.
4. On the right side details pane check the Run option.
5. From the adjacent drop-down menu choose the script you just saved in step 1.

Here’s the video on how to do it.

Script:
#!/bin/bash
open -a Terminal "`pwd`"

Command to give execute permission:
chmod +x /path/to/the/open_terminal.sh

If you are lazy like me here’s the gist, download and use it:¬†https://gist.github.com/itsdamslife/9532d757676b1f3c9b25f3959128367c

Hope this is helpful.

Happy coding ūüėČ

inspiration courtesy: The in-built Terminal of Visual Studio Code by Microsoft


Damodar Shenoy's DEV Profile

Blogging

What is blogging?

Blogging is just like maintaining a diary online. Its just logging/recording things you want to just write down and read later or/and also if you like then sharing it. Its similar to writing in your own diary, you get to theme and customize your articles, attach pictures.

The word Blog came from the truncated word of weblog. Blog contains articles and pages. Post is a term used to describe each article.

Types of blogging:

  • Personal blogs –¬†online diary or commentary written by an individual
  • Collaborative blogs or group blogs are thoe written by multiple authors
  • Microblogging –¬†small pieces of digital content‚ÄĒwhich could be text, pictures, links, short videos, or other media
  • Corporate and organizational blogs – written by employees for the employees and/or public too
  • Aggregated blogs – a feed of other blogs on something specific
  • Reverse blogging –¬†composed by its users¬†or opened up for anyone to write
  • vlogs – This is nothing but video blogging, creating videos and sharing

Why blogging?

  • personal reasons – your personal blog posts penning anything of your own interest.
  • record an event or something which needs to be preserved
  • a passion and they like to write down stuff.
  • a way of making a living – these people are hired to write blogposts, articles.
  • Some just want to record their day to day stuff or anything interesting in their life.
  • Some want to make their blog itself a resume of their work.

How to get started with blogging?

There are various Content Management Systems (CMS) like WordPress, Blogger, Medium etc., which lets you create your own blog. Sign up with any one of them and get started. Easiest one is Medium, not much to customize. In case of other two you get lots of options to customize. All of them maintain your content for free but with limitations. And then each of them have their own paid plans which gives you more capacity and more features as per their plans if any.

Start with writing a small post like a gist of your day. Or anything intersting which happened today. Or any story of your’s from the past. Start writing one paragraph per day. Follow few blogs try to observe how they written their post. Learn on the go.

Tips I learnt from others:

  • Best to start off with a small one para post – first step is always tough
  • Be precise and be specific on the topic which you are writing
  • Try to be consistent – like a daily gist or a weekly post or a biweekly or monthly post
  • Try to post one per week initially – I myself found it ideal.
  • Do not over think about criticism. Improve from it.

Once you get a hang of writing consistently next is to plan your next few posts and keep them ready. Try to be plan for a month in advance. We are all humans, we find ourselves sometimes lazy enough to do a routine. With this even if you skip you have one ready. Even if you skip one in your routine just continue writing, never stop.

keep reading keep blogging keep improving

courtesy : https://en.wikipedia.org/wiki/Blog

Deep copy and Shallow Copy

This is an important concept of computer science. You may have heard it very less in your day-to-day work life but your work will directly or indirectly relate to this one of the main concept of memory management. Let’s dive into this.

Here is scenario – Assume you have a team of 5 members. You have created a document on Google Drive and shared the link to the document with your team members.

Now how the doc is used / consumed is upto the members. Primarily there are two ways:

  1. One is : Using the online version directly to read/update or if someone updates you get the latest update directly. One can see the changes live.
  2. The other way is: Download a copy to your local system and use it as per your wish, manipulate it update it without altering the original copy which is on the cloud.

Thats it. If you know the difference between the 2 above,You got the concept! The first one is Shallow copy of the document and the second one is Deep copy of the document.

Now using this analogy let me explain you the memory management concepts of Objective-C and Swift.

  • strong : Members who have doc added to their own drive. Even if original is deleted the doc is not deleted. The reference link still points to the doc
  • weak : Members who have access to the doc will be informed upon deletion of the doc. Now the reference link will be invalid. It will point to nil.
  • assign :¬†Members who have access to the doc will NOT be informed upon deletion of the doc. Now the reference link will be invalid. App crashes if the link is accessed.
  • copy : Members download copy of the doc to their own system. Does not effect if either of them are modified or deleted. Takes up additional memory unlike the above 3 which are referenced to same memory location. Mutable copy is when document is downloaded with RW permissions.

The 4 statements above may or maynot hold good for Google drive but only used to explain the concept.

Pros & Cons:

Shallow copy

  • Doc link which is stored in the cloud
  • Owner and admins is the strong reference
  • Non admins will have weak reference
  • Changes to the document will be notified to every member

Deep copy

  • Document downloaded to local system
  • Consumes additional storage
  • If some one changes in the cloud does not effect your local system
  • Whatever you change locally does not effect cloud version

I made up this analogy because I found it easier to link both the concepts for understanding. Let me know if you find this difficult or missing. Please share your comments below.

happyCoding();


Dam's DEV Profile

AWS in 5 minutes

This post will give you a basic understanding of what Amazon Web Service is, how components in it works, what each component is responsible for at a very high level – all these in just 5 minutes.

This post is gives you a brief idea about the components used in aws. This will surely help you understand things when aws developers are discussing about topics and issues while at work.

EC2Elastic Cloud Computing instance is where you run your web app server or a micro-service server. This is one of the primary component of AWS. You can create multiple instances of the servers in multiple availability zone so that if one zone goes down your services to end users are not affected. Session maintainence can be configured here or in ELB

ELBElastic load balanacer automatically distributes incoming application traffic across multiple targets. It handles the traffic coming from the public networks (users/mobile/consumers). The major functionality of this component is route the traffic to different servers balancing the load from incoming traffic. It can handle the varying load of your application traffic in a single Availability Zone or across multiple Availability Zones.

ELB facing the public network will be inside a public subnet to make it accessible. Apart from this and S3 instance all other components will be inaccessible to public as they will be configured with private subnet. This would be the best place to have session stickiness.

S3Simple Storage Service is used for storing all static files like documents, audio, video, image files. This service is only used for storing and retrieving the files. Glacier is used in connection to S3 to archive the least used or unused files to reduce the storage space.

AWS
The diagram represents typical web app architecture using some of the important components of amazon web services. Also shows the interactions between the components.

DataBases:

RDSRelational DataBase is the place where you store and manage your application data. This service supports RDBMS solutions like MySQL, etc. This service also supports the Master-Slave architectures.

NoSQL DB are used if web app solution needs a document based databases like DynamoDB, etc.

Security Group – is used to manage the access to service anyone can have. Each service must ideally have a security group defined.

Route 53 is a highly available and scalable cloud Domain Name System (DNS) web service. It is designed to give developers and businesses a way to route end users to your application servers.

IAMIdentity and Access Management is the one where you can add/update/delete users and their permissions. Generally there will be end users, administrators, developers.

Elastic Cache is a managed, in-memory data store services. You can choose Redis or Memcached to power real-time applications. ElastiCache is a popular choice for Gaming, Ad-Tech, Financial Services, Healthcare, and IoT apps.

For administrators: CloudWatch monitoring service for AWS cloud resources and the applications you run on AWS. It keeps an eye your whole setup and triggers a notification using SNS service to email the administrators if there arises any warning or alert on servers using SES service.

Lambda services are generally used for solutions designed with serverless architectures.

Hope this would be useful to in one or the other way, at least giving you a sneak peak about what AWS is all about.

Obj-C — Swift — Obj-C

This is one of the rare scenarios one might get into, but the problem and its solution are unique and the simplest one here.

  • Have you come across a scenario where you felt the need for an additional method in a class inside a framework (one of the Pods you added) to achieve your work?
  • Is the library implemented in Objective-C?
  • Is your legacy code in Objective-C and now you are strategically moving to Swift?

Today at work my friend, Vinodh, asked me this:

“I have a pod framework which is in Objective-C, I need to add a functionality but needs to be used in Obj-C for now and may be used in Swift file in future. What is the best way to do this?

Let us say we have a class called Person inside one of your pod frameworks. This Person class has name, age and gender as properties, with a function to format the name.

// Objective-C header file of Person class
#import 

typedef enum : NSUInteger {
    male,
    female
} Gender;

@interface Person : NSObject

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) Gender *gender;
@property (nonatomic, strong) NSUInteger *age;

- (NSString*)formattedName;

@end

// Objective-C Implementation of Person class
@implementation Person

- (NSString*)formattedName
{
    return [NSString stringWithFormat:"This is %@",self.name];
}

@end

When the formattedTitle method is called on a person object with value for name property ‘Vinodh’ it would print like “This is Vinodh”.

Now we need to extend this Person class with another method say a new format which tells the age along with the name.

In classic Objective-C style it would be adding a category to Person class, Importing this category wherever you need this new method. This would have been the best way before Swift was introduced.

But there is a disadvantage if new developer join unitl and unless (s)he imports the category header, code completion will not show the new method. Probably the new developer will end up writing the same method creating a new category again. This is a problem.

Swift to rescue. Do the following:

  • Create a Person class extension and write the needed method
  • Now create a protocol and declare the method signature
  • Now prefix the protocol with @objc to make this available in Obj-C files

Here’s how you do it.

@objc protocol Formats {
    func getFormattedName(with ageHidden: Boolean) -> String
}

extension Person: Formats {
    func formattedName(with ageHidden: Boolean) -> String {
        let formattedString: String = ageHidden ? "This is \(self.name)" : "This is \(self.name) aged \(self.age) years."
        return formattedString
    }
}

Now wherever you type [personObject form… in Obj-C or in personObject.form… in Swift the code complete will show you both the methods one Person class another from the extension we added.

Love to hear more stories from your side. Please do share in comments.

Happy Coding!

WordPress on local machine

When I talked to a friend about learning wordpress development he said why do you want to learn wordpress now? Its an old technology. Now everyone is moving to either Medium or having their own blog developed from scratch.

It’s a true, a reality. With node, MEAN stack, Swift for server side and similar other frameworks a developer can build and run his own site with latest technology. WordPress still works on php, MySQL – the classic xAMP stack.

Why do you want to learn wordpress now? Its an old technology. Now everyone is moving to either Medium or having their own blog developed from scratch.

This doesnt mean we should stop learning old technology which are still doing good. Those are the systems which are still doing good, scaling good. They are thought through and are designed in a better way to last long compared to any new platforms today. I mean Facebook is still powered by php.

This doesn’t mean new technology is not there in terms of scalability. Sad truth is most never get opportunity to scale. Some never see the light of the day and some which get to see hardly have any subscribers and developers of that blog never scale them.

Why am I learning this now?

Learn and understand, experiment, know inside of it and whereabouts of what needs to be done then customize it according to your needs.

  • WP gives a base to start creating your own websites primarily blogs.
  • Lot of templates available or build your own and share.
  • Spend time in customizing as per your needs rather than build from scratch.
  • We can learn how various components are used.
  • Architectures and patterns followed.
  • The schema design.
  • Its always interesting to learn old technologies.

This is the reason why I went ahead with starting on wordpress. As a first step I wanted to install wordpress and try some themes and plugins. But to install I need a server to host and need a database hosting too. Next I searched for how to install WordPress locally on my system? got the results.

It needs a xAMP stack РApache-MySQL-PHP either on Linux, macOS or Windows. I have a macOS. Now next come how to start a Apache server? After some searching on internet Found MAMP which makes your task very easy. MAMP is for macOS and Windows too and there is another one WAMP for windows only.

There is no better way to have a server of your own for free and do your experiments. And the only best way for this full freedom installing it locally on your system.

Install WordPress locally:

  • Download MAMP
  • Install MAMP or WAMP as per their site
  • Download WordPress¬†Remember this is wordpress.org¬†not .com
  • Unzip the downloaded wordpress file, you must get a folder – wordpress
  • Copy the wordpress folder into installed MAMP folder’s htdocs folder*
  • Now click on Start servers
  • Once the loading spinners stop and you see green in front of Apache and MySQL your servers are running
  • Open your favorite browser and type http://localhost:8888 and hit enter
  • Set up database –
    • Go to¬†localhost/phpmyadmin
    • Go to Databases, add a name for the table and click Create
  • Configure WordPress –
    • Now open a browser tab and type localhost:8888/wp-admin
    • Follow the wizard
    • When asked for enter Database name, username, password, Host
    • By default username and password both are ‘root
    • Leave the Table prefix as it is and click Submit
    • Next click on Run Installation
    • Give a name, username-password and email-id for your blog
    • Click on Install wordpress. Success!
    • Now when you login, you should be able to see Admin console
Congrats!! You are up and running 
wordpress instance locally

*Alternatively you can also set the path from which MAMP has to serve. Launch MAMP – Go to Preferences – Web Server tab – Change the Document Root folder.

Where to go from here?

I am yet to do this, but definitely next step is to design your website and customize your wordpress installation. Here is a 7 video series on how to build a wordpress site

Now explore installing themes, creating a couple of themes and plugins. Along with creating them it will be interesting to understand how everything fits. I have just installed WP on my system and yet to explore all these.

This is where I learnt how to install WordPress locally.