Giter Site home page Giter Site logo

jintin / swimat Goto Github PK

View Code? Open in Web Editor NEW
1.6K 35.0 90.0 3.52 MB

An Xcode formatter plug-in to format your swift code.

Home Page: https://jintin.github.io/Swimat/

License: MIT License

Swift 98.39% HTML 1.61%
swift xcode-plugin formatter xcode-extension xcode swimat

swimat's Introduction

Swimat

Build Status Codacy Badge Awesome

github homebrew-cask

Swimat is an Xcode plug-in to format your Swift code.

Preview

Installation

There are three way to install.

  1. Install via homebrew-cask
# Homebrew previous version
brew cask install swimat
# Homebrew latest version
brew install --cask swimat
  1. Download the App directly.
    https://github.com/Jintin/Swimat/releases/download/1.7.0/Swimat.zip

  2. Clone and archive to Mac App by yourself.

Usage

After installation, you should open the Swimat.app once to make the functionality works.

In the Xcode menu click [Editor] -> [Swimat] -> [Format] then the current active file will reformat.

You can also create a hot-key in [Xcode] -> [Preferences..] -> [Key Bindings], if you don't have any prefernce you can set as + + L.

TroubleShooting

Check [System Preferences] -> [Extensions] -> [Xcode Source Editor] -> [Swimat] is checked.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Jintin/Swimat.

License

The module is available as open source under the terms of the MIT License.

swimat's People

Contributors

ams-twelker avatar bdrelling avatar firetrap avatar hyperphonic0 avatar ijaureguialzo avatar jintin avatar jirapornpraneet avatar mavideniz avatar noah0316 avatar reidmweber avatar saagarjha avatar sampayo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swimat's Issues

自动补空白行空格

xcode自己的重新空格化总是会添加空格的
image

所以要么再调用xcode的一次,或者就补上去呢?这样空格的好处是下一行的时候保留了tab位

bug of generics syntax

hello!

I found a bug.

  • before
class test {
    func function<T:classA where T:protcolA>() -> T {
        return T()
    }
}

class classA {
    required init() {}
}

protocol protcolA {
}
  • after
class test {
    func function<T:classAwhereT:protcolA>() -> T {
        return T()
    }
}

class classA {
    required init() {}
}

protocol protcolA {
}

Ternary Operator Issue

self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? self.bottomBorderColor?.CGColor : self.detailLabelActiveColor?.CGColor

gets turned into

self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? self.bottomBorderColor ? .CGColor : self.detailLabelActiveColor?.CGColor

which doesnt compile

if let as? issue

for set in sets { if let setDict = set as? [String: AnyObject], let workoutSet = MutableWorkoutSet.fromDictionary(setDict) {

becomes

for set in sets { if let setDict = set as ? [String : AnyObject], let workoutSet = MutableWorkoutSet.fromDictionary(setDict) {

Auto-template blocks are broken on format

When you override an existing function, there's a little label that comes up that says "code". Similarly, parameters for functions you're trying to autocomplete would have a block you can tab over to or click into to finish.

When formatting with Swimat, it converts those blocks to something like the following: < #code# >.

In line if

        let optional: String? = "asd"
        var text = optional != nil
            ? String(format: "%d %@",
            0, 
            "asdkjlasdl"
             )
            : "asd"

should be:

        let optional: String? = "test"
        var text = optional != nil
            ? String(format: "%d %@",
                 0, 
                 "asdkjlasdl"
             )
            : "asd"

Xcode 7.3b3 Compatibility

Hi,

are there any known issues with Xcode 7.3b3? The UUID is E71C2CFE-BFD8-4044-8F06-00AE685A406C - could you please add it?

Thanks!

in-line if

if you insert

        let optional: String?
        let a = optional != nil
            ?"true"
            :"false"

it will not auto-indent to the expected: (space between ? and "true")

        let optional: String?
        let a = optional != nil
            ? "true"
            : "false"

Improper formatting of ternary operator

Love the plugin. Keep up the good work.

Problem example:

let sourceControl = (collectionView == firstStateCollectionView) ? controlsArray[indexPath.row] : source.way2DeviceControl[indexPath.row]

turns into:

let sourceControl = (collectionView == firstStateCollectionView)? controlsArray[indexPath.row]: source.way2DeviceControl[indexPath.row]

If parens are removed from the equality term, then the question mark is fine, but the colon is still mis-placed.

Configurable format rule

There's a number of linting tools now available for Swift, such as SwiftLint and Tailor. It would be great if Swimat had the option of using one of these as a canonical style guide. The chosen style should be configurable on a per user and per project basis.

Functions calls with multiple lines

it should be

        let mutableText = NSMutableAttributedString()
        mutableText.appendAttributedString(
                NSAttributedString(
                       string: NSLocalizedString("localized", comment: "comment"),
                       attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14)]
                 )
         )

instead of:

        let mutableText = NSMutableAttributedString()
        mutableText.appendAttributedString(
            NSAttributedString(
            string: NSLocalizedString("localized", comment: "comment"),
            attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14)]
        )
        )

