Skip to content

Commit

Permalink
Merge pull request #2 from Kyoya-prog/topic/fix_bug
Browse files Browse the repository at this point in the history
バグ修正
  • Loading branch information
Kyoya-prog authored Jun 21, 2021
2 parents 60066b5 + 228cdc2 commit baae438
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 47 deletions.
12 changes: 12 additions & 0 deletions iOSEngineerCodeCheck.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
3DE652C626802CFC005396F3 /* SearchRepositoryModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DE652C526802CFC005396F3 /* SearchRepositoryModel.swift */; };
BF0A658D244F2A3B00280FA6 /* ViewController2.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0A658C244F2A3B00280FA6 /* ViewController2.swift */; };
BFD945DF244DC5E80012785A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFD945DE244DC5E80012785A /* AppDelegate.swift */; };
BFD945E1244DC5E80012785A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFD945E0244DC5E80012785A /* SceneDelegate.swift */; };
Expand Down Expand Up @@ -36,6 +37,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
3DE652C526802CFC005396F3 /* SearchRepositoryModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchRepositoryModel.swift; sourceTree = "<group>"; };
BF0A658C244F2A3B00280FA6 /* ViewController2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController2.swift; sourceTree = "<group>"; };
BFD945DB244DC5E80012785A /* iOSEngineerCodeCheck.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSEngineerCodeCheck.app; sourceTree = BUILT_PRODUCTS_DIR; };
BFD945DE244DC5E80012785A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -78,6 +80,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
3DE652C426802CDC005396F3 /* Model */ = {
isa = PBXGroup;
children = (
3DE652C526802CFC005396F3 /* SearchRepositoryModel.swift */,
);
path = Model;
sourceTree = "<group>";
};
BFD945D2244DC5E80012785A = {
isa = PBXGroup;
children = (
Expand All @@ -101,6 +111,7 @@
BFD945DD244DC5E80012785A /* iOSEngineerCodeCheck */ = {
isa = PBXGroup;
children = (
3DE652C426802CDC005396F3 /* Model */,
BFD945DE244DC5E80012785A /* AppDelegate.swift */,
BFD945E0244DC5E80012785A /* SceneDelegate.swift */,
BFD945E2244DC5E80012785A /* ViewController.swift */,
Expand Down Expand Up @@ -265,6 +276,7 @@
BFD945E3244DC5E80012785A /* ViewController.swift in Sources */,
BF0A658D244F2A3B00280FA6 /* ViewController2.swift in Sources */,
BFD945DF244DC5E80012785A /* AppDelegate.swift in Sources */,
3DE652C626802CFC005396F3 /* SearchRepositoryModel.swift in Sources */,
BFD945E1244DC5E80012785A /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
55 changes: 33 additions & 22 deletions iOSEngineerCodeCheck/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="wFt-RI-uk4">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="wFt-RI-uk4">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -14,22 +16,22 @@
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="Fpt-Ev-QNW">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<searchBar key="tableHeaderView" contentMode="redraw" id="6rq-CD-Hob">
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<textInputTraits key="textInputTraits"/>
</searchBar>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="Repository" textLabel="V66-xN-aKy" detailTextLabel="E7E-kF-FF6" style="IBUITableViewCellStyleValue1" id="jZX-YR-etd">
<rect key="frame" x="0.0" y="72" width="414" height="43.5"/>
<rect key="frame" x="0.0" y="68.5" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="jZX-YR-etd" id="k29-jL-IM1">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="V66-xN-aKy">
<rect key="frame" x="20" y="12" width="33.5" height="20.5"/>
<rect key="frame" x="20" y="12" width="33" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand Down Expand Up @@ -76,63 +78,64 @@
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4q1-pG-WSB">
<rect key="frame" x="181" y="547.5" width="52.5" height="33.5"/>
<rect key="frame" x="184" y="547.5" width="46.5" height="30"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" systemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" distribution="equalSpacing" alignment="top" translatesAutoresizingMaskIntoConstraints="NO" id="oOe-O2-3RS">
<rect key="frame" x="20" y="600" width="374" height="120"/>
<stackView opaque="NO" contentMode="scaleToFill" distribution="equalSpacing" alignment="top" translatesAutoresizingMaskIntoConstraints="NO" id="oOe-O2-3RS">
<rect key="frame" x="20" y="600" width="374" height="106"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Language" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="s3M-QO-Kom">
<rect key="frame" x="0.0" y="0.0" width="79" height="20.5"/>
<rect key="frame" x="0.0" y="0.0" width="66.5" height="17"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" systemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="0gb-01-GLC">
<rect key="frame" x="309" y="0.0" width="65" height="120"/>
<rect key="frame" x="320.5" y="0.0" width="53.5" height="106"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Stars" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0WZ-UA-R8O">
<rect key="frame" x="0.0" y="0.0" width="65" height="18"/>
<rect key="frame" x="0.0" y="0.0" width="53.5" height="14.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" systemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Wathcers" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lQC-lo-IqN">
<rect key="frame" x="0.0" y="34" width="65" height="18"/>
<rect key="frame" x="0.0" y="30.5" width="53.5" height="14.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" systemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Forks" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ZMv-4f-X2V">
<rect key="frame" x="0.0" y="68" width="65" height="18"/>
<rect key="frame" x="0.0" y="61" width="53.5" height="14.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" systemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Issues" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dzg-K8-h2L">
<rect key="frame" x="0.0" y="102" width="65" height="18"/>
<rect key="frame" x="0.0" y="91.5" width="53.5" height="14.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" systemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="srK-fe-i1b"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="Iim-eb-8Ad" firstAttribute="leading" secondItem="srK-fe-i1b" secondAttribute="leading" constant="20" id="EMR-2C-CyU"/>
<constraint firstItem="oOe-O2-3RS" firstAttribute="top" secondItem="4q1-pG-WSB" secondAttribute="bottom" constant="22.5" id="EeR-wT-hN5"/>
<constraint firstItem="4q1-pG-WSB" firstAttribute="top" secondItem="Iim-eb-8Ad" secondAttribute="bottom" constant="28" id="G2L-KM-330"/>
<constraint firstItem="4q1-pG-WSB" firstAttribute="centerX" secondItem="Iim-eb-8Ad" secondAttribute="centerX" id="Ght-Nb-HEu"/>
<constraint firstItem="srK-fe-i1b" firstAttribute="trailing" secondItem="Iim-eb-8Ad" secondAttribute="trailing" constant="20" id="IgU-EN-fM3"/>
<constraint firstItem="oOe-O2-3RS" firstAttribute="width" secondItem="Iim-eb-8Ad" secondAttribute="width" id="dPu-j0-Myp"/>
<constraint firstItem="oOe-O2-3RS" firstAttribute="centerX" secondItem="4q1-pG-WSB" secondAttribute="centerX" id="kVV-YK-ePr"/>
<constraint firstItem="Iim-eb-8Ad" firstAttribute="centerY" secondItem="srK-fe-i1b" secondAttribute="centerY" multiplier="0.7" id="ruB-l0-4VM"/>
</constraints>
<viewLayoutGuide key="safeArea" id="srK-fe-i1b"/>
</view>
<navigationItem key="navigationItem" id="J6o-vL-S1z"/>
<connections>
Expand Down Expand Up @@ -166,4 +169,12 @@
<point key="canvasLocation" x="-1417" y="137"/>
</scene>
</scenes>
<resources>
<systemColor name="darkTextColor">
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
40 changes: 40 additions & 0 deletions iOSEngineerCodeCheck/Model/SearchRepositoryModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
struct SearchRepositories: Codable {

let items: [Repository]

private enum CodingKeys: String, CodingKey {
case items
}
}

struct Repository: Codable {

let id: Int
let fullName: String
let language: String
let stargazersCount: Int
let watchersCount: Int
let forksCount: Int
let openIssuesCount: Int

let owner: Owner

private enum CodingKeys: String, CodingKey {
case id = "id"
case fullName = "full_name"
case language = "language"
case stargazersCount = "stargazers_count"
case watchersCount = "watchers_count"
case forksCount = "forks_count"
case openIssuesCount = "open_issues_count"
case owner = "owner"
}
}

struct Owner: Codable {
let avatarUrl: String

private enum CodingKeys: String, CodingKey {
case avatarUrl = "avatar_url"
}
}
22 changes: 12 additions & 10 deletions iOSEngineerCodeCheck/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ViewController: UITableViewController, UISearchBarDelegate {

@IBOutlet weak var SchBr: UISearchBar!

var repo: [[String: Any]]=[]
var repo: [Repository]=[]

var task: URLSessionTask?
var word: String!
Expand Down Expand Up @@ -42,13 +42,15 @@ class ViewController: UITableViewController, UISearchBarDelegate {

if word.count != 0 {
url = "https://api.github.com/search/repositories?q=\(word!)"
task = URLSession.shared.dataTask(with: URL(string: url)!) { (data, res, err) in
if let obj = try! JSONSerialization.jsonObject(with: data!) as? [String: Any] {
if let items = obj["items"] as? [[String: Any]] {
self.repo = items
DispatchQueue.main.async {
self.tableView.reloadData()
}
task = URLSession.shared.dataTask(with: URL(string: url)!) { [weak self] (data, res, err) in
guard let data = data,err == nil else {
print(err!)
return
}
if let fetchedRepos = try? JSONDecoder().decode(SearchRepositories.self, from: data){
self?.repo = fetchedRepos.items
DispatchQueue.main.async {[weak self] in
self?.tableView.reloadData()
}
}
}
Expand All @@ -75,8 +77,8 @@ class ViewController: UITableViewController, UISearchBarDelegate {

let cell = UITableViewCell()
let rp = repo[indexPath.row]
cell.textLabel?.text = rp["full_name"] as? String ?? ""
cell.detailTextLabel?.text = rp["language"] as? String ?? ""
cell.textLabel?.text = rp.fullName
cell.detailTextLabel?.text = rp.language
cell.tag = indexPath.row
return cell

Expand Down
Loading

0 comments on commit baae438

Please sign in to comment.