Mandar Apte

UI/UX Designer from Mumbai, Maharashtra, India.

Category: Code Examples

  • Chapter 04: Array in Swift

    What is an Array?
    An array is an ordered list with indices / Index.
    Examples of an array are a to-do list, shopping list, Amazon Wish List, etc.

    Let’s say we have an array list of apps

    Index:
    0 1 2 3

    Element:
    “Reminders” “Mail” “Xcode” “Calendar”

    Important Note:
    The index of the first element always starts with zero because the way computer scientists deal with data in memory, they have offset & offset starts with zero & that’s why the Array begins with zero. The index of an array never exceeds the number of elements.

    Here is how to declare an Array in Swift:
    We will declare an array with the let or var keyword, the identifier name, the equal sign, and square brackets. A comma separates each element.

    var apps = ["Reminders", "Mail", "Xcode", "Calendar"] // Array of Strings, Each element is of Type String
    var number = [1, 2, 300, 4000] // Array of Integers, Each element is of Type Integer
    var bools = [true, false, false, true] // Array of Boolean values, Each element is of Type Bool
    var groups = [["John", "Tom", "Steve"], ["Brandon", "Bill"]] // Array inside array
    (more…)
  • Chapter 03: String in Swift

    All About String in Swift Programming Language

    Let’s know what String is. String is a collection of characters

    Here is how to declare a String

    var courseName = "iOS Development"
    var language = "Swift"

    Here is how to use functions like String Concatenation, i.e. attaching one String to a second string

    var hello = "Hello, "
    let world = "World! "
    let sentence = hello + world + "This is iOS Development" // "Hello, world! This is iOS Development"

    Important Note:
    As you can see above, we have used the ‘+’ operator to concatenate two strings together

    (more…)
  • Chapter 02: Variables & Constants in Swift

    Data Types in Swift Language

    Integers i.e. Int:
    1, 2, 3, 199, 1000
    Float & Doubles:
    3.14, 1.168, M_PI
    Boolean Values like Bool:
    true or false
    Collection of Characters like Strings:
    “iOS Development”, “Apple”, “1.2”

    We can create our data type using the keywords Struct & Class.

    All About Variables

    Here is how we declare Variables in Swift:
    First, we start with the ‘var’ keyword, then ‘Identifier Name’ & ‘Initial Value.’

    Here is how to Declare Integer values: Int

    var thisYear = 2017
    var ourAge = 20

    Here is how to Declare Empty Integer

    var emptyInteger = Int()

    Here is how to Declare a String

    var courseName = "iOS Development"
    var language = "Swift"
    var software = "Xcode"
    (more…)
  • Identify the iPhone or iPad model programmatically using Swift Language.

    You may be programming a Universal App for iPhone, iPad, or iPad Pro and wondering how to write conditional code for those variant iOS device sizes.

    So here is how to write code by identifying the device height of your display or frame.

    Here is how to solve this situation by identifying device height,

    Note:
    This code uses the native bounds of the device, so it will work for all current devices that may be in landscape or portrait mode. Code is written in Swift Programming Language.

    (more…)
  • Call function from FirstViewController to SecondViewController using Swift Programming Language.

    Here is the situation in your Xcode project where you want to call a method from another class Swift file to your original class of Swift file.

    Let’s call your original swift class file ‘FirstViewController’, which has ‘UIViewController’ as a superclass.

    The second swift that you want to call a function from, we will assume that it has ‘SecondViewController’ as the class name & it has ‘UIViewController’ as a superclass.

    You have written a function called ‘print something()’ in your ‘SecondViewController’ that would be triggered when somebody taps on the button present on ‘FirstViewController’ as IBAction called ‘print this(sender: UIButton)’

    So, you will write a print function as follows:

    (more…)
  • The complete guide for maintaining and optimising WordPress websites for optimum performance.

    Introduction

    I have been using WordPress for almost more than five years now.

    In the post below, I will explain the step-by-step procedure for hardening, securing, and optimising WordPress for best performance and security.

    So, First things first,

    Introduction to WordPress

    What is WordPress? WordPress is a free and open-source content management system (CMS) based on PHP and MySQL. Its features include a plugin architecture and a template system. As of January 2015, over 23.3% of the top 10 million websites used WordPress. WordPress is also the most popular blogging system on the Web, with more than 60 million websites using it.

    As we know today, WordPress is offered in two different formats: one is managed and hosted by the team at WordPress.com, and the other is self-hosted by the user using a downloadable installable package available at WordPress.org.

    Difference between WordPress.com & WordPress.org

    The following things differentiate WordPress.com and WordPress.org from each other

    1st Difference
    WordPress.com: The user provides the content & website is managed by the team at WordPress.com.
    WordPress.org: Content provided by the User & Managed by the user itself.

    (more…)
  • Leverage browser caching for improved webpage load time performance & speed.

    Introduction:

    To enable browser caching, you need to set expiry dates on certain files. Find your .htaccess file in the root of your domain. You can edit the .htaccess file with Notepad or any text editor. In this file, we will set our caching parameters to tell the browser what types of files to cache over a period of time so that page loading time improves by avoiding or keeping certain files and using browser cache from history.

    (more…)
  • Fix the WordPress.com Jetpack error: ‘Website needs to be publicly accessible to use Jetpack.’

    As we know, the WordPress community exist on wordpress.com & wordpress.org

    WordPress.org is a downloadable CMS (Content Management System) distribution for self-hosting used by web designers and developers.

    Being a CMS lead developer, Automattic wants its wordpress.com experience to be available to its wordpress.org users. So, they developed plugins like JetPack for WordPress self-hosted websites.

    JetPack Error:
    Your website needs to be publicly accessible to use Jetpack: site_inaccessible
    Error Details: The Jetpack server could not communicate with your site [HTTP 404]. Ask your web host if they allow connections from WordPress.com. If you need further assistance, contact Jetpack Support: http://jetpack.me/support/

    Your website needs to be publicly accessible to use Jetpack- site_inaccessible Error Details- The Jetpack server was unable to communicate with your site HTTP 404
    (more…)
  • Using the Sticky Navigation Bar to increase the page views per visit (session) ratio for any website.

    It is a well-known, tried-and-tested method to have a sticky navigation bar at the top of a responsive website design and layout.

    A fixed navigation bar at the top helps mobile or desktop website users have a fixed area where they can find navigation icons and links through which they can browse and navigate the current website. Having a fixed navigation bar at the top helps webmasters increase page views, i.e., it helps webmasters increase the page views per visit ratio.

    Yes, it occupies space at the top, but it helps the user have navigation links handy whenever he wants to browse the website. Space constraints only refer to mobile devices with small screen sizes.

    The following is the code that helps you have a fixed navigation bar. Copy and paste the following CSS code in your style.css

    (more…)
  • How to fix WordPress Automatic Update Error.

    Background:

    When WordPress.Org releases a new update to its WordPress standalone CMS (Content Management System), you may have set your website to get your installation updated automatically, or you may like to do it yourself at your preferred time.

    But because of server load on the part of your web host, you may get an error something like this with a screwed-up blank website with the following error printed on the screen:

    Warning: require(/nfs/domains/your-domain-name.com/html/wp-includes/session.php) [function.require]: failed to open stream: No such file or directory in /nfs/domains/your-domain-name.com/html/wp-settings.php on line 122
    
    Fatal error: require() [function.require]: Failed opening required '/nfs/domains/your-domain-name.com/html/wp-includes/session.php' (include_path='.:/usr/local/php-5.3.27/share/pear') in /nfs/domains/your-domain-name.com/html/wp-settings.php on line 122

    The actual cause of the above errors:

    As mentioned, errors are generated because of interrupted WordPress updates, primarily because of heavy load on your web host’s online server. As the update fails, all files mismatch with consistent version numbers, so some old source files remain as it is & only the remaining few get updated with the new version. So, it is a problem of source code version consistency.

    How to fix this:

    Error 01: [function.require]: failed to open stream: No such file or directory in

    Error 02: Fatal error: require() [function.require]: Failed opening required & (include_path=’.:/usr/local/php-5.3.27/share/pear’)

    (more…)

Sponsors


Search