Swimat indents empty lines

Hi,

first of all I'd like to thank you for your great work!

Unfortunately Swimat seems to indent empty lines if the line after is indented.
Swimat indents empty lines

It would be great if Swimat could remove any unnecessary whitespace in empty lines. This would increase the code quality.

Best regards

Format on save

Is it possible to configure the plugin to format the files on save? It would remove the need to remember to apply the formatting and keep the formatting consistent for an entire project and team without anyone having to think about it.

Invalid formatting when Swift code contains C

Swimat formats the following code:

import Foundation

public final class Server {
    private var sock: Int32
    private var addr: sockaddr_in?
    private var bufferSize = 1024

    public init?(_ port: UInt16) {
        sock = socket(AF_INET, Int32(SOCK_STREAM), 0)
        if sock < 0 {
            addr = nil
            return nil
        }

        // Set the option to reuse the address on the server socket
        var reuseOn: Int32 = 1
        setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseOn, socklen_t(sizeof(Int32)))

        // Set the receive buffer size on the server socket
        setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &bufferSize, socklen_t(sizeof(Int)))

        // Bind to any available interface
        addr = sockaddr_in(
            sin_len: __uint8_t(sizeof(sockaddr_in)),
            sin_family: sa_family_t(AF_INET),
            sin_port: htons(port),
            sin_addr: in_addr(s_addr: in_addr_t(0)),
            sin_zero: (0, 0, 0, 0, 0, 0, 0, 0)
        )

        let serverBind = bind(sock, sockaddr_cast(&addr), socklen_t(sizeof(sockaddr_in)))
        if serverBind >= 0 {
            print("Server started at port \(port)")
        }
    }

    public func listenAndServe() {
        if listen(sock, 10) < 0 {
            exit(1)
        }

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) {
            while true {
                let client = accept(self.sock, nil, nil)
                if client > 0 {
                    // This prevents crashes when blocking calls are pending and the app is backgrounded
                    var no_sig_pipe: Int32 = 1;
                    setsockopt(client, SOL_SOCKET, SO_NOSIGPIPE, &no_sig_pipe, socklen_t(sizeof(Int32)));

                    var buffer = [UInt8](count: self.bufferSize, repeatedValue: 0)
                    let readBytes = read(client, &buffer, self.bufferSize)

                    let data = NSData(bytes: buffer, length: readBytes)
                    if let dataString = String(data: data, encoding: NSUTF8StringEncoding) {
                        print(dataString)
                        // TODO: Parse the request
                    }

                    let msg = "Hello World"
                    let contentLength = msg.utf8.count

                    self.echo(client, "HTTP/1.1 200 OK\n")
                    self.echo(client, "Server: Swift Web Server\n")
                    self.echo(client, "Content-length: \(contentLength)\n")
                    self.echo(client, "Content-type: text-plain\n")
                    self.echo(client, "\r\n")

                    self.echo(client, msg)

                    print("Response sent: '\(msg)' - Length: \(contentLength)")

                    shutdown(client, SHUT_RDWR)
                    close(client)
                }
            }
        }
    }

    private func echo(socket: Int32, _ output: String) {
        output.withCString { (bytes) in
            send(socket, bytes, Int(strlen(bytes)), 0)
        }
    }
}

