Git Product home page Git Product logo

swiftsnippets's Introduction

Swift Snippets

❤️ Support my app ❤️

❤️❤️😇😍🤘❤️❤️

A collection of Swift snippets to be used in Xcode

Usage

  • swifttrycatch
do {
  try <#code#>
} catch <#errortype#> {
  <#code#>
} catch <#errortype#> {
  <#code#>
}
  • swiftassociatedobject
private struct AssociatedKeys {
  static var <#name#> = "<#name#>"
}

var <#name#>: String? {
  get {
    return objc_getAssociatedObject(self, &AssociatedKeys.<#name#>) as? String
  }

  set {
    if let newValue = newValue {
      objc_setAssociatedObject(self, &AssociatedKeys.<#name#>, newValue as String?,
        .OBJC_ASSOCIATION_RETAIN_NONATOMIC
      )
    }
  }
}
  • swiftavailable
@available(iOS 7, *)
  • swiftcheckavailability
if #available(iOS 9, *) {
    <#API available statements#>
} else if #available(macOS 10.12, *) {
    <#API available statements#>
} else {
    <#fallback statements#>
}
  • swiftcheckversion
#if swift(>=3.0)
    <#code#>
#elseif swift(>=2.2)
    <#code#>
#elseif swift(>=2.1)
    <#code#>
#endif
  • swiftcheckplatform
#if os(iOS) || os(tvOS)
  <#code#>
#elseif os(watchOS)
  <#code#>
#elseif os(OSX)
  <#code#>
#endif
  • swiftdispatchafter
DispatchQueue.main.asyncAfter(deadline: .now() + <#time#>) {
  <#code#>
}
  • swiftdispatchasync
DispatchQueue.global(qos: .background).async {
  <#code#>
}
  • swiftdispatchonce
let <#name#>: <#type#> = {
  return <#code#>
}()
  • swiftinitcoder
public required init?(coder aDecoder: NSCoder) {
  fatalError("init(coder:) has not been implemented")
}
  • swiftmark
// MARK: - <#section#>
  • swiftsubscript
subscript(<#name#>: <#type#>) -> <#type#> {
  get {
    return <#value#>
  }
  set(newValue) {
      <#code#>
  }
}
  • swiftguardself
guard let `self` = self else {
  return
}
  • swiftuitableviewdatasource
func numberOfSections(in tableView: UITableView) -> Int {
 return <#count#>
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 return <#count#>
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 <#code#>
}
  • swiftuicollectionviewdatasource
func numberOfSections(in collectionView: UICollectionView) -> Int {
  return <#count#>
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  return <#count#>
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  <#code#>
}
  • swiftuipickerviewdatasource
func numberOfComponents(in pickerView: UIPickerView) -> Int {
  return <#count#>
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
  return <#count#>
}

Installation

Manual

Drag codesnippet files from Snippets into /Library/Developer/Xcode/UserData/CodeSnippets

Automatic

Run this in your terminal

curl -fsSL https://raw.githubusercontent.com/hyperoslo/SwiftSnippets/master/install.sh | sh

Author

Credit

License

SwiftSnippets is available under the MIT license. See the LICENSE file for more info.

swiftsnippets's People

Contributors

hvsw avatar onmyway133 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

swiftsnippets's Issues

Swift 3 branch

Hey @hyperoslo, I'd be cool to add a Swift 3 branch so we could make the necessary changes over there since a lot of methods changed, like the dispatch_async, for example.

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.