Use of Operator Overloading with Swift

apple_swift_logo

I was just going through the Swift document and I found that Swift allow to overload the operator just like as C++ Language. Objective-C doesn’t allow to overload the operator.

As swift document we can also say “Operator Functions”.

Let’s Overload ^ (XOR Operator) to make Power of the value

Function Prototype :

Declare function prototype with left hand side value and right and side value.

Operations in the function :

To make the power of the value we have to apply following operations

Let’s try to use with the operator :

Happy Coding 🙂

Swift 2.2 Warnings and It’s Solutions – Xcode 7.3

apple_swift_logo

Xcode 7.3 came with Swift 2.2 Version. I just updated to Xcode 7.3 and found following warnings because of Swift version change.

List of warnings with it’s solution:

  1. ‘var’ parameters are deprecated and will be removed in Swift 3
  2. Warning Function Var
    Warning Function Var

    Warning with:

    func functionTest(var param:String) {
    	print(param)
    }
    

    Solution:

    func functionTest(param:String) {
    	print(param)
    }
    

    If you want to update that variable inside the function then you have to create copy of that variable to do operations on that.

  3. Use of string literal for Objective-C selectors is deprecated; use ‘#selector’ instead
  4. Warning Selector
    Warning Selector

    Warning with:

    btn.addTarget(self, action: "functionName", forControlEvents: UIControlEvents.TouchUpInside)
    

    OR

    btn.addTarget(self, action: Selector("functionName"), forControlEvents: UIControlEvents.TouchUpInside)
    

    Solution:

    btn.addTarget(self, action: #selector(ViewController.functionName), forControlEvents: UIControlEvents.TouchUpInside)
    

    Apple Documentation : Added information about the #selector syntax for Objective-C selectors to the Selector Expression section.

  5. ‘++’ is deprecated: it will be removed in Swift 3
  6. Warning ++
    Warning ++

    Warning with:

    var i = 0
            
    for str in arrStr {
    	print(str)
    	i++
    }
    

    Solution:

    var i = 0
            
    for str in arrStr {
    	print(str)
    	i += 1
    }
    

    Apple Documentation : Removed discussion of C-style for loops, the ++ prefix and postfix operators, and the — prefix and postfix operators.

  7. C-style for statement is deprecated and will be removed in a future version of Swift
  8. Warning For Statement
    Warning For Statement

    Warning with:

    for var i=0; i<arrStr.count; i += 1 {
    	print(arrStr[i])
    }
    

    Solution:

    for i in 0 ..< arrStr.count {
    	print(arrStr[i])
    }
    

  9. __FILE__ is deprecated and will be removed in Swift 3, please use #file
  10. Warning __FILE__
    Warning __FILE__

    Warning with:

    __FILE__
    

    Solution:

    #file
    

More swift tutorials/articles are available here.

Happy Coding 🙂

Swift Resources #3

Swift Resources
Swift Resources

Swift Useful Resources:

  • SwiftyStoreKit Lightweight In App Purchases Swift framework for iOS 8.0+ and OSX 9.0+.
  • Sensitive Fresh look at work with gestures in Swift.
  • NumberMorphView A label view for displaying numbers which can transition or animate using a technique called number tweening or number morphing.
  • SwiftImageProcessing This project demonstrates how to do pixel operations in swift.
  • Gifu High-performance animated GIF support for iOS in Swift.

Posted by @NatashaTheRobot in Issue No. 80

If I got time then I will try to post the Swift/Objective-C useful resources everyday.

Happy Coding 🙂

Swift Resources #2 – for Animation

Swift Resources
Swift Resources

Swift Useful Animation Resources:

  • Spring A library to simplify iOS animations in Swift.
  • Animo Bring life to CALayers with SpriteKit-like animation builders
  • Advance A powerful animation framework for iOS and OS X.
  • CKWaveCollectionViewTransition Cool wave like transition between two or more UICollectionView
  • EasyAnimation A Swift library to take the power of UIView.animateWithDuration(_:, animations:…) to a whole new level – layers, springs, chain-able animations and mixing view and layer animations together!
  • Cheetah Easy animation library on iOS with Swift2

If I got time then I will try to post the Swift/Objective-C useful resources everyday.

Happy Coding 🙂

Swift Resources #1

Swift Resources
Swift Resources

Swift Useful Resources:

  • FolioReaderKit FolioReaderKit is an ePub reader and parser framework for iOS written in Swift.
  • KZLinkedConsole Clickable links in your Xcode console, so you never wonder which class logged the message.
  • Chatto A lightweight framework to build chat applications, made in Swift.
  • PFColorHash Generate color based on the given string.
  • SwiftCharts Easy to use and highly customizable charts library for iOS.

If I got time then I will try to post the Swift/Objective-C useful resources everyday.

Happy Coding 🙂