Welcome

I am Ary Tebeka, serial entrepreneur and currently an Indie iOS dev (for the last 4 years). I’ll try to post in this blog things I discover while developing for iOS.

XCBlog-Top 5 Command Line Tools for iOS Developer

Xcode comes with lot of command line tools which you can find at path

 each one has specific purpose but some of them are very important in day to day role of iOS Developers. Most iOS Developers like to do everything from GUI either Xcode or using third party GUI tools but skilled and experienced developer uses command line tools like boss. There are some useful tools that every iOS developer should know and few of them are prefixed with “XC”. In this post, let’s go through five of them.

xcodebuild

The command   is a father of all the the commands in iOS development. You can do most of the iOS developer task like clean, analyse, build, test, archive with ‘xcodebuild’ command however you need to pass lot of option to ‘xcodebuild’ to get the right things done. You can explore these options using it’s man page

Or you can find all these useful information in the web page here. We can use xcodebuild to build, test  and archive our project targets or schemes. The example of the ‘xcodebuild’ would be

The ‘xcodebuild’ is huge command and mastering it takes lot of time but once you know it then you can script anything related to iOS development.

xcode-select

Xcode has a active developer directory usually located at   or we can set it with environmental DEVELOPER_DIR. The command   is used to manage active developer directory of the Xcode so that we can manage two version of Xcode at the same time. We can switch between Xcode version e.g we want to use Xcode beta

We can also use ‘xcode-select’ to install Xcode command line tools with GUI interaction using command

xcrun

Xcode command line tools can be run easily with   command. It gives us ability not only to find the tools but also execute them. We can use ‘xcrun’ to find the swift toolchain

We can execute most of the Xcode command tools using ‘xcrun’. The most useful tool that can be used with ‘xcrun’ would be ‘simctl’ to manage Simulators using command line. We can create, edit, erase and delete simulator using command line using ‘simctl’ e.g we can create

We can also delete, erase simulators using their identifiers. You can read more about xcrun here

xcscontrol

Xcode Server is continuous Integration system provided by Apple. We can use  to manage Xcode Server activities such as start, stop, restarting the sever. We can reset Xcode Server using

xctest

XCTest can be executed using   however there is another tools we can use it for running our unit tests. We can use ‘xctest’ to run unit tests.

There are so many tools available but we are going to cover only these tools as part of this post.

http://shashikantjagtap.net/top-5-command-line-tools-ios-developer/

<

p class=”curated_content”>On – 04 Apr, 2017 By Shashikant Jagtap

17 Xcode Tips and Tricks That Every iOS Developer Should Know

iOS

17 Xcode Tips and Tricks That Every iOS Developer Should Know

Xcode can be overwhelming to iOS developers, especially newbies, but fear not! We are here to help. The number of things that Xcode can help with and allow you to do is astronomical. Being familiar with your IDE is one of the easiest and best ways to sharpen your skills.

Here at Detroit Labs, we are no strangers to battling the mighty, mighty Xcode, and wanted to share our battle stories with you! After polling the Detroit Labs iOS developers, here are 17 of our favorite Xcode tips and tricks.

Key Reference:

  • : Control
  • : Command
  • : Option
  • : Shift
  • : Return

1) Moving a full line or many lines of code up or down using: to move up and to move down. If you have text selected, Xcode will move each line containing your selection; otherwise, it’ll move the line the cursor is in.

2) Using tabs to stay organized/focused. Tabs can be configured individually and optimized for different use cases. Tabs can also be named and later used in behaviors.

3) Using behaviors to display contextually helpful panes.

  • Behaviors are essentially preferences for what Xcode does in response to certain events. Say you started a build; you can set a preference to open a pane in response to it succeeding, failing, starting to be debugged, etc.
  • Fun fact: You can play a sound as a behavior when your tests fail. A developer here likes to set theirs to the failure sound from “The Price is Right.”

4) Open the file in the Assistant Editor. When using “Open Quickly” (), hold while also hitting return.

5) when the cursor is inside a method performs the “Copy Qualified Symbol Name” command, which copies the method name in a nice, easily-pasteable format

6) Effectively use inline documentation that can be parsed by Xcode to provide help when clicking on code/methods.

7) Edit the name of a variable everywhere it appears in scope by hitting .

8) Are you in a folder in Terminal and aren’t sure if your project uses Xcode workspaces or just a project file? Simply run “open -a Xcode .” to open the folder itself and Xcode will figure it out. Protip: Add this to your .bash_profile with a saucy name like ‘workit’ to feel like a real hacker.

9) Shortcuts for showing and hiding things in Xcode.

  • : show/hide debug area
  • : show assistant editor
  • : hide assistant editor

10) Auto-indent code by hitting

11) LICEcap is really useful for making gifs of the simulator. It’s great for PR screenshots. On top of LICEcap, you can use QuickTime to share your hardware device on your screen (for a demo, or to use LICEcap to make a gif). With your iPhone or iPad plugged in, open QuickTime Player and go File -> New Movie Recording. Then tap the down arrow next to the record button and select your connected device. This is useful for remote client demos, using LICEcap to make a gif, or actually recording your device for a PR.

12) Hitting then clicking on a file in the Project navigator opens a selection box to allow you to choose where to open a file.

13) Hold and click a file in the Project Navigator and it opens the file in the Assistant Editor.

14) Think of the Navigator pane (which shows up on the left side of the Xcode window) as the “Command” pane. That’s because holding and pressing a number opens the corresponding “tab” within that pane. For instance, opens the Project Navigator. opens the Breakpoint Navigator. Similarly, think of the Utilities Panes as the “Command+Option” pane. opens the first tab in that pane, the File Inspector.

15) and navigates among related files (e.g. .m and .h and .xib files).

