Skip to content

Instantly share code, notes, and snippets.

@tokorom
Created September 27, 2014 07:03
Show Gist options
  • Save tokorom/d744db2170ea97d05eb1 to your computer and use it in GitHub Desktop.
Save tokorom/d744db2170ea97d05eb1 to your computer and use it in GitHub Desktop.
// 最適化によりnilが返っちゃうfunction
func parseFacebookUserDictionary(dictionary: NSDictionary) -> FacebookUserInformation? {
if let dict = dictionary as? [String : AnyObject] {
let information = FacebookUserInformation(dictionary: dict)
return information
}
return nil
}
// nilが返らないfunction
func parseFacebookUserDictionary(dictionary: NSDictionary) -> FacebookUserInformation? {
if let dict = dictionary as? [String : AnyObject] {
println("\(dictionary.count)") //< この行を外すと誤った最適化がされるので注意!!
let information = FacebookUserInformation(dictionary: dict)
return information
}
return nil
}
@tokorom
Copy link
Author

tokorom commented Sep 27, 2014

最適化レベルを -O(Releaseビルドのデフォルト) から -Onone(Debugビルドのデフォルト) に変更すると、どちらもきちんと値が返るようになります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment