Tumgik
iosswift · 10 years
Link
0 notes
iosswift · 10 years
Link
1 note · View note
iosswift · 10 years
Link
0 notes
iosswift · 10 years
Text
Open Settings app from code
New in iOS8 you can now launch the Settings app and show your apps settings easily with the following line of code… UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
0 notes
iosswift · 10 years
Link
Great article from Mattt Thompson on Swift's new comment syntax in Xcode 6 ß4. Ive been waiting for this! :-)
1 note · View note
iosswift · 10 years
Text
Adding a blur effect in iOS8
iOS8 includes the new UIVisualEffectView which can be used to add dynamic blurs to any area of the screen you like. Here's an example of just making a ViewController's whole view blurry...
override func viewDidLoad() { super.viewDidLoad() // blur let blur = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Light)) blur.frame = view.frame view.addSubview(blur) }
Note: If you want other views to sit on top of the blurred view, add them to its contentView property
6 notes · View notes
iosswift · 10 years
Video
youtube
Swift programming language - Apple Keynote
0 notes
iosswift · 10 years
Link
Describes the key structures, classes, protocols, and free functions available in the Swift Standard Library.
0 notes
iosswift · 10 years
Link
Describes various aspects of Swift's compatibility with the Objective-C language and Cocoa/Cocoa Touch frameworks.
1 note · View note
iosswift · 10 years
Link
The definitive guide to Swift, Apple’s new programming language for building iOS and OS X apps.
0 notes
iosswift · 10 years
Link
I know you know this link already but its a useful shortcut
0 notes
iosswift · 10 years
Text
A simpler RegEx expression syntax
I was kinda disappointed that regular expressions aren't built in to the core Swift syntax, like in other languages like Ruby. So I came up with this String extension that lets me do a regex straight from pattern string...
import Foundation extension String { func firstMatchIn(string: NSString!, atRangeIndex: Int!) -> String { var error : NSError? let re = NSRegularExpression(pattern: self, options: .CaseInsensitive, error: &error) let match = re.firstMatchInString(string, options: .WithoutAnchoringBounds, range: NSMakeRange(0, string.length)) return string.substringWithRange(match.rangeAtIndex(atRangeIndex)) } } var result = "(worl)".firstMatchIn("hello world", atRangeIndex: 1) // -> "worl"
0 notes
iosswift · 10 years
Text
NSFileManager documents & caches extension
Here's a handy little NSFileManager extension that gives you easy access to the documents and caches directories for your app...
import Foundation extension NSFileManager { class func documentsDir() -> String { var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) as [String] return paths[0] } class func cachesDir() -> String { var paths = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true) as [String] return paths[0] } }
1 note · View note
iosswift · 10 years
Text
UIColor and CSS colors - the easy way
We see CSS colors like #2980B9 every day, but how do you use this in a UIColor? It's easy, just break it apart into its Red (29), Green (80) and Blue (B9) components and create your UIColor like this...
import Cocoa extension UIColor { class func belizeHole() -> UIColor! { return UIColor(red: 0x29/0xff, green: 0x80/0xff, blue: 0xb9/0xff, alpha: 1) } }
1 note · View note
iosswift · 10 years
Text
Using FMDB (Bridging Headers)
FMDB is a pretty awesome wrapper around sqlite and a great alternative to CoreData. But its written in Objective-C, so how do you access it from Swift? Add the FMDB files into your project (I usually put them in External/fmdb) and then add a bridging header like this...
// FMDB #import "FMDatabase.h" #import "FMDatabaseAdditions.h" #import "FMDatabasePool.h" #import "FMDatabaseQueue.h" #import "FMResultSet.h"
The FMDB classes should now be accessible from your Swift files. Here is an example of loading and executing a db.sql file to create my DB...
class DB: NSObject { var queue:FMDatabaseQueue? = nil // queue to perform all DB ops on func createDB() { let path = "\(NSFileManager.documentsDir())/rss.db" queue = FMDatabaseQueue(path: path) // create tables queue!.inDatabase({(db: FMDatabase!) in let path = NSBundle.mainBundle().pathForResource("db", ofType: "sql") let sql = String.stringWithContentsOfFile(path, encoding: NSUTF8StringEncoding, error: nil) db.executeStatements(sql) }) } }
0 notes
iosswift · 10 years
Text
Breaking ViewControllers apart with extensions
We're all used to having large ViewController classes that implement multiple delegates for their child views. In Swift you can break each delegate into its own block of code using extensions like this...
import UIKit class MyController: UIViewController { // class specific funcs here } extension MyController : UITableViewDelegate { // table funcs here } extension MyController : UISearchBarDelegate { // search func here }
0 notes