swiftlint

Nested types in Swift - what is the good practice?

末鹿安然 提交于 2020-01-10 04:56:06
问题 I have a swiftlint warning that bothers me. warning: Nesting Violation: Types should be nested at most 1 level deep (nesting) However, the nesting of structs is an established programming technique, and quite a few people advocate it. Edit: Indeed @vadian points out the Swift language guide's rule: To nest a type within another type, write its definition within the outer braces of the type it supports. Types can be nested to as many levels as are required . I am aware it clashes with the use

SwiftLint: Exclude file for specific rule

孤街浪徒 提交于 2019-12-20 11:04:14
问题 I'm trying to do something like this in my .swiftlint.yml file: force_cast: severity: warning # explicitly excluded: - Dog.swift I have this code and I don't like the force_try warning I'm getting for it: let cell = tableView.dequeueReusableCellWithIdentifier(Constants.dogViewCellReuseIdentifier, forIndexPath: indexPath) as! DogViewCell I want to suppress the warning for this file by excluding this file from the rule. Is there a way to do that ? 回答1: Well, if you don't want some specific

Swift 4 Using KVO to listen to volume changes

☆樱花仙子☆ 提交于 2019-12-12 08:21:58
问题 I just updated to Swift 4 and Xcode 9 and got a (swiftlint) warning for the following code telling me that I should use KVO now: Warning: (Block Based KVO Violation: Prefer the new block based KVO API with keypaths when using Swift 3.2 or later. (block_based_kvo)) The old code: override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if keyPath == "outputVolume"{ guard let newKey = change?

Swift 4 Using KVO to listen to volume changes

无人久伴 提交于 2019-12-04 00:15:39
I just updated to Swift 4 and Xcode 9 and got a (swiftlint) warning for the following code telling me that I should use KVO now: Warning: (Block Based KVO Violation: Prefer the new block based KVO API with keypaths when using Swift 3.2 or later. (block_based_kvo)) The old code: override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if keyPath == "outputVolume"{ guard let newKey = change?[NSKeyValueChangeKey.newKey] as? NSNumber else { fatalError("Could not unwrap optional content of new key") } let

How do I use swiftlint to lint a single file?

a 夏天 提交于 2019-12-01 17:40:14
I'd like to use swiftlint to lint a single file. How do I accomplish this? Checking the docs on https://github.com/realm/SwiftLint was not helpful. You can also do this with: swiftlint --path 'path to your file' SCRIPT_INPUT_FILE_COUNT=1 SCRIPT_INPUT_FILE_0="foo.swift" swiftlint lint --use-script-input-files 来源: https://stackoverflow.com/questions/38923401/how-do-i-use-swiftlint-to-lint-a-single-file

How do I use swiftlint to lint a single file?

▼魔方 西西 提交于 2019-12-01 17:02:39
问题 I'd like to use swiftlint to lint a single file. How do I accomplish this? Checking the docs on https://github.com/realm/SwiftLint was not helpful. 回答1: You can also do this with: swiftlint --path 'path to your file' 回答2: SCRIPT_INPUT_FILE_COUNT=1 SCRIPT_INPUT_FILE_0="foo.swift" swiftlint lint --use-script-input-files 来源: https://stackoverflow.com/questions/38923401/how-do-i-use-swiftlint-to-lint-a-single-file

Nested types in Swift - what is the good practice?

孤人 提交于 2019-11-29 13:37:12
I have a swiftlint warning that bothers me. warning: Nesting Violation: Types should be nested at most 1 level deep (nesting) However, the nesting of structs is an established programming technique, and quite a few people advocate it. Edit: Indeed @vadian points out the Swift language guide 's rule: To nest a type within another type, write its definition within the outer braces of the type it supports. Types can be nested to as many levels as are required . I am aware it clashes with the use of generics , and that Xcode may become unbearably slow . It actually was (through measuring the

Difference between NSRange and NSMakeRange

我的梦境 提交于 2019-11-29 13:07:46
Is there any difference between: NSRange(location: 0, length: 5) and: NSMakeRange(0, 5) Because Swiftlint throws a warning when I use NSMakeRange , but I don't know why. Thanks for the Help :-) The only difference between them is that NSRange(location: 0, length: 5) is an initializer for NSRange while NSMakeRange(0, 5) is a function which creates a new NSRange instance (by using the same initializer inside most likely) and actually is redundant in Swift . Swift has simply inherited it from Objective-C . I would stick to the former Main difference is that NSRange(location: 0, length: 24) is

“${PODS_ROOT}/SwiftLint/swiftlint” causes “Command PhaseScriptExecution failed with a nonzero exit code” with Xcode 10

二次信任 提交于 2019-11-28 19:08:02
Updating from Xcode 10.0 beta 2 to Xcode 10.0 beta 3 I now get this error at build time for an iOS project: sourcekit: [1:connection-event-handler:10499: 0.0000] Connection interruptsourcekit: [1:updateSemanticEditorDelay:10499: 0.0007] disabling semantic editor for 10 secondssourcekit: [1:pingService:10499: 0.0007] pinging servicesourcekitten: connection to SourceKitService restored! Connection interrupted Never call this for file that sourcekitd fails.: file File+Cache.swift, line 127 /Users/Coeur/Library/Developer/Xcode/DerivedData/My-App-eloayqptodupvfhbyegtkncnhcpu/Build/Intermediates

Difference between NSRange and NSMakeRange

▼魔方 西西 提交于 2019-11-28 06:57:05
问题 Is there any difference between: NSRange(location: 0, length: 5) and: NSMakeRange(0, 5) Because Swiftlint throws a warning when I use NSMakeRange , but I don't know why. Thanks for the Help :-) 回答1: The only difference between them is that NSRange(location: 0, length: 5) is an initializer for NSRange while NSMakeRange(0, 5) is a function which creates a new NSRange instance (by using the same initializer inside most likely) and actually is redundant in Swift . Swift has simply inherited it