Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. let someString:String! = "this is the string";
  2.  
  3. let someString:String = "this is the string";
  4.  
  5. class MyView : UIView {
  6. @IBOutlet var button : UIButton!
  7. var buttonOriginalWidth : CGFloat!
  8.  
  9. override func awakeFromNib() {
  10. self.buttonOriginalWidth = self.button.frame.size.width
  11. }
  12. }
  13.  
  14. override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell? { return nil }
  15.  
  16. var image : UIImage? = UIImage(named: "NonExistentImage")
  17. if image != nil {
  18. println("image exists")
  19. }
  20. else {
  21. println("image does not exist")
  22. }
  23.  
  24. class FileSystemItem {
  25. }
  26.  
  27. class Directory : FileSystemItem {
  28. lazy var contents : [FileSystemItem] = {
  29. var loadedContents = [FileSystemItem]()
  30. // load contents and append to loadedContents
  31. return loadedContents
  32. }()
  33. }
  34.  
  35. // These classes are buddies that never go anywhere without each other
  36. class B {
  37. var name : String
  38. weak var myBuddyA : A!
  39. init(name : String) {
  40. self.name = name
  41. }
  42. }
  43.  
  44. class A {
  45. var name : String
  46. var myBuddyB : B
  47. init(name : String) {
  48. self.name = name
  49. myBuddyB = B(name:"(name)'s buddy B")
  50. myBuddyB.myBuddyA = self
  51. }
  52. }
  53.  
  54. var a = A(name:"Big A")
  55. println(a.myBuddyB.name) // prints "Big A's buddy B"
  56.  
  57. class MyViewController: UIViewController {
  58.  
  59. var screenSize: CGSize?
  60.  
  61. override func viewDidLoad {
  62. super.viewDidLoad()
  63. screenSize = view.frame.size
  64. }
  65.  
  66. @IBAction printSize(sender: UIButton) {
  67. println("Screen size: (screenSize!)")
  68. }
  69. }
  70.  
  71. if let value = optionalWhichTotallyHasAValue {
  72. println("(value)")
  73. } else {
  74. assert(false)
  75. }
  76.  
  77. println("(value!)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement