Use Carthage For Build Automation In Cocoa Apps

Note: these are just my notes to get started with Carthage and by no means a definitive resource of information.

Carthage is a tool that automates build dependencies for Cocoa apps and provides binary frameworks without modifying out-of-band project files. If you’re using homebrew, installing carthage is a one-liner:

Once installed, build a Cartfile in the home directory of xcode projects. The cartfile will list required projects, by version, as you can see here, which lists AlamoFire:

brew install carthage

Once Carthage is installed, you’ll need a cartfile for each project, to map the dependencies. This gives you the chance to resolve those when you’re building new software. Each time you add something new, simply put the dependency in there, taking into account when you want to use a given version or branch.

# Use the latest version github "AFNetworking/AFNetworking" # Use a local project git "file:///Users/krypted/project1" "branch1"

The above is an example that requires Alamofire (a http networking library commonly used) for the build process to complete as well as a local project file at /Users/krypted/project1 – and while this uses branch1 you can just delete that to not require a specific branch.

Next, we’ll do a quick update, which creates a Carthage directory in your .xcodeproj directory, as well as a cartfile.resolved file.

carthage update

That Carthage directory has a Build folder, which includes the artifacts required to build your project. Put all those in the appropriate platform folder.

Next, we need to tell Carthage to copy the frameworks at build time. To do that, we’ll run a script in the build phase, so click on the Build Phases settings tab and then click to add and select New Run Script Phase from the options. Simply put the following text in there:

/usr/local/bin/carthage copy-frameworks

Click on Input Files and then provide the path to the framework bundle, using “$(SRCROOT)” as the faux root of your .xcodeproj directory, as follows:

$(SRCROOT)/Carthage/Build/iOS/AFNetworking.framework

Click on Output Files and then provide the path to the framework bundle, using “$(SRCROOT)” as the faux root of your .xcodeproj directory, as follows:

$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/AFNetworking.framework

Then do a quick copy-frameworks to make them available and do the routine checking:

/usr/local/bin/carthage copy-frameworks

To then see warnings when artifacts are out-of-date, run Carthage with the outdated verb and a –xcode-warnings flag as follows:

/usr/local/bin/carthage outdated --xcode-warnings

To add this to your build process and have Xcode feed the warnings to you automatically, add this as another Build Phase.

Frameworks

A framework is a type of bundle that packages dynamic shared libraries with the resources that the library requires, including files (nibs and images), localized strings, header files, and maybe documentation. The .framework is an Apple structure that contains all of the files that make up a framework.

