1. 이전 포스팅 확인하기

 

https://growingsaja.tistory.com/900

 

[Objective-C] 앱 만들기 입문 - 10 : 앱 카드 디자인 변경 - 테두리 만들기

1. 이전 포스팅 확인하기 https://growingsaja.tistory.com/899 [Objective-C] 앱 만들기 입문 - 9 : 이모티콘 및 이미지 파일 띄우기 1. 이전 포스팅 확인하기 https://growingsaja.tistory.com/898 [Objective-C] 앱 만들기 입

growingsaja.tistory.com

 

 

 

 

 

2. Binance, Bybit 암호화폐 현재가 정보 함께 받아와서 출력하기

 

 - 프로젝트 그룹, 파일 구조 및 이번에 추가되는 Binance 로고 파일

    a. Binance 정보 수집 추가

    b. 출력 위치 조금 변경

 

exchangeLogo.zip
0.01MB

 

 

 

 

 

3. default.json 수정

 

 Favorite이 아니라 Popular가 맞는 표현이라 바꾸어주었으며, 여러 거래소 및 암호화폐 등을 추가하기 위해 default.json 파일 구조를 변경했습니다.

 

{
    "favoriteList_description": [
        ["category-exchangeName", "Fullname", "codeName", "unit", "symbol", "isAvailable", "remark"],
        ["카테고리-거래소이름", "전체이름", "코드 또는 축약이름", "단위", "심볼", "활성화 여부", "비고"]
    ],
    "popularList": [
        [["spot-Bybit", "spot-Binance"], "Bitcoin", "BTC", "USDT", "BTCUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Ethereum", "ETH", "USDT", "ETHUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Cardano", "ADA", "USDT", "ADAUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Binance Coin", "BNB", "USDT", "BNBUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Solana", "SOL", "USDT", "SOLUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Ripple", "XRP", "USDT", "XRPUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Polkadot", "DOT", "USDT", "DOTUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Dogecoin", "DOGE", "USDT", "DOGEUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Chainlink", "LINK", "USDT", "LINKUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Cosmos", "ATOM", "USDT", "ATOMUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Polygon", "MATIC", "USDT", "MATICUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Stellar", "XLM", "USDT", "XLMUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Litecoin", "LTC", "USDT", "LTCUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Algorand", "ALGO", "USDT", "ALGOUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Aave", "AAVE", "USDT", "AAVEUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Filecoin", "FIL", "USDT", "FILUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Klaytn", "KLAY", "USDT", "KLAYUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Terra", "LUNA", "USDT", "LUNAUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Uniswap", "UNI", "USDT", "UNIUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Wrapped Bitcoin", "WBTC", "USDT", "WBTCUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Internet Computer", "ICP", "USDT", "ICPUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Zilliqa", "ZIL", "USDT", "ZILUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "OMG Network", "OMG", "USDT", "OMGUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Tezos", "XTZ", "USDT", "XTZUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Shiba Inu", "SHIB", "USDT", "SHIBUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Elrond", "EGLD", "USDT", "EGLDUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Axie Infinity", "AXS", "USDT", "AXSUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Decentraland", "MANA", "USDT", "MANAUSDT", "Y", ""],
        [["spot-Bybit", "spot-Binance"], "Waves", "WAVES", "USDT", "WAVESUSDT", "Y", ""]

    ]
}

 

 

 

 

 

4. PopluarAssetListVC 파일 수정

 

 Favorite이 아니라 Popular가 맞는 표현이라 바꾸어주었습니다.

 

// vim Controller/PopluarAssetListVC.h

#import <UIKit/UIKit.h>

// SecondViewController라는 이름의 뷰 컨트롤러 클래스를 선언합니다.
@interface PopluarAssetListVC : UIViewController
@property (readwrite, strong, nonatomic) UIScrollView *scrollView;
@property (readwrite, strong, nonatomic) UIStackView *stackView;
@end

 

// vim Controller/PopluarAssetListVC.m

#import <Foundation/Foundation.h>
#import "PopluarAssetListVC.h"
// api 통신 용도
#import "CRTConnect.h"
// default.json 파일 읽기 용도
#import "CRTJSONReader.h"
// 현재 시간 가져오는 용도
#import "CRTSystem.h"

@implementation PopluarAssetListVC {
    // json에서 가져온 popularList raw 데이터
    NSMutableArray *popularListFullInfo;
    NSMutableArray *popularList_bybit_spot;
    NSMutableArray *popularList_binance_spot;
    NSMutableDictionary *popularPrice_bybit_spot;
    NSMutableDictionary *popularPrice_binance_spot;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 스크롤 뷰 생성 및 초기화
    self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    self.scrollView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.scrollView];
    
    // 스택 뷰 생성 및 초기화
    self.stackView = [[UIStackView alloc] initWithFrame:self.scrollView.bounds];
    self.stackView.axis = UILayoutConstraintAxisVertical;
    self.stackView.distribution = UIStackViewDistributionEqualSpacing;
    self.stackView.alignment = UIStackViewAlignmentFill;
    self.stackView.spacing = 0;
    [self.scrollView addSubview:self.stackView];
    
    // default.json의 popularList 데이터 가져오기
    [self loadPopularList];
    
    // NSTimer 생성 및 메서드 호출 설정 - 매 특정시간마다 호출
    [NSTimer scheduledTimerWithTimeInterval:1
                                     target:self
                                   selector:@selector(updateDataAndView)
                                   userInfo:nil
                                    repeats:YES];
}

// 데이터 가져오기 및 뷰 업데이트 코드
- (void)updateDataAndView {
    // **************************************** [Start] api 콜 준비 **************************************** //
    CRTConnect* tryApiCall = [[CRTConnect alloc] init];
    // **************************************** [Start] Binance 데이터 가져오기 **************************************** //
    NSString *apiURL = @"https://api.binance.com/api/v3/ticker/price";
    [tryApiCall fetchDataFromAPI:apiURL withCompletionHandler:^(NSDictionary *jsonResponse, NSError *error) {
        if (error) {
            NSLog(@"Error: %@", error.localizedDescription);
        } else {
            // 여기에서 jsonResponse를 가공 한 후 앱에서 사용하실 수 있습니다.
            // Binance는 api return data가 array
            NSArray* resultOfApi = (NSArray *)jsonResponse;
            
            // 초기값 세팅 (안해주면 for문 돌면서 해당 dictionary에 데이터가 들어가지 않음)
            self->popularPrice_binance_spot = [@{} mutableCopy];
            // api로 받은 데이터 깔끔한 dictionary로 가공하기
            for (int i=0; i<resultOfApi.count; i++) {
                NSString *symbol = resultOfApi[i][@"symbol"];
                NSString *price = resultOfApi[i][@"price"];
                self->popularPrice_binance_spot[symbol] = price;
            }
        }
    }];
    // **************************************** [End] Binance 데이터 가져오기 **************************************** //
    // **************************************** [Start] Bybit 데이터 가져오기 **************************************** //
    apiURL = @"https://api.bybit.com/spot/quote/v1/ticker/price";
    [tryApiCall fetchDataFromAPI:apiURL withCompletionHandler:^(NSDictionary *jsonResponse, NSError *error) {
        if (error) {
            NSLog(@"Error: %@", error.localizedDescription);
        } else {
            // 여기에서 jsonResponse를 가공 한 후 앱에서 사용하실 수 있습니다.
            // result 안의 value만 추출
            NSArray* resultOfApi = jsonResponse[@"result"];
            
            // 초기값 세팅 (안해주면 for문 돌면서 해당 dictionary에 데이터가 들어가지 않음)
            self->popularPrice_bybit_spot = [@{} mutableCopy];
            // api로 받은 데이터 깔끔한 dictionary로 가공하기
            for (int i=0; i<resultOfApi.count; i++) {
                NSString *symbol = resultOfApi[i][@"symbol"];
                NSString *price = resultOfApi[i][@"price"];
                self->popularPrice_bybit_spot[symbol] = price;
            }
        }
    }];
    // **************************************** [End] Bybit 데이터 가져오기 **************************************** //
    // 메인 스레드에서만 UI 업데이트 수행
    dispatch_async(dispatch_get_main_queue(), ^{
        [self updateView];
    });
}

