Skip to content

Commit

Permalink
Project Added
Browse files Browse the repository at this point in the history
  • Loading branch information
adeeltahir98 committed Jul 30, 2024
1 parent 295b046 commit 1a116b4
Show file tree
Hide file tree
Showing 41 changed files with 2,957 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ViperDemo/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'ViperDemo' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for ViperDemo
pod 'ReachabilitySwift'
pod 'SDWebImage'
end
676 changes: 676 additions & 0 deletions ViperDemo/ViperDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>ViperDemo.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
</dict>
</dict>
</dict>
</plist>
36 changes: 36 additions & 0 deletions ViperDemo/ViperDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AppDelegate.swift
// ViperDemo
//
// Created by Adeel Tahir on 17/12/2022.
//

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions ViperDemo/ViperDemo/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
21 changes: 21 additions & 0 deletions ViperDemo/ViperDemo/Assets.xcassets/cover.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "cover.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "favpng_avatar-user-profile-business.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "pngegg.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions ViperDemo/ViperDemo/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
15 changes: 15 additions & 0 deletions ViperDemo/ViperDemo/Extensions/Encodable+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Encodable+Extension.swift
// ViperDemo
//
// Created by Adeel Tahir on 12/17/22.
//

import Foundation

extension Encodable {
var dictionary: [String: Any]? {
guard let data = try? JSONEncoder().encode(self) else { return nil }
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? [String: Any] }
}
}
23 changes: 23 additions & 0 deletions ViperDemo/ViperDemo/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
15 changes: 15 additions & 0 deletions ViperDemo/ViperDemo/Managers/APIManager/API.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// API.swift
// ViperDemo
//
// Created by Adeel Tahir on 12/17/22.
//

import Foundation

struct API {
static let kSearchUsers = "https://api.github.com/search/users?q={username}+in:login&type=Users&per_page={maxItems}&page={pageNumber}"
static let kUserDetails = "https://api.github.com/users/{username}"
static let kUserReposAPI = "https://api.github.com/users/{username}/repos"
static let kUserFollowersAPI = "https://api.github.com/users/{username}/followers"
}
99 changes: 99 additions & 0 deletions ViperDemo/ViperDemo/Managers/APIManager/APIManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// ViperDemo
//
// Created by Adeel Tahir on 12/17/22.
//

import Foundation

class APIGeneric<response: Codable> {

static func fetchRequest(apiURL:String, completion: @escaping (Resource<response>) -> Void) {
print(apiURL)

var resource = Resource<response>(data: nil, error: nil, state: .loading)
completion(resource)

NetworkService.shared.loadNetworkData(requestType: .get, fromUrl: apiURL, parameters: [:]) { networkResponse in
if let err = networkResponse.error {
resource.error = err
} else {
do {
if let data = networkResponse.data {
let jsonResponse = try JSONSerialization.jsonObject(with: data, options: [])
print(jsonResponse)

if (jsonResponse as? NSArray)?.count == 0 {
resource.error = .serverSideError("No Data Found.")
}
else {
if networkResponse.statusCode == 200 {
let responseModel = try JSONDecoder().decode(response.self, from: data)
resource.data = responseModel
} else {
let responseModel = try JSONDecoder().decode(NotSuccessModel.self, from: data)
resource.error = .serverSideError(responseModel.message ?? "")
}
}
}
else {
resource.state = .failure
}
} catch let error {
resource.error = .serverSideError(error.localizedDescription)
}
}

completion(resource)
}
}
}

class PostAPIGeneric<request: Codable,response: Codable> {

static func postRequest(apiURL:String, requestType: RequestType = .post ,requestModel:request, completion: @escaping (Resource<response>) -> Void) {

print(apiURL)

var resource = Resource<response>(data: nil, error: nil, state: .loading)
completion(resource)

guard let parameters = requestModel.dictionary else {
resource.state = .failure
completion(resource)
return
}

NetworkService.shared.loadNetworkData(requestType: .get, fromUrl: apiURL, parameters: parameters) { networkResponse in
if let err = networkResponse.error {
resource.error = err
} else {
do {
if let data = networkResponse.data {
let jsonResponse = try JSONSerialization.jsonObject(with: data, options: [])
print(jsonResponse)

if (jsonResponse as? NSArray)?.count == 0 {
resource.error = .serverSideError("No Data Found.")
}
else {
if networkResponse.statusCode == 200 {
let responseModel = try JSONDecoder().decode(response.self, from: data)
resource.data = responseModel
} else {
let responseModel = try JSONDecoder().decode(NotSuccessModel.self, from: data)
resource.error = .serverSideError(responseModel.message ?? "")
}
}
}
else {
resource.state = .failure
}
} catch let error {
resource.error = .serverSideError(error.localizedDescription)
}
}

completion(resource)
}
}
}
Loading

0 comments on commit 1a116b4

Please sign in to comment.