LoginSignup
2
2

More than 5 years have passed since last update.

swiftで関数作成時の引数の外部名とショートハンドについて

Last updated at Posted at 2015-08-14

基本ショートハンド使っとけばよいかな

外部名なし

定義

func writeData(searchWordText:String) {
    let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    let searchWordContext:NSManagedObjectContext  = appDel.managedObjectContext!
    let searchWordEntity: NSEntityDescription! = NSEntityDescription.entityForName("SearchWord", inManagedObjectContext: searchWordContext)
    let searchWord: RecentSearch.SearchWord = NSEntityDescription.insertNewObjectForEntityForName("SearchWord", inManagedObjectContext: searchWordContext) as! SearchWord
    searchWord.search_word = searchWordText
    searchWord.update_date = NSDate()
}

呼び出し

writeData("testtest")

外部名

定義

func writeData(searchWordText word:String) {
    let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    let searchWordContext:NSManagedObjectContext  = appDel.managedObjectContext!
    let searchWordEntity: NSEntityDescription! = NSEntityDescription.entityForName("SearchWord", inManagedObjectContext: searchWordContext)
    let searchWord: RecentSearch.SearchWord = NSEntityDescription.insertNewObjectForEntityForName("SearchWord", inManagedObjectContext: searchWordContext) as! SearchWord
    searchWord.search_word = word
    searchWord.update_date = NSDate()
}

呼び出し

writeData(searchWordText:"testtest")

ショートハンド

定義

func writeData(#searchWordText:String) {
    let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    let searchWordContext:NSManagedObjectContext  = appDel.managedObjectContext!
    let searchWordEntity: NSEntityDescription! = NSEntityDescription.entityForName("SearchWord", inManagedObjectContext: searchWordContext)
    let searchWord: RecentSearch.SearchWord = NSEntityDescription.insertNewObjectForEntityForName("SearchWord", inManagedObjectContext: searchWordContext) as! SearchWord
    searchWord.search_word = searchWordText
    searchWord.update_date = NSDate()
}

呼び出し

writeData(searchWordText:"testtest")
2
2
0

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
2
2