// default.json 파일의 popularList 데이터 읽기
-(void) loadPopularList {
    // default.json의 popularList 불러오고 정상인지 1차 확인하기 = popularList에 있는 각 element들의 개수가 같은지 확인
    CRTJSONReader *tryReadingDefaultJsonFile = [[CRTJSONReader alloc] init];
    NSDictionary *defaultData = [tryReadingDefaultJsonFile loadJSONFromFile:@"default"];
    popularListFullInfo = defaultData[@"popularList"];
    int checkDefaultJsonFile = 0;
    for (int i=0; i<popularListFullInfo.count-1; i++) {
        if ([popularListFullInfo[i] count] == [popularListFullInfo[i+1] count]) {
            checkDefaultJsonFile += 1;
        }
    }
    if (checkDefaultJsonFile == [popularListFullInfo count]-1) {
        // default.json파일의 popularList 안에 있는 Array들 중 길이가 모두 같으면
        NSLog(@"%@", @"[INFO] default.json Check : Normal");
    } else {
        // default.json파일의 popularList 안에 있는 Array들 중 길이가 다른 것이 1개라도 있으면 WARN 출력 및 앱 dead
        NSLog(@"****************************************************");
        NSLog(@"[WARN] Check File : default.json - popularList");
        NSLog(@"****************************************************");
    }
}

-(void) updateView {
    // **************************************** [Start] 뷰 그리기 **************************************** //
    // 기존 뷰 삭제
    for (UIView *subview in self.scrollView.subviews) {
        [subview removeFromSuperview];
    }
    // viewDidLoad 메서드에서 스크롤 뷰를 초기화하고 설정합니다.
    self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    self.scrollView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.scrollView];
    
    //카드뷰 배치에 필요한 변수를 설정합니다.
    // 카드 목록 나열될 공간 세팅
    // ****************************** //
    // 목록 상단 공백 margin 설정
    CGFloat cardViewTopStartMargin = 10.0;
    // 카드 목록의 좌우 공백 각각의 margin
    CGFloat horizontalMargin = 2.0;
    // 카드와 카드 사이의 공백
    CGFloat cardViewSpacing = 0.0;
    // 카드뷰 목록 노출 시작 x축 위치 자동 설정
    CGFloat cardViewXPosition = horizontalMargin;
    // ****************************** //
    // 카드 자체에 대한 세팅
    // 카드 높이 길이 (상하 길이) 설정
    CGFloat cardViewHeight = 44.0;
    // 카드 좌우 길이 phone size 참조하여 자동 조정
    CGFloat cardViewWidth = [UIScreen mainScreen].bounds.size.width - horizontalMargin * 2;
    // 카드뷰 안에 내용 들어가는 공간까지의 margin
    CGFloat basicMarginInCard = 4.0;
    CGFloat defaultFontSize = 16.0;
    // ****************************** //
    
    // **************************************** [Start] 최상단에 기타 정보 공간 **************************************** //
    UIView *topInfoTab = [[UIView alloc] initWithFrame:CGRectMake(cardViewXPosition, cardViewTopStartMargin - (cardViewSpacing + cardViewHeight), cardViewWidth, cardViewHeight)];
    // 국기 너비 길이 (좌우 길이) 설정
    CGFloat miniImange = 18.0;
    
    /* #################### 글로벌 지구 이모티콘 및 시간 설정 #################### */
    UILabel *earthLabel = [[UILabel alloc] initWithFrame:CGRectMake(basicMarginInCard, basicMarginInCard, miniImange, 20)];
    earthLabel.text = @"🌍";
    // 표준 시간 = 그리니치 표준시 : 더블린, 에든버러, 리스본, 런던, 카사블랑카, 몬로비아
    UILabel *liveGMTLabel = [[UILabel alloc] initWithFrame:CGRectMake(basicMarginInCard + miniImange, basicMarginInCard, cardViewWidth / 2, 20)];
    // 레이블의 텍스트를 설정합니다. 여기에서는 sortedArray 배열의 i 번째 요소를 사용합니다.
    liveGMTLabel.text = [[CRTSystem alloc] init].NowDateTimeUTC;
    liveGMTLabel.font = [UIFont fontWithName:@"Pretendard-Regular" size:defaultFontSize];
    
    /* #################### 한국 이모티콘 및 시간 설정 #################### */
    // 태극기
    UILabel *koreanFlagLabel = [[UILabel alloc] initWithFrame:CGRectMake(basicMarginInCard, basicMarginInCard + cardViewHeight / 2, miniImange, 20)];
    koreanFlagLabel.text = @"🇰🇷";
    // 한국 시간
    UILabel *liveKSTLabel = [[UILabel alloc] initWithFrame:CGRectMake(basicMarginInCard + miniImange, basicMarginInCard + cardViewHeight / 2, cardViewWidth / 2, 20)];
    // 레이블의 텍스트를 설정합니다. 여기에서는 sortedArray 배열의 i 번째 요소를 사용합니다.
    liveKSTLabel.text = [[CRTSystem alloc] init].NowDateTimeKST;
    liveKSTLabel.font = [UIFont fontWithName:@"Pretendard-Regular" size:defaultFontSize];
    
    /* #################### cardView를 self.scrollView에 추가 #################### */
    // global 적용
    [topInfoTab addSubview:earthLabel];
    [topInfoTab addSubview:liveGMTLabel];
    // korea 적용
    [topInfoTab addSubview:koreanFlagLabel];
    [topInfoTab addSubview:liveKSTLabel];
    [self.scrollView addSubview:topInfoTab];
    
    // **************************************** [Start] 카드뷰 목록 쭉 만들기 **************************************** //
    for (int i=0; i<popularListFullInfo.count; i++) {
        /* #################### 카드뷰 기본 세팅 #################### */
        UIView *cardView = [[UIView alloc] initWithFrame:CGRectMake(cardViewXPosition, cardViewTopStartMargin + i * (cardViewSpacing + cardViewHeight), cardViewWidth, cardViewHeight)];
        
        // 카드 테두리 다크그레이색
        cardView.layer.borderColor = [UIColor darkGrayColor].CGColor;
        cardView.layer.borderWidth = 1.0;
        
        // 카드뷰 모서리를 둥글게 설정합니다. 조건 1
        cardView.layer.cornerRadius = 0.0;
        // cardView의 경계를 기준으로 내용물이 보이는 영역을 제한합니다. masksToBounds를 YES로 설정하면, cardView의 경계 밖에 있는 모든 내용물은 자르고 숨깁니다(클립 됩니다). 즉 뷰의 경계 값을 초과한 부분을 자르기 위해 masksToBounds를 YES로 설정합니다. 반면 masksToBounds가 NO인 경우(기본값)에는 뷰의 경계 밖에 있는 내용물이 그대로 보이게 됩니다.
        cardView.layer.masksToBounds = YES;
        
        // UILabel의 텍스트 색상 및 배경색 설정
        // 카드뷰 배경색을 설정합니다.
        if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
            // 다크모드인 경우
            cardView.backgroundColor = [UIColor blackColor];
            [self.view addSubview:cardView];
        } else {
            // 라이트모드인 경우
            cardView.backgroundColor = [UIColor whiteColor];
            [self.view addSubview:cardView];
        }
        
        // UILabel 객체를 생성합니다. 이 레이블은 암호화폐의 이름을 표시할 것입니다.
        // 따라서 CGRect를 사용하여 레이블의 위치와 크기를 설정하며, 왼쪽 위 모서리에서 시작합니다.
        UILabel *cryptoNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(basicMarginInCard, basicMarginInCard, cardViewWidth / 4, 20)];
        // 레이블의 텍스트를 설정합니다. 여기에서는 sortedArray 배열의 i 번째 요소를 사용합니다.
        cryptoNameLabel.text = popularListFullInfo[i][4];
        cryptoNameLabel.font = [UIFont fontWithName:@"Pretendard-Bold" size:defaultFontSize];
