LoginSignup
7
6

More than 5 years have passed since last update.

NSDictionary要素追加方法 for Swift(Cocoa)

Last updated at Posted at 2015-07-07

初歩的なことですがハマったのでメモします.

hoge.swift
var dictionary: NSDictionary = NSDictionary()
dictionary.setValue("hoge", forKey: hoge) // Error
hoge.swift
var dictionary: NSDictionary = NSMutableDictionary()
dictionary.setValue("hoge", forKey: hoge) // Success

コメントを頂いたので修正

hoge.swift
let dictionary: NSDictionary = NSDictionary()
dictionary.setValue("hoge", forKey: hoge) // Error
hoge.swift
let dictionary: NSDictionary = NSMutableDictionary()
dictionary.setValue("hoge", forKey: hoge) // Success
7
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6