Giter VIP home page Giter VIP logo

networkmanager's Introduction

NetworkManager-SwiftUI

NetworkManager is a simple and lightweight class written in SwiftUI to handle all of your network state management in your iOS projects. It provides a clean and easy-to-use interface for monitoring network connectivity, and updating your app's UI accordingly.

Requirements

swift v5.3+ platform iOS deployment target iOS 13+

Features

Here's the list of the awesome features NetworkManager has:

  • Simple and easy-to-use interface
  • Automatically updates the UI when the network state changes
  • Monitors the network state in real-time.
  • Provides an observable object for binding to in SwiftUI.
  • Can be easily integrated with other parts of your app to handle network-related logic.

Installation

To install NetworkStateManager, simply add the NetworkStateManager.swift file to your Xcode project and enjoy ๐Ÿ™‚.

How to use

First create a NetworkState object and add it as an environmentObject to your root View.

import SwiftUI

@main
struct NetworkStateDemoApp: App {
    
    let networkState = NetworkState()
    
    var body: some Scene {
        WindowGroup {
            ContentView().environmentObject(networkState)
        }
    }
}

Use the isConnected variable to render out your UI. For more understanding download and run the project.

import SwiftUI

struct ContentView: View {
    
    @EnvironmentObject var networkManager: NetworkManager
    
    var body: some View {
        VStack(spacing: 20) {
            Image(systemName: networkManager.isConnected ? "wifi" : "wifi.slash").font(.largeTitle)
            
            let status = networkManager.isConnected == true ? "Online" : "Offline"
            Text("You are \(status) and connected to \(networkManager.networkType?.rawValue ?? "")")
                .foregroundColor(.green)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Customization

You can also customize the behavior of NetworkManager by subclassing it and overridding the methods you want to change.

Contribution

Your contributions and suggestions are always welcome. Feel free to open an issue or create a pull request.

Note

This is just a sample README.md, you can add more details, examples and so on based on the actual implementation of your NetworkManager.swift class.

networkmanager's People

Contributors

devendrabhumca12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

hebaomar94

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.