Frameworks are stored in the following location (where the * is the name of an app or framework):

  • /Applications/*contents/Frameworks
  • /Library/*/
  • /Library/Application Support/*/*.app/Contents/
  • /Library/Developer/CommandLineTools/
  • /Library/Developer/
  • /Library/Frameworks
  • /Library/Printers/
  • /System/iOSSupport/System/Library/PrivateFrameworks
  • /System/iOSSupport/System/Library/Frameworks
  • /System/Library/CoreServices
  • /System/Library/Frameworks
  • /System/Library/PrivateFrameworks
  • /usr/local/Frameworks 

If you just browse through these directories, you’ll see so many things you can use in apps. You can easily add an import followed by the name in your view controllers in Swift. For example, in /System/Library/Frameworks you’ll find the Foundation.framework. Foundation is pretty common as it contains a number of APIs such as NSObject (NSDate, NSString, and NSDateFormatter). 

You can import this into a script using the following line:

import Foundation


As with importing frameworks/modules/whatever (according to the language) – you can then consume the methods/variables/etc in your code (e.g.  let url = NSURL(fileURLWithPath: “names.plist”).

Apple Development Conferences

There are a lot of Apple developers out there these days. And it often seems like few groups like to share information more than those who work in the Apple space. So where can you go to learn more about Apple development? There are a lots of websites and code camps, but what about annual conferences?
  • WWDC: San Jose, CA – This is the grandaddy of them all. Hear from the people who build the frameworks and IDEs directly! But registration is limited and no everyone can go to that one place at that one date and time of the year. Also, different conferences can give different perspectives, so even if you go to WWDC every year, it’s worth looking at some of these other conferences as a +1!
  • AltConf: San Jose – Everything from iBeacons to how to name a product. The big thing is that it’s held alongside WWDC so I mention it first. By developers for developers – but not really connected to Apple’s developer relations. 
  • Mac Admin & Developer Conference UK: MacADUK is a great intersection between administration and development. A little bit of everything and a lot of smart. Grows every year. 
  • DevWorld: 
  • MacTech: This is more of an 
  • Appdevcon: Amsterdam – I like conferences for and by developers. And I like Amsterdam. 
  • Objective By The Sea: Hawaii!!! – Who doesn’t love a conference in Hawaii?!?! But more importantly, some of the top security minds in the Apple world have signed up for the inaugural conference to 
  • dot Swift: Paris – A Swift conference in Paris. I prefer how to write code type of conferences, or why pick a framework. So there ya’ go. In Paris.
  • RWdevCon: Washington, DC – I love the format of a tutorial-driven conference (and will likely emulate that in the future. Nothing gets rid of the silly touchy-feely stuff in tech conferences more than how-tos!
  • Swift by Northwest
  • iOSCon 2018: London – Any conference Aaron Hillegass ends up at is gonna’ be good. Especially if you live close. 
  • iosdevukAberystwyth, Wales, UK – iOS Development
  • forwardSwift: San Francisco – Talk about new Swifty-bits!
  • FunSwiftConf: New York – Fun is for Functional Swift!
  • App Builders: Switzerland – My and for app developers. 
  • try! Swift: New York and Tokyo
  • DeveloperWeek: Oakland, CA – More of an overall development conference
  • IndieDevStock
  • Playgrounds: Australia – No dates or location for next year, but it’ll be good.
  • Swift Summit
  • MobileWorld Congress: Barcelona – More upper level but with good dev sessions. Warning, developers sent here might end up writing their own games long term! 😉
  • UIKonf: Berlin – I love these videos, test driven development, specific information about frameworks (often from the people that wrote the frameworks. Awesome.
  • Teki-Con: Atlanta – Any conference Aaron Hillegass ends up at is gonna’ be good. Especially if you live close. 
  • 360 iDev: Denver – Good technical workshops that focus on metal and frameworks and all the fun stuffs.
  • Game Developers Conference: San Francisco – Guess what? Everything you learn building games translates to building any kind of app you could imagine. 
  • ADDC: Barcelona – More of a focus on design than hard core coding techniques. Some people are into that!
  • OSCON: Portland – Learn about all the latest and greatest open source languages and projects.
  • QCon New York – A bit more about organizing software teams and team structure.
  • Microsoft Ignite: Orlando – If you build enterprise software, you likely leverage the Active Directory, Azure identity, or even host on Azure, meaning Ignite is very pertinent to what you’re doing. While you might not see sessions on how to drop a specific Swift framework into a project, you might.
  • Google I/O: San Francisco – What I said above but for s/Microsoft/Google.
  • Facebook F8: San Jose – What I said above but for s/Microsoft/Facebook.
  • AWS reInvent: Las Vegas – What I said above but for s/Microsoft/Amazon
  • IT/Dev Connections: Dallas – When you deploy software, you likely need to automate the build process. When you get into that intersection between IT and DevOps, you should at least read the session descriptions for this conference to see if it’s something you’re into. 
  • DockerCon: San Francisco – If you devop (yes, I made up a verb) in Docker all day then this is your conference. 
  • DevOps Con: Berlin – More on DevOps, but in Germany!
  • MacDevOps YVR: Vancouver – More on Devops, but for Macs!
  • Jax DevOps: London – Devops, but a little more businessy and processy.
  • PowerShell and DevOps Global Summit: Bellevue (Seattleish) – Devops, but more Microsofty.
  • GoTo Conference: Chicago – More devops but kinda’ like an unconference. Which leads to some really interesting and diverse sessions. I like getting ideas from really niche workflows.
  • O’Reilly Fluent Conference: San Jose – Ever read an O’Reilly book on HTML5 or CSS or Java? If so, you will likely find this a cool conference. 
  • JavaOne: San Francisco – Like WWDC but for Java. 
There are also a number of conferences on general Apple administration topics. If you’re doing general Apple devops and admin work I’d definitely check those out! I have a page of those here:

Apple Admin Conferences

I like engineering topics, but if you’re into the businessy side of Apps, check out: 

Top Mobile App Conferences and Events To Go To in (2019)

List of ISO Country Codes

The following is a list of ISO country codes: AFGHANISTAN AF ALBANIA AL ALGERIA DZ AMERICAN SAMOA AS ANDORRA AD ANGOLA AO ANTARCTICA AQ ANTIGUA AND BARBUDA AG ARGENTINA AR ARMENIA AM ARUBA AW AUSTRALIA AU AUSTRIA AT AZERBAIJAN AZ BAHAMAS BS BAHRAIN BH BANGLADESH BD BARBADOS BB BELARUS BY BELGIUM BE BELIZE BZ BENIN BJ BERMUDA BM BHUTAN BT BOLIVIA BO BOSNIA AND HERZEGOVINA BA BOTSWANA BW BOUVET ISLAND BV BRAZIL BR BRITISH INDIAN OCEAN TERRITORY IO BRUNEI DARUSSALAM BN BULGARIA BG BURKINA FASO BF BURUNDI BI CAMBODIA KH CAMEROON CM CANADA CA CAPE VERDE CV CAYMAN ISLANDS KY CENTRAL AFRICAN REPUBLIC CF CHAD TD CHILE CL CHINA CN CHRISTMAS ISLAND CX COCOS (KEELING) ISLANDS CC COLOMBIA CO COMOROS KM CONGO CG CONGO, THE DEMOCRATIC REPUBLIC OF THE CD COOK ISLANDS CK COSTA RICA CR CÔTE D’IVOIRE CI CROATIA HR CUBA CU CYPRUS CY CZECH REPUBLIC CZ DENMARK DK DJIBOUTI DJ DOMINICA DM DOMINICAN REPUBLIC DO ECUADOR EC EGYPT EG EL SALVADOR SV EQUATORIAL GUINEA GQ ERITREA ER ESTONIA EE ETHIOPIA ET FALKLAND ISLANDS (MALVINAS) FK FAROE ISLANDS FO FIJI FJ FINLAND FI FRANCE FR FRENCH GUIANA GF FRENCH POLYNESIA PF FRENCH SOUTHERN TERRITORIES TF GABON GA GAMBIA GM GEORGIA GE GERMANY DE GHANA GH GIBRALTAR GI GREECE GR GREENLAND GL GRENADA GD GUADELOUPE GP GUAM GU GUATEMALA GT GUINEA GN GUINEA-BISSAU GW GUYANA GY HAITI HT HEARD ISLAND AND MCDONALD ISLANDS HM HONDURAS HN HONG KONG HK HUNGARY HU ICELAND IS INDIA IN INDONESIA ID IRAN, ISLAMIC REPUBLIC OF IR IRAQ IQ IRELAND IE ISRAEL IL ITALY IT JAMAICA JM JAPAN JP JORDAN JO KAZAKHSTAN KZ KENYA KE KIRIBATI KI KOREA, DEMOCRATIC PEOPLE’S REPUBLIC OF KP KOREA, REPUBLIC OF KR KUWAIT KW KYRGYZSTAN KG LAO PEOPLE’S DEMOCRATIC REPUBLIC (LAOS) LA LATVIA LV LEBANON LB LESOTHO LS LIBERIA LR LIBYAN ARAB JAMAHIRIYA LY LIECHTENSTEIN LI LITHUANIA LT LUXEMBOURG LU MACAO MO MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF MK MADAGASCAR MG MALAWI MW MALAYSIA MY MALDIVES MV MALI ML MALTA MT MARSHALL ISLANDS MH MARTINIQUE MQ MAURITANIA MR MAURITIUS MU MAYOTTE YT MEXICO MX MICRONESIA, FEDERATED STATES OF FM MOLDOVA, REPUBLIC OF MD MONACO MC MONGOLIA MN MONTENEGRO ME MONTSERRAT MS MOROCCO MA MOZAMBIQUE MZ MYANMAR MM NAMIBIA NA NAURU NR NEPAL NP NETHERLANDS NL NETHERLANDS ANTILLES AN NEW CALEDONIA NC NEW ZEALAND NZ NICARAGUA NI NIGER NE NIGERIA NG NIUE NU NORFOLK ISLAND NF NORTHERN MARIANA ISLANDS MP NORWAY NO OMAN OM PAKISTAN PK PALAU PW PALESTINIAN TERRITORY, OCCUPIED PS PANAMA PA PAPUA NEW GUINEA PG PARAGUAY PY PERU PE PHILIPPINES PH PITCAIRN PN POLAND PL PORTUGAL PT PUERTO RICO PR QATAR QA RÉUNION RE ROMANIA RO RUSSIAN FEDERATION RU RWANDA RW SAINT HELENA SH SAINT KITTS AND NEVIS KN SAINT LUCIA LC SAINT PIERRE AND MIQUELON PM SAINT VINCENT AND THE GRENADINES VC SAMOA WS SAN MARINO SM SAO TOME AND PRINCIPE ST SAUDI ARABIA SA SENEGAL SN SERBIA RS SEYCHELLES SC SIERRA LEONE SL SINGAPORE SG SLOVAKIA SK SLOVENIA SI SOLOMON ISLANDS SB SOMALIA SO SOUTH AFRICA ZA SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS GS SPAIN ES SRI LANKA LK SUDAN SD SURINAME SR SVALBARD AND JAN MAYEN SJ SWAZILAND SZ SWEDEN SE SWITZERLAND CH SYRIAN ARAB REPUBLIC SY TAIWAN TW TAJIKISTAN TJ TANZANIA, UNITED REPUBLIC OF TZ THAILAND TH TIMOR-LESTE TL TOGO TG TOKELAU TK TONGA TO TRINIDAD AND TOBAGO TT TUNISIA TN TURKEY TR TURKMENISTAN TM TURKS AND CAICOS ISLANDS TC TUVALU TV UGANDA UG UKRAINE UA UNITED ARAB EMIRATES AE UNITED KINGDOM GB UNITED STATES US UNITED STATES MINOR OUTLYING ISLANDS UM URUGUAY UY UZBEKISTAN UZ VANUATU VU VENEZUELA VE VIET NAM VN VIRGIN ISLANDS, BRITISH VG VIRGIN ISLANDS, U.S. VI WALLIS AND FUTUNA WF WESTERN SAHARA EH YEMEN YE ZAMBIA ZM ZIMBABWE ZW

pyMacWarranty variant in Swift on my GitHub

Posted a new swift command line tool to accept serial number data from an Apple device and respond with warranty information about a device at https://github.com/krypted/swiftwarrantylookup. This is based on pyMacWarranty, at https://github.com/pudquick/pyMacWarranty. Screen Shot 2016-03-15 at 10.34.41 PM

Hello Swift

Let’s do a typical Hello World example in Swift. I have Xcode installed, so I can invoke a swift environment using xcrun, a command to start an interactive Xcode environment and then defining swift as the language I want to use, as follows using a standard Mac terminal session: $xcrun swift Then I get a welcome screen, which is kind: Welcome to Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81). Type :help for assistance. Then, I can throw some string into a variable: 1> let mystring = "Hello Swift" And I get a response that the string was accepted, as a string: mastering: String = "Hello Swift" Then I can just echo that string out, popping it into a quoted and parenthetical (since it has a variable inside it, made regular by the \): 2> print ("mystring is \(mystring).") And I get the following response: mastering is Hello Swift. Pretty simple syntax. We can also use two strings and then use the + operator to concatenate (a typical programming task): let firstword = "Hello" let secondword = "Swift" let mystring = firstword + secondword print ("mystring is \(mystring).") Now that the basics are out of the way, why not build a Swift API…