like this:

import Foundation

public final class Server {
    private var sock: Int32
    private var addr: sockaddr_in?
    private var bufferSize = 1024

    public init?(_ port: UInt16) {
        sock = socket(AF_INET, Int32(SOCK_STREAM), 0)
        if sock <0{
addr=nil
returnnil
}

//Settheoptiontoreusetheaddressontheserversocket
varreuseOn:Int32=1
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseOn, socklen_t(sizeof(Int32)))

//Setthereceivebuffersizeontheserversocket
setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &bufferSize, socklen_t(sizeof(Int)))

//Bindtoanyavailableinterface
addr=sockaddr_in(
sin_len:__uint8_t(sizeof(sockaddr_in)), 
sin_family:sa_family_t(AF_INET), 
sin_port:htons(port), 
sin_addr:in_addr(s_addr:in_addr_t(0)), 
sin_zero:(0, 0, 0, 0, 0, 0, 0, 0)
)

letserverBind=bind(sock, sockaddr_cast(&addr), socklen_t(sizeof(sockaddr_in)))
ifserverBind> = 0 {
            print("Server started at port \(port)")
        }
    }

    public func listenAndServe() {
        if listen(sock, 10) <0{
exit(1)
}

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)){
whiletrue{
letclient=accept(self.sock, nil, nil)
ifclient> 0 {
            // This prevents crashes when blocking calls are pending and the app is backgrounded
            var no_sig_pipe: Int32 = 1;
            setsockopt(client, SOL_SOCKET, SO_NOSIGPIPE, &no_sig_pipe, socklen_t(sizeof(Int32))) ;

            var buffer = [UInt8] (count: self.bufferSize, repeatedValue: 0)
            let readBytes = read(client, &buffer, self.bufferSize)

            let data = NSData(bytes: buffer, length: readBytes)
            if let dataString = String(data: data, encoding: NSUTF8StringEncoding) {
                print(dataString)
                // TODO: Parse the request
            }

            let msg = "Hello World"
            let contentLength = msg.utf8.count

            self.echo(client, "HTTP/1.1 200 OK\n")
            self.echo(client, "Server: Swift Web Server\n")
            self.echo(client, "Content-length: \(contentLength)\n")
            self.echo(client, "Content-type: text-plain\n")
            self.echo(client, "\r\n")

            self.echo(client, msg)

            print("Response sent: '\(msg)' - Length: \(contentLength)")

            shutdown(client, SHUT_RDWR)
            close(client)
        }
    }
}
}

private func echo(socket: Int32, _ output: String) {
    output.withCString {(bytes) in
        send(socket, bytes, Int(strlen(bytes)), 0)
    }
}
}

It seems to be an issue related to the lack of parentheses around the condition in the first if statement in the initializer.

I'm using Xcode 7.1.1 and installed Swimat via Alcatraz.

calling optional closure

if you try to call a optional closure like:

closure?(String(format : "asdas"))

It will format to:

closure ? (String(format : "asdas"))

Causing an error on xcode.

Wrong indentation

When you put something like
UIView.animateWithDuration(time,
delay: 0,
usingSpringWithDamping: 0.8,
initialSpringVelocity: 0,
options: [
UIViewAnimationOptions.AllowUserInteraction,
UIViewAnimationOptions.CurveEaseOut],
animations: { () -> Void in
},
completion: { (animated) -> Void in
})

it indents to (removing the spaces of options array):
UIView.animateWithDuration(time,
delay: 0,
usingSpringWithDamping: 0.8,
initialSpringVelocity: 0,
options: [
UIViewAnimationOptions.AllowUserInteraction,
UIViewAnimationOptions.CurveEaseOut],
animations: { () -> Void in
},
completion: { (animated) -> Void in
})

in-line if

let boolValue = isBool ? true: false
should indent to
let boolValue = isBool ? true : false

