Skip to content

Commit

Permalink
Updated the Access Modifiers guideline
Browse files Browse the repository at this point in the history
  • Loading branch information
htinlinn committed Apr 27, 2017
1 parent 4b2c2eb commit e4ab29c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions BestPractices.md
Expand Up @@ -133,7 +133,7 @@ var dataSource: [String] {
Be careful to use *didSet* only on an initialized property. A typical example where it is dangerous to use *didSet* is to set an IBOutlet value before the view loaded.

```swift
internal final class myViewController: UIViewController {
final class myViewController: UIViewController {

@IBOutlet weak var label: UILabel!

Expand Down Expand Up @@ -163,7 +163,7 @@ According to Apple's [documentation](https://developer.apple.com/library/ios/doc
#### Example

```swift
internal final class MyClass {
final class MyClass {

let notNilInstance = Instance()
weak var delegate: MyDelegate?
Expand Down
31 changes: 15 additions & 16 deletions README.md
Expand Up @@ -462,10 +462,10 @@ In closures, think about: should `self` be `weak` instead of `strong`? Apple has
For brackets, prefer the Xcode-default syntax of having the opening brace be on the same line as the statement opening it:

```swift
internal final class MyObject {
final class MyObject {
}

internal enum MyEnum {
enum MyEnum {
}

func doSomething() {
Expand All @@ -483,15 +483,15 @@ For type declarations, include a single space between the type declaration and t
it:

```swift
internal final class MyObject {
final class MyObject {

let value = 0
```

In addition, include a space before the type declaration's closing bracket:

```swift
internal final class MyObject {
final class MyObject {

let value = 0

Expand Down Expand Up @@ -576,7 +576,7 @@ is more Objective-C than Swift in its composition. The caller may not know which

```swift

internal enum NumberError: ErrorType {
enum NumberError: ErrorType {
case notEven
case tooLarge
}
Expand Down Expand Up @@ -611,7 +611,7 @@ The above, while slightly more cumbersome, this has well-defined benefits:
} catch {
fatalError("Unhandled error occurred.")
}

return result
```

Expand Down Expand Up @@ -640,11 +640,10 @@ In general, you should avoid `NSError` in Swift in favor of defining your own `E

## Access Modifiers

Always specify access modifiers to top-level definitions. Do not specify them otherwise unless
the modifier is needed:
Specify access modifiers only when they are needed and required by the compiler. For types and functions with the access level of `internal`, do not explicitly specify the access modifier since all entities in Swift are `internal` by default.

```swift
internal final class Object {
final class Object {

var myInt: Int

Expand All @@ -662,7 +661,7 @@ Further, the access modifier should always be presented first in the list before
// Good!
private unowned var obj: Object

internal func doSomething() {
func doSomething() {
}

// Wrong!
Expand Down Expand Up @@ -764,7 +763,7 @@ unnecessary verbiage and spacing to make code clearer.
For enum declarations, declare each enum case on a new line with its own `case` statement instead of a comma-separated list.

```swift
internal enum State {
enum State {
case open
case closed
case pending
Expand All @@ -782,7 +781,7 @@ var previousState = States.closed // Reads less clearly than the previous option
For enums with raw values, declare the raw value on the same line as its declaration:

```swift
internal enum HTTPMethod: String {
enum HTTPMethod: String {
case get = "GET"
case post = "POST"
}
Expand All @@ -791,7 +790,7 @@ internal enum HTTPMethod: String {
For any other functions or properties associated with the enum, place them after the last case item in the enum list:

```swift
internal enum State {
enum State {
case open
case closed
case pending
Expand Down Expand Up @@ -819,12 +818,12 @@ any function or variable that should not be overridden by a subclass should be d

```swift
// Not built for inheritance.
internal final class Object {
final class Object {

}

// Purposefully utilizable as a base class
internal class BaseClass {
class BaseClass {

func doSomething () {
}
Expand All @@ -835,7 +834,7 @@ internal class BaseClass {

}

internal final class SubClass: BaseClass {
final class SubClass: BaseClass {

override func doSomething() {
update()
Expand Down

0 comments on commit e4ab29c

Please sign in to comment.