Skip to content

Latest commit

 

History

History
76 lines (54 loc) · 1.81 KB

swift.md

File metadata and controls

76 lines (54 loc) · 1.81 KB

Resources

xcode shortcuts

  • Re-indent: ctrl + I
  • go back: ctrl + cmd + <-
  • reveal in project navigator: shft + cmd + J
  • jump to definition: ctrl + cmd + J

NSLog

NSLog("Error: \(error)")

casting int to string

cell.imageView?.image = UIImage(named: "image-cell" + String(indexPath.row + 1))

UI without storyboard

  • Remove main interface from General tab
  • set the custom view controller to main window
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
    let viewController = BeautifulWeatherViewController()
    
    let mainWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
    mainWindow.backgroundColor = UIColor.whiteColor()
    mainWindow.rootViewController = viewController
    mainWindow.makeKeyAndVisible()
    
    window = mainWindow
          
    
    return true
}

unresolved identifier 'layout'

Use constrain instead

func layoutView() {
    constrain(backgroundView) { view in
        view.top == view.superview!.top
        view.bottom == view.superview!.bottom
        view.left == view.superview!.left
        view.right == view.superview!.right
    }
}

float and edge type conversion error

the type of superview!.top is CGFloat

let currentWeatherInsect: Float = Float(view.frame.height) - Float(currentWeatherView.frame.height) - 10
constrain(currentWeatherView) { view in
    view.top == view.superview!.top + CGFloat(currentWeatherInsect)
    return
}