Run in Playgrounds

I am working in a Playground and when I click Swimat as advised in the docs, it shows a popup with a message "Only support swift now". Can you fix it please?

~ unary operator.

~ should be treated just as ++:

width &= ~(0x1) now becomes after applying Swimat width &= ~ (0x1) - notice the space before the parenthesis - this causes a compiler error: Unary operator cannot be separated from its operand.

Nil coalescing operator issue

Hi, last version of this great plugin has following issue:

var name: String?
let result = name ?? "empty"

is reformatted to

var name: String?
let result = name ? ? : "empty"

Result: compile error.

Closure indent incorrect

inputTags.forEach({ (tag) -> () in
    if tag.id == targetId {
        result = tag
    }
})

swimat ->

inputTags.forEach({ (tag) -> () in
        if tag.id == targetId {
            result = tag
        }
    })

Incorrect formatting: enums in switch and minuses

Hi! First of all I have to thank you for this plugin. It's awesome! I was really happy to know that there's this one. But there are two issues I have by using it:

  1. When I tried to format code with enums in switch statement, the plugin deleted all tabulation;
  2. If I'm using code like "let secondInt = -firstInt" plugin puts a space between "-" and the expression.
    Hope this helps to make this plugin better!

If you have any questions, please let me know and I'll try to help if I can.
Thanks!

Option to indentation?

Currently Swimat use tab to indent, when I used on my code which is indent in space, it create a big mess that combine tab and space.

Can we choose to use tab or space to indent?

format error

auto format will turn
#if (arch(i386) || arch(x86_64)) && os(iOS)
to
#if(arch(i386) || arch(x86_64)) && os(iOS)
error when build

inconsistency formatting

swipGestureRight = UISwipeGestureRecognizer (target: self , action: Selector("swipViewRight:") )
swipGestureRight = UISwipeGestureRecognizer(target: self, action: Selector("swipViewRight:"))

the above 2 lines have passed by the formate as valid, it would be a lot better if for the sack of readability the following is adopted.
swipGestureRight = UISwipeGestureRecognizer (target: self, action: Selector("swipViewRight:"))

..< and ... operators.

It seems that preferred Apple way currently is that there is a space both before and after the operator:

Correct:

1 ..< 2
1 ... 2

Incorrect:

1..<2
1 ..<2
1...2
1 ...2

I'm basing this on how the autofixer in Xcode 7.3b2 behaves - the for var i = 0; i < 3; ++i for loop style is deprecated as of Swift 2.2 and Xcode offers automatically to replace the loop with the following: for i in 0 ..< 3 - including the spaces.

Crash XCode when reformat code

I use XCode 7.1.1