//        systemFontOfSize:defaultFontSize
        // 생성한 cryptoNameLabel을 cardView의 서브뷰로 추가합니다. 이렇게 함으로써 레이블이 카드 뷰에 표시됩니다.
        [cardView addSubview:cryptoNameLabel];
        
        /* #################### High spot 현재 가격, 거래소 정보 노출 라벨 세팅 #################### */
        // 암호화폐 가격 레이블을 생성하고 카드뷰에 추가합니다.
        // 가격위한 기본 셋
        UILabel *cryptoPriceHighLabel = [[UILabel alloc] initWithFrame:CGRectMake(cardViewWidth / 3, basicMarginInCard, cardViewWidth / 2, 20)];
        cryptoPriceHighLabel.textAlignment = NSTextAlignmentRight;
        cryptoPriceHighLabel.font = [UIFont fontWithName:@"Pretendard-ExtraBold" size:defaultFontSize];
        
        // 거래소 이름 및 로고 레이블을 생성하고 카드뷰에 추가합니다.
        // 거래소 이름을 위한 기본 셋
        UILabel *exchangeNameHighLabel = [[UILabel alloc] initWithFrame:CGRectMake(cardViewWidth / 4 + miniImange, basicMarginInCard, cardViewWidth/4, 20)];
        exchangeNameHighLabel.font = [UIFont fontWithName:@"Pretendard-Regular" size:defaultFontSize];
        // 거래소 아이콘을 위한 기본 셋
        UIImageView *exchangeLogoHighImage = [[UIImageView alloc] initWithFrame:CGRectMake(cardViewWidth / 4, basicMarginInCard, miniImange, miniImange)];
        exchangeLogoHighImage.contentMode = UIViewContentModeScaleAspectFit; // 해당 옵션을 사용하여 가로세로 비율 유지 크기입니다.
        
        /* #################### Low spot 현재 가격, 거래소 정보 노출 라벨 세팅 #################### */
        // 암호화폐 가격 레이블을 생성하고 카드뷰에 추가합니다.
        // 가격위한 기본 셋
        UILabel *cryptoPriceLowLabel = [[UILabel alloc] initWithFrame:CGRectMake(cardViewWidth / 3, cardViewHeight/2, cardViewWidth / 2, 20)];
        cryptoPriceLowLabel.textAlignment = NSTextAlignmentRight;
        cryptoPriceLowLabel.font = [UIFont fontWithName:@"Pretendard-ExtraBold" size:defaultFontSize];
        
        // 거래소 이름 및 로고 레이블을 생성하고 카드뷰에 추가합니다.
        // 거래소 이름을 위한 기본 셋
        UILabel *exchangeNameLowLabel = [[UILabel alloc] initWithFrame:CGRectMake(cardViewWidth / 4 + miniImange, cardViewHeight/2, cardViewWidth/4, 20)];
        exchangeNameLowLabel.font = [UIFont fontWithName:@"Pretendard-Regular" size:defaultFontSize];
        // 거래소 아이콘을 위한 기본 셋
        UIImageView *exchangeLogoLowImage = [[UIImageView alloc] initWithFrame:CGRectMake(cardViewWidth / 4, cardViewHeight/2, miniImange, miniImange)];
        exchangeLogoLowImage.contentMode = UIViewContentModeScaleAspectFit; // 해당 옵션을 사용하여 가로세로 비율 유지 크기입니다.
        
        // 안에 들어가는 문구
        // 특정 거래소에 있는지 확인
        if ([popularListFullInfo[i][0] containsObject:@"spot-Binance"]) {
            // ****** 거래소 이미지 설정 ****** //
            exchangeNameHighLabel.text = @"Binance";
            exchangeLogoHighImage.image = [UIImage imageNamed:@"exchangeBinance.png"];
            // Binance에 특정 코인 있는 경우
            if ([popularPrice_binance_spot objectForKey:popularListFullInfo[i][4]]) {
                // ****** 가격 노출값 설정 ****** //
                cryptoPriceHighLabel.text = popularPrice_binance_spot[popularListFullInfo[i][4]];
            // 없으면 - 출력
            } else {
                cryptoPriceHighLabel.text = @"-";
            }
        }
        if ([popularListFullInfo[i][0] containsObject:@"spot-Bybit"]) {
            // ****** 거래소 이미지 설정 ****** //
            exchangeNameLowLabel.text = @"Bybit";
            exchangeLogoLowImage.image = [UIImage imageNamed:@"exchangeBybit.jpeg"];
            // Bybit에 특정 코인 있는 경우
            if ([popularPrice_bybit_spot objectForKey:popularListFullInfo[i][4]]) {
                // ****** 가격 노출값 설정 ****** //
                cryptoPriceLowLabel.text = popularPrice_bybit_spot[popularListFullInfo[i][4]];
            // 없으면 - 출력
            } else {
                cryptoPriceLowLabel.text = @"-";
            }
        }
        [cardView addSubview:cryptoPriceHighLabel];
        [cardView addSubview:exchangeNameHighLabel];
        [cardView addSubview:exchangeLogoHighImage];
        [cardView addSubview:cryptoPriceLowLabel];
        [cardView addSubview:exchangeNameLowLabel];
        [cardView addSubview:exchangeLogoLowImage];
        
        // cardView를 self.scrollView에 추가합니다.
        [self.scrollView addSubview:cardView];
    }
    // **************************************** [End] 카드뷰 목록 쭉 만들기 **************************************** //
    // 상하 스크롤 최대치 자동 설정
    CGFloat contentHeight = popularListFullInfo.count * (cardViewHeight + cardViewSpacing);
    self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, contentHeight);
}
@end

 

 

 

 

 

