Difference between revisions of "Swift code snippets"

From Hawk Wiki
Jump to: navigation, search
 
(40 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Making Network Request==
+
=Swift Code Snippts=
<pre>
+
Back To [[IOS_Swift]]
var clientId = "Put your client id here"
+
==[[Swift: Use NSUserDefaults to Store Persistence Data]]==
+
 
var url = NSURL(string: "https://api.instagram.com/v1/media/popular?client_id=\(clientId)")!
+
==[[Swift: Making Network Request Using NSURLConnection]]==
var request = NSURLRequest(URL: url)
+
 
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in
+
==[[Swift:Use AFNetworking setImageWithURL]]==
    var responseDictionary = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as NSDictionary
+
 
    self.photos = responseDictionary["data"] as NSArray
+
==[[Swift:Using UIRefreshControl]]==
    self.tableView.reloadData()
+
 
   
+
==[[Swift:Using UIGestureRecognizer]]==
    println("response: \(self.photos)")
+
 
}
+
==Swift:Example of fetching messages from Parse==
</pre>
+
https://gist.github.com/sandofsky/7134b1ff90d235901254
==Use setImageWithURL==
+
 
Create the bridging file: create a new Objective-C file, name it anything, and when you save it, Xcode will prompt you generate a bridging file. <br>
+
==[[Swift:Auto Table Row Height]]==
In an Objective-C bridging file:
+
 
<pre>
+
==[[Swift:Navigation between storyboards]]==
#import <AFNetworking/UIImageView+AFNetworking.h>
+
 
</pre>
+
==[[Swift:Notification Observer Using NSNotificationCenter]]==
In the swift view file, to set a imageView using URL:
+
 
<pre>
+
==[[Swift:Get Raw Histogram from CGImage]]==
setImageWithURL(NSURL(string: thumbnail))
+
 
</pre>
+
==[[Swift:UIGraphics Drawing on UIView]]==
 +
 
 +
==[[Swift:UIGraphics Scale Down CGImage]]==
 +
 
 +
==[[Swift: Convert between CGImage, CIImage and UIImage]]==
 +
 
 +
==[[Swift:Detect Volumn Button Press]]==
 +
 
 +
==[[Swift:NSTimer scheduledTimerWithTimeInterval]]==

Latest revision as of 03:10, 9 April 2015

Swift Code Snippts

Back To IOS_Swift

Swift: Use NSUserDefaults to Store Persistence Data

Swift: Making Network Request Using NSURLConnection

Swift:Use AFNetworking setImageWithURL

Swift:Using UIRefreshControl

Swift:Using UIGestureRecognizer

Swift:Example of fetching messages from Parse

https://gist.github.com/sandofsky/7134b1ff90d235901254

Swift:Auto Table Row Height

Swift:Navigation between storyboards

Swift:Notification Observer Using NSNotificationCenter

Swift:Get Raw Histogram from CGImage

Swift:UIGraphics Drawing on UIView

Swift:UIGraphics Scale Down CGImage

Swift: Convert between CGImage, CIImage and UIImage

Swift:Detect Volumn Button Press

Swift:NSTimer scheduledTimerWithTimeInterval