Git Product home page Git Product logo

swift_example_project's Introduction

swift_example_project

stepy by step to create a swift project with swiftpm tool

Step 1: init the swift project

swift package init --type executable

Step 2: import the package which the project needed

Edit the Package.Swift file

Origin file content show like this:

// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "swift_example_project",
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .executableTarget(
            name: "swift_example_project"),
    ]
)

import SwifterSwift package

New Package.swift file show like this:

// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "swifter",
    dependencies: [
        .package(url: "https://github.com/SwifterSwift/SwifterSwift.git", from: "6.0.0")
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .executableTarget(
            name: "swifter",
            dependencies: ["SwifterSwift"]),
    ]
)

Step 3: update the project

swift package update

Step 4: edit the code file, import specify package, such as SwifterSwift

// The Swift Programming Language
// https://docs.swift.org/swift-book

import SwifterSwift
import Foundation

// Add 1 month to current date
var date = Date()
// date.add(.month, value: 1)

// print("today:",date)

// Return date at the beginning of current day
let res = date.beginning(of: .hour)
print("\(date) beginning of day:",res!)


// // Return date at the end of current month
let r2 = Date().end(of: .month)
print("end of month:",r2!)

Step 5: run the project

swift run

the whole work flow is over here.

End.

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.