5. MyTabBarController 파일 수정

 

 Favorite이 아니라 Popular가 맞는 표현이라 바꾸어주었습니다.

 

// vim MyTabBarController.h

#import <UIKit/UIKit.h>

// MyTabBarController라는 이름의 탭바 컨트롤러 클래스를 선언합니다.
@interface MyTabBarController : UITabBarController

@end

 

// vim MyTabBarController.m

#import <Foundation/Foundation.h>

#import "MyTabBarController.h"
#import "CurrencyTrackerListVC.h"
#import "PopluarAssetListVC.h"
#import "MyProfileVC.h"

@implementation MyTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    // FirstViewController를 생성하고 속성을 설정합니다.
    PopluarAssetListVC *firstTabMainVC = [[PopluarAssetListVC alloc] init];
    UINavigationController *naviVC1 = [[UINavigationController alloc] initWithRootViewController:firstTabMainVC];
    naviVC1.tabBarItem.title = @"첫 번째";
    naviVC1.tabBarItem.image = [UIImage systemImageNamed:@"camera"];
    
    // SecondViewController를 생성하고 속성을 설정합니다.
    CurrencyTrackerListVC *secondTabMainVC = [[CurrencyTrackerListVC alloc] init];
    UINavigationController *naviVC2 = [[UINavigationController alloc] initWithRootViewController:secondTabMainVC];
    naviVC2.tabBarItem.title = @"두 번째";
    naviVC2.tabBarItem.image = [UIImage systemImageNamed:@"house"];
    
    // ThirdViewController를 생성하고 속성을 설정합니다.
    MyProfileVC *thirdTabMainVC = [[MyProfileVC alloc] init];
    UINavigationController *naviVC3 = [[UINavigationController alloc] initWithRootViewController:thirdTabMainVC];
    naviVC3.tabBarItem.title = @"세 번째";
    naviVC3.tabBarItem.image = [UIImage systemImageNamed:@"trash.fill"];

    // 생성된 뷰 컨트롤러를 탭바 컨트롤러에 배치합니다.
    NSArray *viewControllers = @[naviVC1, naviVC2, naviVC3];
    self.viewControllers = viewControllers;}

@end

 

 

 

 

 

6. CRTJSONReader 파일 변경사항 없음

 

 변경사항 없습니다.

 

// vim CRTJSONReader.h

#import <Foundation/Foundation.h>

@interface CRTJSONReader : NSDictionary

// JSON 파일을 읽어오기 위한 메소드 선언
- (NSDictionary*)loadJSONFromFile:(NSString *)fileName;

@end

 

// vim CRTJSONReader.m

#import "CRTJSONReader.h"

@implementation CRTJSONReader

- (NSDictionary *) loadJSONFromFile:(NSString *)jsonFileName {
    NSBundle *mainBundle = [NSBundle mainBundle];
    NSString *jsonFilePath = [mainBundle pathForResource:jsonFileName ofType:@"json"];
    NSError *errorJson = nil;
    // 불러올 객체 없을때 reutrn하는 데이터 생성
    NSDictionary *emptyDictionary = [NSDictionary dictionary];

    // 파일 경로를 확인합니다.
    if (jsonFilePath != nil) {
        NSLog(@"JSON 파일 경로: %@", jsonFilePath);

        // JSON 데이터를 읽어옵니다.
        NSData *jsonData = [NSData dataWithContentsOfFile:jsonFilePath];

        // JSON을 NSDictionary로 파싱합니다.
        NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&errorJson];
        if (errorJson) {
            NSLog(@"JSON 파싱 오류: %@", [errorJson localizedDescription]);
            return emptyDictionary;
        } else {
            // JSON 데이터를 사용합니다.
//            NSLog(@"JSON 객체: %@", jsonObject);
            return jsonObject;
        }
    } else {
        NSLog(@"JSON 파일을 찾을 수 없습니다.");
        return emptyDictionary;
    }
}

@end

 

 

 

 

 

7. 결과 예시

 

 

+ Recent posts