Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at



C言語の単純型 Swiftの型
Bool Bool
short int16
int int32
long Int
long long Int64
float Float
double Double


種類 C言語の型 Swiftの型
ポインタ const T * UnsafePointer
T * UnsafeMutablePointer
const void * UnsafeRawPointer
void * UnsafeMutableRawPointer
クラスCのインスタンス C * const * UnsafePointer
C * __strong UnsafeMutablePointer
C ** AutoreleasingUnsafeMutablePointer
関数 T (*func)(U) @convention(c)(U) -> T
T (*func)(void) @convention(c)() -> T
ブロック T (^block)(U) @convention(block)(U) -> T

Array から NSArray への変換方法

let intList:[Int] = [1,2,3,4]
let cArray = intList as NSArray

NSArray から Array への変換方法

let ns1: NSArray = [100, "sample", 200]
let ns2: NSArray = [10, 20, 30]

if let ar1 = ns1 as? [Any] {
    print(type(of: ar1))

if let ar2 = ns2 as? [Int] {
    print(type(of: ar2))


let strList = array.filter{ $0 is String }

Swift のDictionaryはそのままNSDictionaryに変換可能。
複数の型のキーを含まなければならない場合は AnyHashable型のキー
値が複数の型の場合は Any型の値

let d:[AnyHashable: Any] = [AnyHashable(0): "Zero",
                            AnyHashable("II"): 2]
let nsDic = d as NSDictionary


Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
Help us understand the problem. What are the problem?