16) If you’re fighting with code signing and Xcode tells you that you don’t have a valid signing identity that matches the provisioning profile, it may show you a seemingly random code that may not look to mean much. Find-identity is useful for finding this. Security find-identity -v shows installed valid identities.

17) Finding a file folder in your folder hierarchy is a HUGE waste of time. In Xcode 8, you can use the “Open Quickly” dialog or to save some time. When it’s open you can type any part of the file name you are looking for to find it.

Are you an iOS developer? See what it’s like to work here, and if you’re interested, apply!

https://www.detroitlabs.com/blog/2017/04/13/17-xcode-tips-and-tricks-that-every-ios-developer-should-know/

<

p class=”curated_content”>On – 13 Apr, 2017 By Elyse Turner

Improved Wiggling iOS 9 UICollectionView (Swift)

With iOS 9 UICollectionView now has built-in drag and drop reorder. This is very easy to enable specially when using a UICollectionViewController.

However there is no animation showing that the move operation started or finished, and worse there is no delegate call or notification to be informed of move start/end.

So here is my UICollectionView subclass which adds:

  • Wiggle animation while moving (taken from this library)
  • isWiggling read-only property to check if collection view is currently moving a cell
  • Notifications at start and end of move

Here is the code

//
//  WigglingCollectionView.swift
//
//  Created by Ary Tebeka on 19/07/15.
//  Copyright © 2015 Ary Tebeka. All rights reserved.
//

import UIKit

let WigglingCollectionViewStartedMovingNotification = "WigglingCollectionView.StartedMoving"
let WigglingCollectionViewFinishedMovingNotification = "WigglingCollectionView.FinishedMoving"

class WigglingCollectionView: UICollectionView {

    var isWiggling: Bool { return _isWiggling }
    
    private var _isWiggling = false

    override func beginInteractiveMovementForItemAtIndexPath(indexPath: NSIndexPath) -> Bool {
        startWiggle()
        NSNotificationCenter.defaultCenter().postNotificationName(WigglingCollectionViewStartedMovingNotification, object: self)
        return super.beginInteractiveMovementForItemAtIndexPath(indexPath)
    }
    
    override func endInteractiveMovement() {
        super.endInteractiveMovement()
        stopWiggle()
        NSNotificationCenter.defaultCenter().postNotificationName(WigglingCollectionViewFinishedMovingNotification, object: self)
    }
    
    // Wiggle code below from https://github.com/LiorNn/DragDropCollectionView
    
    private func startWiggle() {
        for cell in self.visibleCells() {
            addWiggleAnimationToCell(cell as UICollectionViewCell)
        }
        _isWiggling = true
    }
    
    private func stopWiggle() {
        for cell in self.visibleCells() {
            cell.layer.removeAllAnimations()
        }
        _isWiggling = false
    }
    
    private func addWiggleAnimationToCell(cell: UICollectionViewCell) {
        CATransaction.begin()
        CATransaction.setDisableActions(false)
        cell.layer.addAnimation(rotationAnimation(), forKey: "rotation")
        cell.layer.addAnimation(bounceAnimation(), forKey: "bounce")
        CATransaction.commit()
    }
    
    private func rotationAnimation() -> CAKeyframeAnimation {
        let animation = CAKeyframeAnimation(keyPath: "transform.rotation.z")
        let angle = CGFloat(0.04)
        let duration = NSTimeInterval(0.1)
        let variance = Double(0.025)
        animation.values = [angle, -angle]
        animation.autoreverses = true
        animation.duration = self.randomizeInterval(duration, withVariance: variance)
        animation.repeatCount = Float.infinity
        return animation
    }
    
    private func bounceAnimation() -> CAKeyframeAnimation {
        let animation = CAKeyframeAnimation(keyPath: "transform.translation.y")
        let bounce = CGFloat(3.0)
        let duration = NSTimeInterval(0.12)
        let variance = Double(0.025)
        animation.values = [bounce, -bounce]
        animation.autoreverses = true
        animation.duration = self.randomizeInterval(duration, withVariance: variance)
        animation.repeatCount = Float.infinity
        return animation
    }
    
    private func randomizeInterval(interval: NSTimeInterval, withVariance variance:Double) -> NSTimeInterval {
        let random = (Double(arc4random_uniform(1000)) - 500.0) / 500.0
        return interval + variance * random;
    }

}

Apple Watch ClockKit: Reload Complications Placeholder Templates

I just posted a radar to suggest an enhancement to the way ClockKit currently handles the placeholder templates for the Apple Watch complications.

Here is the text I submitted:

I am developing a watch app with complications that can be customised by the user. It would be nice for users to see a placeholder according to the data and format they customised. Currently templates are loaded only once at app install. A great improvement would be an API call from the iPhone companion app to request reloading of all (or some) of the complication templates.

Swift: should a function Throw or return an Optional?

Since Swift 2.0 we now have two ways for a function to fail:

  • It can return an Optional
  • Or it can Throw

Let’s use a very simple example: a function to return the square root of a number.
It is supposed to fail if the number was negative of course.

Return an Optional

func sqrt1(number: Float) -> Float? {
    guard(number >= 0) else {
        return nil
    }
    return sqrt(number)
}

func use1() {
    if let result = sqrt1(17) {
        print(result)
    } else {
        print("Error")
    }
}

Throw an exception

func sqrt2(number: Float) throws -> Float {
    guard(number >= 0) else {
        throw SqrtErrors.negativeNumber
    }
    return sqrt(number)
}

func use2() {
    do {
        let result = try sqrt2(17)
        print(result)
    } catch  {
        print("Error")
    }
}

Which style do you prefer? The obvious advantage of “throw” is that we get an ErrorType with information on the reason of the failure.
On the other side, Optional results can be chained and this can make it a much more convenient choice when we don’t care about the reason for failure.