Skip to content
This repository was archived by the owner on Aug 18, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions brain-marks.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
91C8958926228D1500689196 /* Tweet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91C8958826228D1500689196 /* Tweet.swift */; };
FFEBBB3A26223F75000F475F /* brain_marksApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEBBB3926223F75000F475F /* brain_marksApp.swift */; };
FFEBBB3C26223F75000F475F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEBBB3B26223F75000F475F /* ContentView.swift */; };
FFEBBB3E26223F7E000F475F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FFEBBB3D26223F7E000F475F /* Assets.xcassets */; };
Expand Down Expand Up @@ -34,6 +35,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
91C8958826228D1500689196 /* Tweet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tweet.swift; sourceTree = "<group>"; };
FFEBBB3626223F75000F475F /* brain-marks.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "brain-marks.app"; sourceTree = BUILT_PRODUCTS_DIR; };
FFEBBB3926223F75000F475F /* brain_marksApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = brain_marksApp.swift; sourceTree = "<group>"; };
FFEBBB3B26223F75000F475F /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -74,6 +76,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
91C8958726228CF600689196 /* Model */ = {
isa = PBXGroup;
children = (
91C8958826228D1500689196 /* Tweet.swift */,
);
path = Model;
sourceTree = "<group>";
};
FFEBBB2D26223F75000F475F = {
isa = PBXGroup;
children = (
Expand All @@ -97,6 +107,7 @@
FFEBBB3826223F75000F475F /* brain-marks */ = {
isa = PBXGroup;
children = (
91C8958726228CF600689196 /* Model */,
FFEBBB3926223F75000F475F /* brain_marksApp.swift */,
FFEBBB3B26223F75000F475F /* ContentView.swift */,
FFEBBB3D26223F7E000F475F /* Assets.xcassets */,
Expand Down Expand Up @@ -283,6 +294,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
91C8958926228D1500689196 /* Tweet.swift in Sources */,
FFEBBB3C26223F75000F475F /* ContentView.swift in Sources */,
FFEBBB7626226A39000F475F /* Secrets.swift in Sources */,
FFEBBB3A26223F75000F475F /* brain_marksApp.swift in Sources */,
Expand Down Expand Up @@ -444,7 +456,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"brain-marks/Preview Content\"";
DEVELOPMENT_TEAM = Y535846H6P;
DEVELOPMENT_TEAM = U23VWM3L5A;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "brain-marks/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
Expand All @@ -466,7 +478,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"brain-marks/Preview Content\"";
DEVELOPMENT_TEAM = Y535846H6P;
DEVELOPMENT_TEAM = U23VWM3L5A;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "brain-marks/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
Expand Down
50 changes: 48 additions & 2 deletions brain-marks/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import SwiftUI

struct ContentView: View {
var body: some View {
Text("Hello, world!")
.padding()
Button("hey",action:{
get()
})
}
}

Expand All @@ -19,3 +20,48 @@ struct ContentView_Previews: PreviewProvider {
ContentView()
}
}
extension ContentView{
func get(){
var request = URLRequest(url: URL(string: "https://api.twitter.com/2/tweets/1380990780248973312")!,timeoutInterval: Double.infinity)

request.addValue("Bearer Add_Bearer_Token", forHTTPHeaderField: "Authorization")

request.httpMethod = "GET"

let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))

return
}

if let response = response as? HTTPURLResponse{
guard (200 ... 299) ~= response.statusCode else {
print("Status code :- \(response.statusCode)")
return
}

do{
if error == nil{
let result = try JSONDecoder().decode(ResponseModel.self, from: data)
//update UI
print(result)

}

DispatchQueue.main.async {
//update UI
}

}catch{
print("\(error.localizedDescription)")
}

}


}
task.resume()
}
}

19 changes: 19 additions & 0 deletions brain-marks/Model/Tweet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Tweet.swift
// brain-marks
//
// Created by PRABALJIT WALIA on 11/04/21.
//

import Foundation
struct TweetModel:Codable{
let id:String
let text:String
// init(from decoder: Decoder) throws {
// self.id = 20
// self.text = "setting up"
// }
}
struct ResponseModel:Codable{
let data:TweetModel
}