Coding Explorer Blog

Exploring how to code for iOS in Swift and Objective-C

  • Home
  • Apps
  • About
  • Contact

Supporting Dynamic Type for iOS7 Apps

Last updated on June 25, 2014

In a program I was working on, I decided to use Dynamic Type.  You can read about it here, but suffice it to say, it is a new way of handling text sizes in iOS7.  The user can set a value in their iOS device’s settings to set all text to be bigger or smaller than default, for any app that implements Dynamic Type.  This is a bit more advanced than my other posts, but it is surprisingly easy to do, so I thought I would write a post about what I learned.

Setup and using preferredFontForTextStyle

First off, you have to create an outlet for any label, textfield, or whatever you have that you want to dynamically change the text size of, so as to have a place to set the font.  The easiest way to do this is to use the assistant editor on your view, and command+drag your text control to the assistant editor (in the @interface area of your .m for a private outlet).  Once you release it will ask you a few questions, and the defaults are fine usually, so you just have to give it a name.

[Read more…]

Filed Under: Syntax

Objective-C Custom Initializers

Last updated on July 24, 2014

Let’s say you are programming a flashcard app.  In the model for these flashcards, you will have a flashcard object, and each flashcard has 2 strings as properties (one for the front of the card, and one for the back).  You could just alloc-init the card, and then set them later… but what use is a blank flashcard?  Why not only initialize a flashcard when those piece of data are provided?  That is what custom initializers are for.

Here is an example of making this flashcard class with its own custom initializer.

In FlashCard.h:

@interface FlashCard : NSObject

@property (strong, nonatomic) NSString *frontText;
@property (strong, nonatomic) NSString *backText;

- (instancetype)initWithFront:(NSString *)onFront back:(NSString *)onBack;

@end

In FlashCard.m:

#import "FlashCard.h" 

@implementation FlashCard

- (instancetype)initWithFront:(NSString *)onFront back:(NSString *)onBack
{
    if ((self = [super init])) {
        _frontText = onFront;
        _backText = onBack;
    }
    return self;
} 

@end

And that is pretty much all there is to it.  While it is not a lot of text, there are a few things that I had to look up a bit to understand what was going on in these statements, so I will go into more depth to explain some of the new things shown here.

[Read more…]

Filed Under: Syntax

Top Objective-C Learning Resources

Last updated on June 25, 2014

When I decided to start learning Objective-C, I started looking for a lot resources to assimilate, to learn as much as I could.  I have been a big fan of podcasts for the last couple years, so I searched for podcasts about iOS and Objective-C programming.  Early on, I found this post on the Accidental Technologist that listed several good podcasts in this field.  I will cover them here myself as well, but I thought I should call out where I found these in the first place.

Firstly, of course, are the Apple WWDC videos and sample code provided there if you are a registered developer at the iOS Dev Center.

Video

Stanford’s Developing for iOS Classes on iTunes U – These are absolutely amazing.  Out of all of the resources I have gone through, these have been the most helpful in getting me going.  Profesor Paul Hegarty covers many different aspects of Objective-C and iOS, from the basics to Core Data, and does so in a very casual and easy to understand way.

When gathering links for this blog post, I found that this iOS 7 version of the class is currently in progress, so I have linked it here.  I will be going back through these to see what new tidbits I can find that are iOS 7 specific.

[Read more…]

Filed Under: General

NSString – Objective-C Class Reference

Last updated on June 25, 2014

I have mentioned NSString in previous posts, so I might as well write about it in my new set of class reference posts.  I also keep forgetting the formatting specifiers, and so I’ll put up a table of those for everyone to see when you want to know the correct specifier for a formatted string.  As we’ve seen before, an NSString is an object that represents a block of text.  The name presumably comes from the fact that it is a string of characters, though that is just supposition, but does make it slightly easier to remember.  For a little history, in C, a string was an array of an 8-bit variable named “char”, which was short for character.  In each of those spots of an array was a number that would denote a letter based off of the ASCII standard.  If you’re curious, here is a link to a copy of the ASCII Table.  At the end of the string, to denote the end, was a NUL character, which is denoted by the number 0.  Unlike most of my trips into history though, this is actually still quite relevant to Objective-C.

[Read more…]

Filed Under: Class Reference

NSDictionary – Objective-C Class Reference

Last updated on June 25, 2014

Have you had a collection of objects that you want to by name?  Lets say you had an object that contains contact info for a person.  If I wanted to see the contact information for somebody, I’d want to just tell something, “Hey, give me Jimmy’s contact info”, and it would get it for me.  That is exactly what NSDictionary does for you.

NSDictionary is way to perform easy lookups for objects stored in the dictionary, via a key of some sort.  It basically stores data in something called a “key value pair”.  I will use the even simpler example of looking up the definition of a word in a standard Miriam-Webster style dictionary.  The word you are looking up is the “key.”  The definition you are trying to find for that word is the “value.”  In this post, I’ll go over some of the basics.

[Read more…]

Filed Under: Class Reference

  • « Previous Page
  • 1
  • …
  • 13
  • 14
  • 15
  • 16
  • Next Page »

Subscribe to the Coding Explorer Newsletter

* indicates required

Follow Us

Facebooktwitterrss

Recent Posts

  • Error Handling in Swift
  • Creating and Modifying a URL in your Swift App
  • Watch Connectivity in Swift — Application Context
  • watchOS Hello World App in Swift
  • API Availability Checking in Swift

Categories

  • Class Reference
  • General
  • Interface Builder
  • My Apps
  • Objective-C
  • Swift
  • Syntax
  • Tutorial
  • Uncategorized

Archives

  • May 2016
  • March 2016
  • February 2016
  • December 2015
  • July 2015
  • June 2015
  • April 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • January 2014
  • November 2013
  • September 2013
  • August 2013
  • July 2013
  • Terms Of Use
  • Privacy Policy
  • Affiliate Disclaimer

Subscribe to the Coding Explorer Newsletter

* indicates required

Copyright © 2025 Wayne Media LLC · Powered by Genesis Framework · WordPress