About Me

My photo
Drum & Bass Producer, Software Developer, Love my Cats

how to use custom or external fonts in swift ios app

if you want to use external or custom fonts in a swift ios app, just:
1. copy the font files into the project
2. in your info.plist file, add an entry called "Fonts provided by application" (xcode will autocomplete you)
3. now you have an array, in which you add the names of the fonts - each in its own string entry

and that's how you add custom fonts to your ios app - good luck!

how to limit UITextField number of characters

When you wan t to limit the number of characters that a user can input to a uitextfield, you can use this uitextfielddelegate method:


import UIKit

class ViewController: UIViewController, UITextFieldDelegate { // make sure you inherit uitextfielddelegate

    @IBOutlet weak var textField: UITextField! // your textfield
    let limit = 10

    override func viewDidLoad() {
        super.viewDidLoad()
        textField.delegate = self // set myself as the delegate
    }

// this method "listens" to changes in the textfield, and you can return true or false as appropriate
    func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
        guard let text = textField.text else { return true }
        let newLength = text.characters.count + string.characters.count - range.length
        return newLength <= limit
    }
}

How to FIX Cocoa pods in swift 3 error : “Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

While installing a cocoa pod, I ran into this hideous and misleading error:

“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.


A long stroll around stackoverflow and the cocoapods github issues forums showed me many solutions, but none was simple and straightforward.

So I just read the whole error again, and saw the "Or......" part, and followed it with a bit of improvisation.

Here's how to solve this error:

1. click the "pods" project in your xcode workspace
2. select the target of the pod that generated this issue
3. go to its build setting and search for "SWIFT_VERSION"
4. find the field "Use Legacy Swift Language Version" - and set it to "No"
5. clean, (maybe delete derived data), build - and you're fine :)


I hope you find this helpful to solving this error with cocoapods and swift 3 on xcode 8

Garlic - A drag-n-drop Remote Configuration Framework for iOS (objective-c)

Garlic

A drag-n-drop remote configuration framework for iOS

Features:

  • Easy 1-line integration
  • ZERO libraries required (not even AFNetworking!)
  • Remote feature flags
  • Local settings fallback
  • Custom remote settings
  • Force updates
  • No collisions with other frameworks

Setup:

In most cases, you want to load remote settings either in the lifecycle events in your AppDelegate or ViewController, or anywhere else you like:

  1. #import “Garlic.h”
  2. Init and setup Garlic with a remote settings plist URL and a completion block: [[Garlic sharedInstance] setupWithRemoteConfigURL:@”{{your-remote-settings-plist-url-here.com}}” completionHandler:^(void){ // code to run when setup was done }

Force update:

Determine if the app should be updated, based on build numbers

if ([[Garlic sharedInstance] shouldForceUpdateApp]) { // ask user to update app }

Feature flags:

Check if a feature should be activated

if ([[Garlic sharedInstance] shouldAllowFeature:@"{{your-feature-name-here}}"]) { // show the button/menu that enables that feature}

Custom values:

Get remote values for your custom purposes

NSString *tipOfTheDay = [[Garlic sharedInstance] getSettingForKey:@"TipOfTheDay-2015-11-27"]

Future features:

  1. Force synchronous url request
  2. Load settings from JSONs and XMLs, in addition to plists
  3. POST remote settings: change remote settings in the server when shaking the device
  4. Web-based remote settings editor
  5. Push updates: engage a remote settings update using a push notification
  6. Targeted Feature Flags: toggle features for specific user IDs, geolocations, device models..

Made with <3 by Nur Nachman - nur.xyz

[mac os x tutorial] How to install the pip python package manager in mac os x

how to install pip python package manager:
simply run this in Terminal:
sudo easy_install pip