Application Specific Information:
Sending doMenuAction to <Swimat: 0x7ff7d6131440> from <NSMenuItem: 0x7ff7d723e7e0 Swimat>
ProductBuildVersion: 7B1005
UNCAUGHT EXCEPTION (NSRangeException): -[__NSCFString characterAtIndex:]: Range or index out of bounds
UserInfo: (null)
Hints:
0: Sending doMenuAction to <Swimat: 0x7ff7d6131440> from <NSMenuItem: 0x7ff7d723e7e0 Swimat>
Backtrace:
0 0x00007fff8d69ae1a __exceptionPreprocess (in CoreFoundation)
1 0x0000000103ea0c6e DVTFailureHintExceptionPreprocessor (in DVTFoundation)
2 0x00007fff967eedd4 objc_exception_throw (in libobjc.A.dylib)
3 0x00007fff8d70165d +[NSException raise:format:](in CoreFoundation)
4 0x00007fff8d610de6 -[__NSCFString characterAtIndex:](in CoreFoundation)
5 0x000000010b2ab921 -[SwiftParser transformIndex:] at /Users/buxik/Library/Application Support/Alcatraz/Plug-ins/Swimat/Swimat/SwiftParser.m:99 (in Swimat)
6 0x000000010b2ab4e9 -[SwiftParser formatString:withRange:] at /Users/buxik/Library/Application Support/Alcatraz/Plug-ins/Swimat/Swimat/SwiftParser.m:19 (in Swimat)
7 0x000000010b2aaa09 -[Swimat doMenuAction] at /Users/buxik/Library/Application Support/Alcatraz/Plug-ins/Swimat/Swimat/Swimat.m:43 (in Swimat)
8 0x00007fff93df7082 _os_activity_initiate (in libsystem_trace.dylib)
9 0x00007fff9eb39811 -[NSApplication sendAction:to:from:](in AppKit)
10 0x000000010447aff9 __37-[DVTApplication sendAction:to:from:]_block_invoke (in DVTKit)
11 0x0000000103ea09ac DVTInvokeWithFailureHint (in DVTFoundation)
12 0x000000010434c827 -[DVTApplication sendAction:to:from:](in DVTKit)
13 0x00007fff9eb395ab -[NSMenuItem _corePerformAction](in AppKit)
14 0x00007fff9eb3930b -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:](in AppKit)
15 0x00007fff93df7082 _os_activity_initiate (in libsystem_trace.dylib)
16 0x00007fff9eb381f9 -[NSMenu performKeyEquivalent:](in AppKit)
17 0x00007fff9eb373a0 -[NSApplication _handleKeyEquivalent:](in AppKit)
18 0x00007fff9ea5d1ed -[NSApplication sendEvent:](in AppKit)
19 0x00000001050e3be5 -[IDEApplication sendEvent:](in IDEKit)
20 0x00007fff9e8c3d9a -[NSApplication run](in AppKit)
21 0x00007fff9e88cfbe NSApplicationMain (in AppKit)
22 0x00007fff9a1eb5ad start (in libdyld.dylib)

Performing @selector(doMenuAction) from sender NSMenuItem 0x7ff7d723e7e0
abort() called

Application Specific Signatures:
NSRangeException

Application Specific Backtrace 1:
0 CoreFoundation 0x00007fff8d69ae32 __exceptionPreprocess + 178
1 DVTFoundation 0x0000000103ea0c6e DVTFailureHintExceptionPreprocessor + 194
2 libobjc.A.dylib 0x00007fff967eedd4 objc_exception_throw + 48
3 CoreFoundation 0x00007fff8d70165d +[NSException raise:format:] + 205
4 CoreFoundation 0x00007fff8d610de6 -[__NSCFString characterAtIndex:] + 102
5 Swimat 0x000000010b2ab921 -[SwiftParser transformIndex:] + 138
6 Swimat 0x000000010b2ab4e9 -[SwiftParser formatString:withRange:] + 593
7 Swimat 0x000000010b2aaa09 -[Swimat doMenuAction] + 449
8 libsystem_trace.dylib 0x00007fff93df7082 _os_activity_initiate + 75
9 AppKit 0x00007fff9eb39811 -[NSApplication sendAction:to:from:] + 460
10 DVTKit 0x000000010447aff9 __37-[DVTApplication sendAction:to:from:]_block_invoke + 379
11 DVTFoundation 0x0000000103ea09ac DVTInvokeWithFailureHint + 83
12 DVTKit 0x000000010434c827 -[DVTApplication sendAction:to:from:] + 335
13 AppKit 0x00007fff9eb395ab -[NSMenuItem _corePerformAction] + 336
14 AppKit 0x00007fff9eb3930b -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 114
15 libsystem_trace.dylib 0x00007fff93df7082 _os_activity_initiate + 75
16 AppKit 0x00007fff9eb381f9 -[NSMenu performKeyEquivalent:] + 357
17 AppKit 0x00007fff9eb373a0 -[NSApplication _handleKeyEquivalent:] + 920
18 AppKit 0x00007fff9ea5d1ed -[NSApplication sendEvent:] + 4274
19 IDEKit 0x00000001050e3be5 -[IDEApplication sendEvent:] + 739
20 AppKit 0x00007fff9e8c3d9a -[NSApplication run] + 796
21 AppKit 0x00007fff9e88cfbe NSApplicationMain + 1176
22 libdyld.dylib 0x00007fff9a1eb5ad start + 1
23 ??? 0x0000000000000001 0x0 + 1

