otz.li

  • Home
  • Privacy Policy / Impressum
  • March 23, 2019
  • in Uncategorized
  • cwolf
  • Comments are closed

Soft Hyphens in .strings Files

If you localize your apps, you might have a .strings file for the various translations. Text that flows nicely in English, might flow rather horribly in Germany, which often uses much longer words. Using a soft hyphen will allow you to avoid that awkward spacing. To add one in your soft-strings use \U00AD Within Swift […]

Read More
  • January 6, 2019
  • in Swift
  • cwolf
  • Comments are closed

Swift 4: Copy a UILabel in iOS

By default a UILabel doesn’t get any copy & paste commands in iOS. After all, it’s a label, why would you want to copy a label? It turns out, you might want to do that, if you are “abusing” a label to show something useful and in that case you probably want the entire label […]

Read More
  • January 6, 2019
  • in Swift
  • cwolf
  • Comments are closed

Swift 4: Adding new UI Elements to the Main.strings file, which Xcode auto-generates for you

When you are ready to localize your App, Xcode will auto-generate a Main.strings file for your Main Storboard. In that file every element of the User Interface (labels & more) are listed in the following format:

Swift
1
2
/* Class = "UILabel"; text = "Subtitle"; ObjectID = "y5E-9n-LU8"; */
"y5E-9n-LU8.text" = "Untertitel";

That’s a pretty awesome format, as it makes localization quick and simple. However, if you add Elements after […]

Read More
  • January 6, 2019
  • in Swift
  • cwolf
  • Comments are closed

Swift 4: Help align UITextView to other labels, by avoiding the annoying inset

When aligning a UITextView with other labels on the screen, the inset becomes an issue. It is easy enough to work around, however if you wanted to just “switch” them off, you can add the following to your ViewDidLoad Function:

Swift
1
2
textView.textContainerInset = .zero
textView.textContainer.lineFragmentPadding = 0

 

Read More
  • September 30, 2018
  • in Swift
  • cwolf
  • Comments are closed

Swift 4: Validating a 13 digit ISBN

For a project I needed to validate a 13 digit ISBN. According to Wikipedia you can validate an ISBN by calculating the checksum, but more accurately calculating the check-digit of an ISBN as follows: The ISBN-13 check digit, which is the last digit of the ISBN, must range from 0 to 9 and must be […]

Read More
  • September 26, 2018
  • in Swift
  • cwolf
  • Comments are closed

Swift 4: An extension to define UIColors with “normal” RGB values and set some named colors

UIColors require you to enter red, green and blue as values between 0 and 1. In pracitcal terms that means you need to divide your values by 255 to obtain the CGFloat required. Easy enough? Surely! Still it is a tad annoying, especially as the rest of the world will give you RGB values between […]

Read More
  • September 25, 2018
  • in Swift
  • cwolf
  • Comments are closed

Swift 4: Pull To Refresh / UIRefreshControl

TableViews can have a useful feature to refresh the data inside of them, simply pull to refresh. Apple didn’t invent this, that was Loren Brichter of Tweetie, which was sold to Twitter and Twitter was eventually granted a Patent for the feature. Today this feature is absolutely ambiguous and very easy to implement. For example, […]

Read More
  • September 24, 2018
  • in Swift
  • cwolf
  • Comments are closed

Swift 4: JSON decoding with JSONDecoder() and structs

I have no apps in the app store, but a while ago I wrote an app for my own edutainment, which needed to parse JSON Data. At the time it was so darn complicated, that I enlisted Cocoapods and SwiftyJSON to help make things easier. SwiftJSON is pretty cool as it abstracts away a lot […]

Read More
  • September 23, 2018
  • in Swift
  • cwolf
  • Comments are closed

Swift 4: Show Network Activity Indicator

I sure am going to be unpopular, but I don’t get why an App is allowed to make “silent” network requests – in other words: I don’t get why the Network Indicator isn’t shown by the OS to alert users that there is network activity going on. However if you have a function, which makes […]

Read More
  • September 22, 2018
  • in Swift
  • cwolf
  • Comments are closed

Swift 4: Convert Unix Timestamp to a nicely formatted Date & Time

I needed to convert a Unix Timestamp, which for some inexplicit reason was being returned as a String by an API I was using and this is the super foolish function I ended up with. I am not going to shame the API Provider for returning a timestamp as a String 😉

Swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
func createDateTime(timestamp: String) -> String {
    var strDate = "undefined"
        
    if let unixTime = Double(timestamp) {
        let date = Date(timeIntervalSince1970: unixTime)
        let dateFormatter = DateFormatter()
        let timezone = TimeZone.current.abbreviation() ?? "CET"  // get current TimeZone abbreviation or set to CET
        dateFormatter.timeZone = TimeZone(abbreviation: timezone) //Set timezone that you want
        dateFormatter.locale = NSLocale.current
        dateFormatter.dateFormat = "dd.MM.yyyy HH:mm" //Specify your format that you want
        strDate = dateFormatter.string(from: date)
    }
        
    return strDate
}

 

Read More

Posts navigation

1 2 3

Search

Categories

Tag Cloud

AIM AIM Linux amazon server API AWS beautifulsoup conversion convert unix timestamp Core Data counting files custom XML date time file count File upload gettext() Image Orientation Image Scale Indicator install Internationalization macos MARC MARC21 MARCXML Network Activity Network Activity Indicator php PHP.ini pip Poedit preg_match programming pymarc python Scale to Width show String swift swift 4 timestamp unix USMARC web scraping webscraping XML