For MacOS Sierra, we can configure user name and user email as global settings for a user via terminal.
Below is an example to set user name and user gmail for a user.
git config --global user.name "usera"
git config --global user.email "usera@gmail.com"
The settings will be written to ~/.gitconfig file. After the commands, all git repositories by default will have user name of "usera" and user email as "usera@gmail.com.
Saturday, December 31, 2016
Friday, December 30, 2016
Web access in Swift 3
Xcode 8.2.1 is used for the development of web access below.
Use UIWebView to load a webpage or display html string. Let's define an IBOutlet for a UIWebView component as following.
1. Use loadRequest to load a URL request.
2. Use loadHTMLString to display HTML string.
Sometimes we need to get the contents of a URL to do some parsing. Below is an example to use the dataTask function of a URLSession to load the contents of a URL
We can also use URLRequest in dataTask function to get the contents of a URL, which is quite similar.
The former seems to be more straightforward.
For security reasons, insecure http access is not allowed. Ref[1] talked about details on adding exception domains into.plist. An example to add stackoverflow.com and all its subdomains is below.
Use UIWebView to load a webpage or display html string. Let's define an IBOutlet for a UIWebView component as following.
@IBOutlet weak var webView: UIWebView!
1. Use loadRequest to load a URL request.
if let myURL = URL(string:"https://stackoverflow.com") {
/// Use loadRequest to load a URL
webView.loadRequest(URLRequest(url: myURL))
}
2. Use loadHTMLString to display HTML string.
///Use loadHTMLString to diplay HTML string in web view.
webView.loadHTMLString("<h1>Hello</h1>", baseURL: nil)
Sometimes we need to get the contents of a URL to do some parsing. Below is an example to use the dataTask function of a URLSession to load the contents of a URL
///Use dataTask function to get contents for a URL
if let myURL = URL(string:"https://stackoverflow.com") {
let task = URLSession.shared.dataTask(with: myURL, completionHandler: {
(data, respose, error) in
if error != nil {
print(error as Any)
} else {
if let unwrappedData = data {
let strData = NSString(data: unwrappedData, encoding: String.Encoding.utf8.rawValue)
as! String
print(strData)
}
}
})
task.resume()
}
We can also use URLRequest in dataTask function to get the contents of a URL, which is quite similar.
///Use dataTask function for a URL request
if let myURL = URL(string:"https://stackoverflow.com") {
let myRequest = URLRequest(url: myURL)
let task = URLSession.shared.dataTask(with: myRequest, completionHandler: {
(data, response, error) in
if error != nil {
print(error as Any)
} else {
if let unwrappedData = data {
let strData = NSString(data: unwrappedData, encoding: String.Encoding.utf8.rawValue)
as! String
print(strData)
}
}
})
task.resume()
}
The former seems to be more straightforward.
For security reasons, insecure http access is not allowed. Ref[1] talked about details on adding exception domains into.plist. An example to add stackoverflow.com and all its subdomains is below.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>stackoverflow.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
References
-----------
1. How to Add App Transport Security Exception Domains,
https://cocoacasts.com/how-to-add-app-transport-security-exception-domains/
Thursday, December 29, 2016
Swipe Actions for UITableViewCell
There are two references Ref[1,2] on swipe actions for UITableViewCell. Things have changed a bit for iOS 8.2.
For example, the following function is not needed for UITableView's delegate to make rows editable. By default, the rows are editable.
To disable rows from editing, we can return false for the above function.
Ref[2] illustrates how to delete a row. For Xcode 8.2, the corresponding code snippet is below
We can also use editActionsForRowAt to delete a row as below.
References
--------------
1. http://www.brianjcoleman.com/tutorial-swipe-actions-for-uitableviewcell-in-swift/
2. https://www.ioscreator.com/tutorials/delete-rows-table-view-ios8-swift
For example, the following function is not needed for UITableView's delegate to make rows editable. By default, the rows are editable.
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
To disable rows from editing, we can return false for the above function.
Ref[2] illustrates how to delete a row. For Xcode 8.2, the corresponding code snippet is below
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCellEditingStyle.delete {
todoList.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
}
}
We can also use editActionsForRowAt to delete a row as below.
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let delAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Delete") { (action, index) in
self.todoList.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
}
delAction.backgroundColor = UIColor.orange
return [delAction]
}
editActionsForRowAt can enable more actions for a row and is more useful.References
--------------
1. http://www.brianjcoleman.com/tutorial-swipe-actions-for-uitableviewcell-in-swift/
2. https://www.ioscreator.com/tutorials/delete-rows-table-view-ios8-swift
Tuesday, December 27, 2016
Touch ID for iOS programming
References
--------------
1. Touch ID with Swift https://www.devfright.com/touch-id-swift/
--------------
1. Touch ID with Swift https://www.devfright.com/touch-id-swift/
Xcode Useful Shotcuts
Some useful shortcuts to make Xcode development more efficient.
1. Build and running
2. Files and Windows
3. Navigation
4. Editor
1. Build and running
⌘ + B Build ⇧ + ⌘ + K Clean ⌘ + R Run
2. Files and Windows
⌘ + F Find text in a file ⇧ + ⌘ + F Find text in Project ⌘ + N Create a new file ⌘ + T Open a new tab ⌘ + W Close a tab
3. Navigation
⌘ + 0 Show/Hide Navigator ⌥ + ⌘ + 0 Show/Hide Utilities
4. Editor
⌃ + I Reindent ⎋ or ⌃ + Space Show/Hide completion5. Others
⌥ + Click or Force Click Quick help for class or method name that was clicked. ⌘ + Click Go to the definition of the class that was clicked.
Monday, December 26, 2016
Mac commonly used shortcuts
Ref[1] contains a complete list of MacOS shortcuts. Here I list a few commonly used ones from it.
References
-------------
1. Mac Keyboard shortcuts, https://support.apple.com/en-us/HT201236
Fn–Up Arrow Page Up: Scroll up one page. Fn–Down Arrow Page Down: Scroll down one page. Fn–Left Arrow Home: Scroll to the beginning of a document. Fn–Right Arrow End: Scroll to the end of a document. Command–Up Arrow Move the insertion point to the beginning of the document. Command–Down Arrow Move the insertion point to the end of the document. Command–Left Arrow Move the insertion point to the beginning of the current line. Command–Right Arrow Move the insertion point to the end of the current line. Control-A Move to the beginning of the line or paragraph. Control-E Move to the end of a line or paragraph.
References
-------------
1. Mac Keyboard shortcuts, https://support.apple.com/en-us/HT201236
Social Sign In On iOS
References
--------------
1. Swift 3 + Firebase Authentication - Google Sign In
https://www.youtube.com/watch?v=83EXULT480Q
2. Swift 3: Firebase Social Login - Google Sign In (Ep 4)
https://www.youtube.com/watch?v=rDKtMz_PcLQ
3. Swift 3: Firebase Social Login - Facebook Authentication and Cocoapods
https://www.youtube.com/watch?v=iSszeW1aH6I
4. Swift 3: Firebase Social Login - Facebook Email and Custom Login Button (Ep 2)
https://www.youtube.com/watch?v=Tl_uCGjCZd8
5. Sign in series #2: Adding Google Sign-in to your iOS App (Route 85)
https://www.youtube.com/watch?v=QmnI5c85sf0
6.
http://stackoverflow.com/questions/39550525/firinstanceid-warning-stop-will-reset-deviceid-from-memory-xcode-console-lo/39560078#39560078
--------------
1. Swift 3 + Firebase Authentication - Google Sign In
https://www.youtube.com/watch?v=83EXULT480Q
2. Swift 3: Firebase Social Login - Google Sign In (Ep 4)
https://www.youtube.com/watch?v=rDKtMz_PcLQ
3. Swift 3: Firebase Social Login - Facebook Authentication and Cocoapods
https://www.youtube.com/watch?v=iSszeW1aH6I
4. Swift 3: Firebase Social Login - Facebook Email and Custom Login Button (Ep 2)
https://www.youtube.com/watch?v=Tl_uCGjCZd8
5. Sign in series #2: Adding Google Sign-in to your iOS App (Route 85)
https://www.youtube.com/watch?v=QmnI5c85sf0
6.
http://stackoverflow.com/questions/39550525/firinstanceid-warning-stop-will-reset-deviceid-from-memory-xcode-console-lo/39560078#39560078
Friday, December 16, 2016
Developer's useful websites for various resources
1. various sounds and music
http://freesfx.com/
2. Make images files as icons for iOS apps
http://makeappicon.com
http://freesfx.com/
2. Make images files as icons for iOS apps
http://makeappicon.com
Wednesday, December 14, 2016
Swift Language Tips
References
--------------
1. The as! operator, https://developer.apple.com/swift/blog/?id=23
--------------
1. The as! operator, https://developer.apple.com/swift/blog/?id=23
Sunday, December 11, 2016
User Notification
Reference
1. User Notifications in iOS 10 Tutorial,
https://www.youtube.com/watch?v=H2B-dIK2X_c
1. User Notifications in iOS 10 Tutorial,
https://www.youtube.com/watch?v=H2B-dIK2X_c
Subscribe to:
Posts (Atom)