簡體   English   中英

問:如何在iOS中聲明Byte []的屬性?

[英]Q:how to declare a property of Byte[] in iOS?

我有一個需要接收Byte[]

.h文件中:

- (void)setPC1_APPKEY:(Byte[] )pC1_APPKEY;

.m文件中:

我想擁有一個Byte[]屬性來保存它。

但是當我這樣聲明屬性時:

@property (nonatomic, assign) Byte PC1_APPKEY[];

它顯示錯誤: property cannot have array or function type'Byte[]'

因此,我將其設置為以下屬性:

{
    Byte PC1_APPKEY[];
}

它顯示錯誤: Field has Incomplete type 'Byte[]'

如何獲得Byte[] 謝謝。

你可以像這樣使用Pointer

@property (nonatomic, assign) Byte *PC1_APPKEY;

全部文件

。H

//
//  ocViewController.h
//  testTableViewHeader
//
//  Created by 刷臉卡 on 10/11/16.
//  Copyright © 2016 曾祥林. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TestViewController : UIViewController
- (void)setPC1_APPKEY:(Byte[] )pC1_APPKEY;
@end

.m

//
//  ocViewController.m
//  testTableViewHeader
//
//  Created by 刷臉卡 on 10/11/16.
//  Copyright © 2016 曾祥林. All rights reserved.
//

#import "TestViewController.h"

@interface TestViewController ()
@property (nonatomic, assign) Byte *PC1_APPKEY;
@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *testString = @"1234567890";
    NSData *testData = [testString dataUsingEncoding: NSUTF8StringEncoding];
    self.PC1_APPKEY = (Byte *)[testData bytes];
    for(int i=0;i<[testData length];i++){
        printf("testByte = %d\n",self.PC1_APPKEY[i]);
    }
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setPC1_APPKEY:(Byte [])pC1_APPKEY{
    self.PC1_APPKEY = pC1_APPKEY;
}

@end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM