Skip to content

Instantly share code, notes, and snippets.

View nvkiet's full-sized avatar

Kiet Nguyen - CoFounder & CEO at GrabLingo.com nvkiet

View GitHub Profile
@nvkiet
nvkiet / HideStatusbar
Created July 24, 2014 08:04
Force hide status bar in iOS 6 and iOS 7
//viewDidload
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
// Add this Method
@nvkiet
nvkiet / LinkerFlag
Created July 24, 2014 02:00
Compile correctly for non-ARC projects
-fno-objc-arc
Add -fobjc-arc to compiler flags under build phases to ARC files to make them compile correctly for non-ARC projects.
@nvkiet
nvkiet / [Swift] GetCountryNames
Last active April 23, 2016 20:36
Declare a static variable in a function
class func countryNames() -> [String] {
struct Static {
static var instance: [String]?
}
if let names = Static.instance {
return names
}
var names = [String]()
for code in NSLocale.ISOCountryCodes() as [String] {
@nvkiet
nvkiet / SingleTon
Created July 20, 2014 13:32
Declare a Singleton in Swift
class var sharedInstance : PusherManager {
struct Static {
static let instance : PusherManager = PusherManager()
}
return Static.instance;
}
@nvkiet
nvkiet / StrechImage
Created July 18, 2014 17:11
UIImage stretchableImageWithLeftCapWidth
- (UIImage *) resizableImageWithSize:(CGSize)size
{
if( [self respondsToSelector:@selector(resizableImageWithCapInsets:)] )
{
return [self resizableImageWithCapInsets:UIEdgeInsetsMake(size.height, size.width, size.height, size.width)];
} else {
return [self stretchableImageWithLeftCapWidth:size.width topCapHeight:size.height];
}
}
@nvkiet
nvkiet / RemoveCocoadPods
Created July 18, 2014 05:56
Removing CocoaPods from a project
Removing CocoaPods from a project is possible, but not currently automated by the CLI. First thing, if the only issue you have is not being able to use an xcworkspace you can use CocoaPods with just xcodeprojs by using the --no-integrate flag which will produce the Pods.xcodeproj but not a workspace. Then you can add this xcodeproj as a subproject to your main xcodeproj.
If you really want to remove all CocoaPods integration you need to do a few things:
NOTE editing some of these things if done incorrectly could break your main project. I strongly encourage you to check your projects into source control just in case. Also these instructions are for CocoaPods version 0.28.0, they could change with new versions.
Delete the standalone files (Podfile Podfile.lock and your Pods directory)
Delete the generated xcworkspace
Open your xcodeproj file, delete the references to Pods.xcconfig and libPods.a (in the Frameworks group)
Under your Build Phases delete the Copy Pods Resources and Check Pods Ma
@nvkiet
nvkiet / [Swift] Switch-RootViewController
Last active January 28, 2025 07:46
Switch root view controller
func switchRootViewController(rootViewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
if animated {
UIView.transitionWithView(window, duration: 0.5, options: .TransitionCrossDissolve, animations: {
let oldState: Bool = UIView.areAnimationsEnabled()
UIView.setAnimationsEnabled(false)
self.window!.rootViewController = rootViewController
UIView.setAnimationsEnabled(oldState)
}, completion: { (finished: Bool) -> () in
if completion {
completion!()
@nvkiet
nvkiet / [Xcode6beta2]NSURLAuthenticationMethodClientCertificate
Created July 7, 2014 06:02
dyld: Symbol not found: _NSURLAuthenticationMethodClientCertificate when trying to run iOS app
Re-ordering in XCode didn't do the trick; I'm using Cocoapods, which creates a Pods.xcconfig file. This has a OTHER_LDFLAGS line. I put -framework Foundation as the first entry, and that's made my project work.
OTHER_LDFLAGS = -framework Foundation -ObjC …
http://stackoverflow.com/questions/24043532/dyld-symbol-not-found-nsurlauthenticationmethodclientcertificate-when-trying#answer-24288986
@nvkiet
nvkiet / [Swift] Init a subview
Last active August 29, 2015 14:03
Init a subview
Also for people referring to @akashivskyy answer, and having trouble or crash with error
fatal error: use of unimplemented initializer 'init(coder:)' for class
Implementing initWithCoder in Objective-C is not required but in Swift is required
So to use @akashivskyy's asnwer you need also to add these lines to your destinationViewController.
init(coder aDecoder: NSCoder!)
{
@nvkiet
nvkiet / CustomFont-iOS
Created July 6, 2014 16:56
How to use custom font in iOS
You need your font in .otf or .ttf copied to your project. For example in Supporting Files.
You need to edit .plist file. Add "Fonts provided by application" key into your plist and in Item 0 copy the exact filename of the font you copied to your Supporting files WITH extension. For example: "JosefinSansStd-Light_0.otf"
Make sure that the font you imported to your app is being packed into app itself. Do that by selecting your Target, then Build Phases, then Copy Bundle Resources. If you don't see your font in there, drag it from Supporting Files.
Finally, you would like to list all your fonts when the app starts just to see useable name for your font. You will do that with this little piece of code:
NSArray *fontFamilies = [UIFont familyNames];
for (int i = 0; i < [fontFamilies count]; i++)
{