Protocol declaration

In swift is up to you to use ";" or not (despite I think is better to not use it)

If you do this

protocol protocolName {   
   func functionName();
}

it will format to;

protocol protocolName {   
   func functionName() ;
}

(see the space between function name and ";")

It was perfect if you can give the option to auto-delete ";" (for everything).

Line end semicolon problem

Hi,

First of all thanks for great solution for swift development!

I'm using semicolons at the end of lines, but swimat insert a space between end character and semicolon.
Can you remove this, plesase?

Edit: It insert space only, if there is ')' before ';'

Messes Swift-style documentation comments

Example:

    /// Column separator. "," by default.
    private var _columnSeparator: Character = Character(",")

When Swimat is applied, the comment gets messed up:

    // / Column separator. "," by default.
    private var _columnSeparator: Character = Character(",")

Notice the space after the initial //.

closures indentation

if you try this

  UIView.animateWithDuration(ANIMATION_TIME,
            delay: 0,
            options: [UIViewAnimationOptions.CurveLinear, UIViewAnimationOptions.AllowUserInteraction],
            animations: { () -> Void in
                 self.textfield.text = "ads"
        }) { (completed) -> Void in
                 self.textfield.text = "ads"
        }

it auto-indents (wrongly) to:

      UIView.animateWithDuration(ANIMATION_TIME,
            delay: 0,
            options: [UIViewAnimationOptions.CurveLinear, UIViewAnimationOptions.AllowUserInteraction],
            animations: { () -> Void in
            self.textfield.text = "ads"
        }) { (completed) -> Void in
            self.textfield.text = "ads"
        }

Error formatting the operator "as?"

The code

if let response: [String: String] = response.result.value as? [String: String] {

is formatted like this:

if let response: [String: String] = response.result.value as ? [String: String] {

Preprocessor macros in Swift code

Hi there,

First, thank you so much for your hard work on this plugin! It's really awesome :)

Here is a bug I found: when using preprocessor macros in a Swift file (such as #if or #else), the codebase is not indented correctly.

I have this:

#if DEBUG
print("foo")
#else
print("bar")
#endif

Instead of that:

#if DEBUG
    print("foo")
#else
    print("bar")
#endif

Nested indent not working correctly

struct Error {

    enum ResultCode: Int {
        case fail = 0, success
    }

    let message : String
    let code : Int
}

Swimat ->

struct Error {

    enum ResultCode: Int {
    case fail = 0, success
    }

    let message : String
    let code : Int
}

Unicode characters get replaced

Unicode characters (in function names or in variable names) get replaced by unrelated ascii characters when formatting.

Tested with "≤", which gets replaced by "d", and "😎", which gets replaced by "=".

Some guard statements with as are causing a space to be inserted after the ?

Before running swimat:

                case .Success(let data):
                    var dogs = [Dog]()

                    guard let data = data["data"] as? [String : AnyObject] else {
                        self?.handleError()
                        return
                    }

After running swimat:

                case .Success(let data):
                    var dogs = [Dog]()

                    guard let data = data["data"] as ? [String : AnyObject] else {
                        self?.handleError()
                        return
                    }

Notice the space inserted in the as ?

Functions with many parameters

Sometimes we want to split the declaration of a function in multiple line
like:

func controller(controller: NSFetchedResultsController,
    didChangeObject anObject: AnyObject,
    atIndexPath indexPath: NSIndexPath?,
    forChangeType type: NSFetchedResultsChangeType,
    newIndexPath: NSIndexPath?) {
        if (true) {
            doThis()
        } else {
            doThat()
        }
    }

but it wrongly do this:

func controller(controller: NSFetchedResultsController,
    didChangeObject anObject: AnyObject,
    atIndexPath indexPath: NSIndexPath?,
    forChangeType type: NSFetchedResultsChangeType,
    newIndexPath: NSIndexPath?) {
    if (true) {
        doThis()
    } else {
        doThat()
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.