Blog | Andy Ibanez https://www.andyibanez.com Teaching you cool stuff since 2012. Mon, 19 Aug 2019 22:08:54 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.10 39653125 In A Few Weeks From Now, This Old Website is Going Away. https://www.andyibanez.com/in-a-few-weeks-from-now-this-old-website-is-going-away/ https://www.andyibanez.com/in-a-few-weeks-from-now-this-old-website-is-going-away/#respond Mon, 19 Aug 2019 22:07:57 +0000 https://www.andyibanez.com/?p=586 Hello all. First, I want to start this post saying “thank you all”. I started this website in 2011 when I started earning some little money when I started college, and it has been a fun trip since then. I blogged mostly about iOS and occasionally covered different topics throughout the years. Sadly, it’s time […]

The post In A Few Weeks From Now, This Old Website is Going Away. appeared first on Andy Ibanez.

]]>
Hello all.

First, I want to start this post saying “thank you all”. I started this website in 2011 when I started earning some little money when I started college, and it has been a fun trip since then. I blogged mostly about iOS and occasionally covered different topics throughout the years. Sadly, it’s time for this specific website to go away.

You may be wondering why I’m taking this measure now. First, you need to remember that I haven’t blogged anything since 2017. My website has almost become irrelevant in terms of content as I haven’t put enough effort in keeping it updated, mostly because I’ve been busy with other things.

When I started this website, I was very surprised by how many people started sharing its content. Not only did people share it with others, people started referencing the content of my blog as a reference for what they were writing. Throughout the years my posts have been linked in StackOverflow answers, and I have even seen it linked from university websites! Makes me think that some tutors thought my content was worth it to share with their students. Seeing my content being spread that way brought big smiles to my face, especially when I noticed sudden spikes in my website’s traffic. Even more surprising, some people actually grabbed my original content and translated it to their own native language to share knowledge even further. I want to thank the people who did that as it made me feel that my content was appreciated.

Unfortunately, right now the vast majority of my content is outdated, and it’s not very relevant anymore. Also I think my writing style has changed throughout the years – I’ve read my older content and I just can’t believe I used to write the way I used to do. Despite being a college student at the time, my style is immature at best, and childish at worst. This kind of thing leaves a wrong impression in my image, and I want it to go away to pursue other endeavors.

Got ya! This is not a goodbye!

I’m not actually thinking in killing my website entirely. Rather, I think it’s time for a new beginning. I want this old website to go away so I can start anew. I do not only want to start writing higher-quality content, but I also want to have a bigger level of compromise with the people who have been reading me in the past 8 years.

And this is I want to do: I want to start a new website, with this very same domain, but with a different format, and with higher quality content. The new website will still be a blog, but I will be using a static site generator instead of WordPress (which frankly I’ve wanted to get rid of for a long time now, but I’m just getting into it).

You might be wondering why such a dramatic post if this website is going to continue in some form anyway. There’s a few reasons for that. First, I wanted to give a big and legit thank you to all the people who have read my blog in the past years. I started blogging as a personal log of things I learned, but it eventually turned into this big thing that got shared around more than I had expected. The second reason is that I want to start with new fresh content, and that means that all my blog posts are going away. They are not being migrated to the new site. Save for a very few exceptions (it’s probably about 10% of my content), everything is going to be deleted, and I wanted to give my readers a change to archive any blog posts that they don’t think are gonna make the cut.

If you want to ask me what content is gonna be carried over to the new site, the answer is “I don’t know yet”. I have the WordPress data that shows me what posts are still very popular, but I do not want to carry all of those to the new site. Also popularity is not related to quality or even relevancy. For example, the article “Are You Storing Sensitive Data in NSUserDefaults? Stop Doing That!” is one of my most popular posts to date. This one has been shared and translated many times. The problem with it is that, while the core idea of the post is still very true today, many things have changed since I posted it – you cannot really access the plist file as easily anymore, so I’d have explore things again and see to what level is still relevant, and whether it deserves such many words to express the main idea. Also, I absolutely HATE the writing style on that one. It makes me want to pull my hair off. It’s very popular, but I feel embarrassed it has been read so many times. Another article that is popular is Multithreading on iOS And Mac OS X Using NSOperations.. This a popular article (not as popular as the other one, though) and the content on it is still very relevant today. The problem with it is, again, my awful writing style. I might carry this one over but not as it currently is. Instead, I might rewrite it from scratch.

Some posts will disappear completely altogether, and the others will be rewritten from scratch. I’m still deciding which ones will make the cut.

As for when this website will go away for sure, I cannot really give a solid date yet. I’m currently working on the new website and exploring static generator tools (I think I’m gonna stick with Hugo). Once I choose the static gen tool, I will go through my old content and choose the ones that will be carried over to the new website. All this could be done for this Friday as it could be done next Friday, or in six weeks from now or more (or less). The new website will not be launched with empty content, and I will do my best to map their URLs to the new website so they don’t break across the vast ocean that is the internet. Also, as part of my compromise to you guys, I will start blogging more often. I will try to organize myself better to write more often. In the past months I have followed many other Swift Devs and I’ve been inspired to involve myself with the community more. I have a desire, and that desire is to be relevant in the Swift and iOS communities again, and I cannot do it with my old content.

So, if you care about still having access to the old content from this website, make sure you save what you care about it. If you are an archivist, please do me a favor and save my website in a way that can be accessed (I can’t be bothered to take such measures myself) by others in the future.

For updates on the upcoming website, follow me on Twitter (@AndyIbanezK), and once again, thank you all for your support.

The post In A Few Weeks From Now, This Old Website is Going Away. appeared first on Andy Ibanez.

]]>
https://www.andyibanez.com/in-a-few-weeks-from-now-this-old-website-is-going-away/feed/ 0 586
Introducing fsduplicates https://www.andyibanez.com/introducing-fsduplicates/ https://www.andyibanez.com/introducing-fsduplicates/#comments Sun, 26 Jun 2016 22:53:15 +0000 https://www.andyibanez.com/?p=546 Just very recently, I wrote a blog post where I suggest people use audio fingerprinting techniques to better search and identify for duplicate songs in their libraries instead of using metadata. I also provided a half-assed script to attempt to do it easily. That script simply did not work as expected, and ultimately writing something […]

The post Introducing fsduplicates appeared first on Andy Ibanez.

]]>
Just very recently, I wrote a blog post where I suggest people use audio fingerprinting techniques to better search and identify for duplicate songs in their libraries instead of using metadata. I also provided a half-assed script to attempt to do it easily.

That script simply did not work as expected, and ultimately writing something that would scan for duplicates was slightly more complicated.

Introducing fsduplicates

Today I’m introducing a better tool that I have built since I wrote that blog post. The tool is called fsduplicates, and it is a command line tool that interacts directly with the AcoustID database.fsduplicates is incomplete, but it is pretty usable for now. It is written in Swift 3 and it is fully open source.

fsduplicates has two main functions: To scan and fetch the AcoustIDs of each song in the AcoustID database (called the indexing process), and duplicate indentification. Using the tool is really easy.

The indexing content is done using the -f flag. Note that you can issue the -v flag to all commands to trigger verbosity.

fsduplicates -f DIR_TO_SEARCH DIR_TO_OUTPUT

An example:

fsduplicates -f /Volumes/iTunes/Music/Nightwish ~/Documents/fsduplicates_nightwish

This will recursively index the contents of the folder you passed as DIR_TO_SEARCH. Do note that this process can take a long time, not only due to the fingerprinting process but to play well with AcoustID’s rules. All the results will be dropped in DIR_TO_OUTPUT (also called a Library). fsduplicates will not move or delete any files. The Library directory will contain three plain text files with info about the songs:

  • library contains a list of all the songs it indexed. This is a simple list of file paths to songs. This is used by fsduplicates to prevent reindexing songs and save you time. The advantage of having this file is that, if you are indexing a large directory and you want to stop, the reindexing process can be restarted later without losing progress.
  • fps_library contains a list of AcoustIDs and the files that match them. If you wanted to analyse your duplicates manually, you would use this pair. Each line stores the data as acoustid:filepath to make it easier to parse using standard Bash tools.
  • no_fps_library contains a list of file paths that did not have a matching fingerprint in AcoustID’s database. Consider contributing the fingerprints of these songs to their service to help them improve.

After the indexing process is done, you can show results using the -s flag.

fsduplicates -s LIBRARY

Example:

fsduplicates -s ~/Documents/fsduplicates_nightwish

This will group fingerprints with file paths that matched them to make it easier to see which songs are duplicated.

-----------------------------------
Showing Duplicates for 08fcc296-7d3f-483f-86ea-cfbe725d291d:
1. /Volumes/iTunes/Music/Nightwish/Bless The Child/02 The Wayfarer.m4a
2. /Volumes/iTunes/Music/Nightwish/Century Child/12 The Wayfarer.m4a
3. /Volumes/iTunes/Music/Nightwish/Ever Dream/03 The Wayfarer.m4a
4. /Volumes/iTunes/Music/Nightwish/Highest Hopes/2-01 The Wayfarer.m4a
5. /Volumes/iTunes/Music/Nightwish/Tales From The Elvenpath/15 Wayfarer.m4a
6. /Volumes/iTunes/Music/Nightwish/Wishsides/2-03 The Wayfarer.m4a
-----------------------------------

-----------------------------------
Showing Duplicates for e9ffe05f-ad4a-4906-afca-26cbbf628787:
1. /Volumes/iTunes/Music/Nightwish/Bless The Child/09 Lagoon.m4a
2. /Volumes/iTunes/Music/Nightwish/Century Child/11 Lagoon.m4a
3. /Volumes/iTunes/Music/Nightwish/Highest Hopes/2-08 Lagoon.m4a
4. /Volumes/iTunes/Music/Nightwish/Tales From The Elvenpath/14 Lagoon.m4a
5. /Volumes/iTunes/Music/Nightwish/Wishsides/2-07 Lagoon.m4a
-----------------------------------

If you pass in the -i flag, you will be able to choose an action for each group. Currently, there’s only the option to create symbolic links of each file in the group in the directory or to skip the group. In the future I will add more actions, like the ability to directly delete the duplicates or move them entirely to the Library path.

fsduplicates -s -i ~/Documents/fsduplicates_nightwish

Sample output:

-----------------------------------
Showing duplicates for 08fcc296-7d3f-483f-86ea-cfbe725d291d:
1. /Volumes/iTunes/Music/Nightwish/Bless The Child/02 The Wayfarer.m4a
2. /Volumes/iTunes/Music/Nightwish/Century Child/12 The Wayfarer.m4a
3. /Volumes/iTunes/Music/Nightwish/Ever Dream/03 The Wayfarer.m4a
4. /Volumes/iTunes/Music/Nightwish/Highest Hopes/2-01 The Wayfarer.m4a
5. /Volumes/iTunes/Music/Nightwish/Tales From The Elvenpath/15 Wayfarer.m4a
6. /Volumes/iTunes/Music/Nightwish/Wishsides/2-03 The Wayfarer.m4a
-----------------------------------
What do you want to do?:
(s)ymbolic link all to Library       (i)gnore

OPTION: 

Creating symbolic links is useful, because you can then drop them into a music player to listen to them.

Downloading fsduplicates

Head over to the project page on Github and download it from there. The install and more complete usage instructions are on the README.md. The project is open source and I welcome contributions, even if they are just cleaning the hacky code I wrote.

Warnings and other notes

I consider this product to be mostly incomplete, but it’s complete enough for my needs. You agree to use this tool under your own risk and not blame me if it creates a black hole in your computer.

The post Introducing fsduplicates appeared first on Andy Ibanez.

]]>
https://www.andyibanez.com/introducing-fsduplicates/feed/ 3 546
Eliminating the C For Loop Is Not Bad for Swift. https://www.andyibanez.com/why-eliminating-c-style-for-loops-is-not-a-bad-thing-for-swift/ https://www.andyibanez.com/why-eliminating-c-style-for-loops-is-not-a-bad-thing-for-swift/#comments Fri, 18 Dec 2015 19:44:30 +0000 https://www.andyibanez.com/?p=417 Eliminating C-Style for loops is not a bad thing for Swift, as there are other kind of loops that can be used and even alternatives to loops themselves.

The post Eliminating the C For Loop Is Not Bad for Swift. appeared first on Andy Ibanez.

]]>
The C-style for ;; loop simply has no place in Swift.

Recently, it has been announced by Chris Lattner himself that Swift will do away with the classical C-style for ;; loop. The suggestion was done by Erica Sadun, one of the most respected members of the iOS Development Community, and her proposal has been accepted for Swift 3.0. This for loop is used in almost every programming language, from Java to Objective-C (of course, it’s just a superset of C after all) and beyond.

It sparked this Reddit discussion about the decision. Many people support the removal of the for ;; loop and many of them seem to be worried. In this post I want to explain why I support the elimination of the C for loop, and why people shouldn’t be worried about its removal in the future.

In this post, I want to urge you to write code with as little loops as possible, and to embrace higher order functions whenever possible. At no point will I suggest you stop using loops altogether. If anything, use the other loops (for-in and repeat-while) instead of for ;;.

Everything that can be done with a loop, can be done without it.

Swift will keep some of its loops, like repeat-while and for-in, so it’s not like Swift is getting rid of the ability to loop altogether.

But even if it were, there are more, cleaner, alternatives to loops. Let’s talk a little about functional programming, which Swift seems to embrace a lot, to see why.

Functional programming is the programming paradigm that embraces immutability and the reduction of side-effects. Think about the difference between let and var. If you are reading this, you are familiar with how these keywords work. Anything you declare with let cannot be changed. Anything declared with var is fair game to be changed in the future.

In a pure functional coding style, you would avoid using var because everything is immutable. This means that there cannot be the concept of a counter variable, because they are incremented or decremented at some point, and that’s not immutability. Now of course, in the real world it is impossible to achieve full functional code, since any user interaction that happens must cause something to happen somewhere in your program. But still, I believe coding “functionally” whenever possible is going to help you write much better code, and using as few little loops as possible is going to help you do that. Getting rid of the classic C-style loop is a very good beginning to start writing functional code.

Like I said in the Reddit thread I mentioned above, I took a functional programming class in Scala in which we didn’t write a single loop, despite the fact that Scala for loops don’t technically violate the principle of immutability. Can you imagine writing a lot of code without a single loop, despite tasks that may need them? It’s entirely possible using recursion and higher-order functions.

Recursion

Recursion is an important topic, and arguably one of the hardest topics for newcomers in programming to understand. One of the reasons people are hating the removal of the C-style for ;; loop is that they say transitioning to Swift from whatever your first language is will be hard, and if you have been programming for a while, it will be hard to get used to. This is not so necessarily true because the concept of recursion is the same everywhere, so even if learning the Swift loops and higher order functions was too complicated, you could still achieve the same results using recursion. This is a big even if, because Swift’s loops are easy, and higher order functions are not too complicated to understand. Really, the only reason you would want to keep for ;; around is to make it easier than it already is to transition from any other language to Swift, and for legacy reasons. I imagine a programmer who has been writing code for the last 20 years has written many for ;; loops, but programming paradigms change, some are introduced, and it is all for the better for Software Development. We simply cannot cling to all idioms and features of old languages for too long.

I think recursion has its place. Some algorithms are better with it, and some of them are more complicated than they should be. Use recursion when it makes sense. I am not saying you should ditch loops altogether after all, and I definitely don’t want people to write over complicated algorithms with recursion when they could have been done with a Swift loop (as long as the loop in question is not a for ;;).

Higher Order Functions

Higher order functions can replace loops for around 90% of tasks that require them, I’d say. The Wikipedia page on Higher-Order Functions defines a higher order function as:

In mathematics and computer science, a higher-order function (also functional, functional form or functor; not to be confused with the functor concept in category theory) is a function that does at least one of the following:

  • takes one or more functions as arguments,
  • returns a function as its result.[disputed – discuss]

This is the definition copied and pasted from Wikipedia as of December 18, 2015 at 2:35 PM – Please note that the second bullet point is marked as disputed.

In short, a higher order function can take one or more functions (if you really are an old school programmer, think of it as a function taking a pointer to a function in C++. If you have worked with C# before, think of lambdas. And, if you are writing in Java 8 and above, think of anonymous functions) and then execute them. Note that the Wikipedia article says that a higher order function returns a function and it is marked as disputed. And rightly so – I’d probably say that a higher order function takes one or more functions as parameters and it might return another function – That is, I wouldn’t say returning a function is required for it to be considered a higher order function. Swift includes many higher order functions for collections that help you reduce the usage of loops.

If you are new to programming, this discussion may be hurting your head a little bit. The good news is I have code examples ready to illustrate how you can reduce the use of loops altogether.

For this example, I will adapt some old code of mine to loops, and then I will show you how to reduce it to using HOFs. This code comes from my app Mignori, and it’s purpose is to run through a JSON response from a web service and to map each JSON object to a class manually with the help of SwiftyJSON. I am not using an object mapper for this as I consider it to be overkill for my specific purpose, but I digress.

You could start with the “naïve” approach. Suppose you just talked to a web server and got a lot of JSON back and you want to map it to your own class. You could do this (I need to state I never used this for loop in the app, but I adapted it from the second snippet):

let json = JSON(data: data)
var createdPosts = [Post]()

if let posts = json.array {			
	for var i = 0; i < posts.count; i++ {
		let post = try Post(json: posts[i], server: self.server)
		createdPosts += [post]
	}
}

Simple enough right? We got the results as a JSON array, and we are going through each element to create a Post with it. The details of a Post object are not important in this article.

If you have been programming for a while, particularly in Swift, you may notice that we can do the same thing, in a cleaner manner, using a for-in loop.

let json = JSON(data: data)
var createdPosts = [Post]()
            
if let posts = json.array {
	for post in posts {
		let post = try Post(json: post, server: self.server)
		createdPosts += [post]
	}
}

This will iterate through each element and then create a Post object with it, without needing to use the array index.

But this can be even better, by using the map higher order function. This function will iterate through each element of the array, do something with it, and return it. In this case, we are converting a raw JSON object to a Post object. That is, we are mapping JSON to Post.

let json = JSON(data: data)
let createdPosts = try json.array?.map({ (jsonPost) -> Post in
	return try Post(json: jsonPost, server: self.server)
})

The map higher order function takes a function. The function you pass as a parameter is the operation that will be done to each object of the JSON array. The map function itself will return a new array – In this case, a new array of Post objects.

This is much, much better and more functional than the approaches described above. The best part is you can still simplify it further without hurting readability:

let json = JSON(data: data)       
let createdPosts = try json.array?.map { return try Post(json: $0, server: self.server)}

Terrific! Something that took us over 5 lines of code before, now takes us two! The $0 is a placehorder for the value the function is giving you – In this case, the JSON Post. If the function had two parameters, you could use $0 and $1 – and so on.

Important Higher Order Functions

If I managed to show you how powerful higher order functions are, then there’s a few of them you should know about. I am not going to explain to you how they work, and I will leave them as an exercise for yourself. Keep in mind you can apply these functions to any collection that conforms to the CollectionType protocol, and as such you can create your own collection types that support these HOFs.

  • map: Map is the function we just saw, which allows you to to operate over the elements of a collection and then return a new array with the results.
  • filter: The filter function will take a function that returns a boolean. You will decide what objects should be part of the new array and which ones won’t. For example, if you have an array of numbers that go from 1 to 200 sequentially, you can filter the array to return a new one that contains only even numbers.
  • reduce: The reduce function will collapse a collection into something else. For example, suppose you have an array of numbers, and you wanted to add them up and return that result. You could achieve this using the reduce function..

There’s many other higher order functions to explore, like flatMap, but they are not as widely used so if you want to know more about them, check the Swift documentation.

When to use Loops

To end this discussion, let’s talk about when you may actually want to use loops. Like I said before, my intention is not to destroy the usage of loops altogether, but rather to decrease their usage as modern programming languages have better alternatives for many cases.

First, don’t use C-style for ;; loops. They are not needed, not at all, and they are going to be removed for Swift 3.0 anyway.

Second, in the case you need to iterate through a collection and you need the index in each operation (basically the only valid usage for for ;; loops I can think of), then you can use the enumerate() method:

for (index, value) in shoppingList.enumerate() {
    print("Item \(index + 1): \(value)")
}

(Code taken from the official Swift guide)

Third, even non-enumerated for-in loops have their uses. I use them to print quick debugging info:

for tag in tagsArray {
	print("tag is \(tag)")
}

Finally, the repeat-while and while loops. These loops can have their use cases, but DO NOT use them to iterate through collections. There’s simply no need to do that. To be honest I haven’t needed to write one of these loops in a long time. I would say their uses are limited, but you would use them for things like this:

while !coffee.empty {
	coffee.drink()
}

Use these loops when you need to do something as long as a condition is true. I repeat, do NOT use them for iterating through collections. Because while you can do that, semantically it doesn’t make any sense. You have all the alternatives for that above.

Conclusion

I welcome the removal of the C-style for ;; loop, because modern languages have better and more robust alternatives to do what you would do with them. We cannot stick to legacy conventions forever, and removing the for ;; loop is a great first step to get rid of them. This may not apply to all languages, but it definitely applies to Swift.

I encourage every developer to adopt the usage of functional paradigm philosophies when it makes sense, and to decrease the usage of loops throughout their code whenever possible.

The post Eliminating the C For Loop Is Not Bad for Swift. appeared first on Andy Ibanez.

]]>
https://www.andyibanez.com/why-eliminating-c-style-for-loops-is-not-a-bad-thing-for-swift/feed/ 4 417
Automatic App and WatchKit App Build Numbers with Xcode. https://www.andyibanez.com/automatic-app-and-watchkit-app-build-numbers-with-xcode/ https://www.andyibanez.com/automatic-app-and-watchkit-app-build-numbers-with-xcode/#respond Sun, 04 Oct 2015 01:54:27 +0000 https://www.andyibanez.com/?p=401 Build Numbers in Xcode The “Build Number”, also known as “Bundle Version” is a field of your info.plist file in your app project. This help helps you build and sort different builds of your app. This field is pretty much free from. You can set your build numbers as you want. I used to use […]

The post Automatic App and WatchKit App Build Numbers with Xcode. appeared first on Andy Ibanez.

]]>
Build Numbers in Xcode

The “Build Number”, also known as “Bundle Version” is a field of your info.plist file in your app project. This help helps you build and sort different builds of your app.

This field is pretty much free from. You can set your build numbers as you want. I used to use a YYMMDD format – Before releasing an app, I would set this field manually and then submit it to iTunes. This is why Mignori has funny bundle numbers: The first version was something like 131229, indicating I completed it and submitted it to iTunes on December 29, 2013. The third build number was 140309, indicating I submitted that version on April 9, 2014, and so on. What I like about doing things like this is that you know exactly when you finished a version and uploaded it to iTunes.

But, more often than not, the build number is either the number of times you built your project – That is, the number of times you clicked the “Play” button on Xcode, or the number of Commits on your Git repo. I eventually started doing the Git repo way, because sometimes I would forget to update the build number manually and it would be a little bit annoying to fix.

Specially with WatchKit apps now. Things are slightly more complicated, but nothing too extreme. Your main app’s Build Number and your WatchKit app’s Build Number have to match. If they don’t watch, Xcode will refuse to compile your project. So save yourself a little bit of trouble it’s easier to have this field update automatically instead of setting it twice.

You can use this bash script to set the build numbers to the number of commits on your git repo:

# Set the build number to the count of Git commits
buildNumber=$(git rev-list --count HEAD)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"

I graciously got this snippet from StackOverflow. But it was a long time ago, so unfortunately I cannot properly credit the author. If you know the author of this script, please let me know so I can update this post. Thanks!

To automatically update your build numbers to the number of git commits in your repo, add the script as following:

  1. Click on your project’s “blue print”.
  2. Select your main app target.
  3. Select “Build Phases” on the tab at the top.
  4. Click the + button, and select “New Run Script Phase”
  5. Copy and paste the script there.
  6. Repeat steps 5 – 6 for your WatchKit app (Select your WatchKit target first).

Xcode Build Numbers

(Click to enlarge).

Now, whenever you click the “Play” button on Xcode, the Build Number will be updated automatically.

If you prefer, you can adapt this to make your Build Number the number of times you physically built your app. The gist is to grab the current build number, add one, and then put it in the appropriate environment variable.

The post Automatic App and WatchKit App Build Numbers with Xcode. appeared first on Andy Ibanez.

]]>
https://www.andyibanez.com/automatic-app-and-watchkit-app-build-numbers-with-xcode/feed/ 0 401
How To Ask Programming Questions. https://www.andyibanez.com/ask-programming-questions/ https://www.andyibanez.com/ask-programming-questions/#respond Thu, 09 Oct 2014 19:11:04 +0000 https://www.andyibanez.com/?p=350 Asking programming questions is actually kind of an art. Learn to ask programming questions properly so you actually get help.

The post How To Ask Programming Questions. appeared first on Andy Ibanez.

]]>
Programming Questions

You’ve just decided to start your travel in the world of programming. You are new to this world, there’s so many things and everything is very confusing. It’s tempting, and it is okay, to ask programming questions. But there’s a few things you should do before asking them.

I have been programming since 2006. I started learning when I started high school, and I have asked thousands of programming questions in my way and I know what kind of questions are going to make other programmers avoid your questions. You have probably heard that programmers are assholes by many other people. But this is not necessarily true. You see, when people ask questions in Stackoverflow or other places, they should make sure their programming questions fill a few requisites before asking them. The truth is, many of us, who have been programming for years, are willing to help you with your problems, but we expect you to have done your research and try before doing so. Yes, we think many questions are a waste of time – yes, many times we think the person asking questions is lazy to provide details to their problems, and yes, we think that it is a waste of time to help someone who hasn’t tried any solution at all before asking for help. People who think programmers are assholes are people who didn’t know how to ask programming questions in the first place.

Read this article before you ask programming questions to anyone or anywhere. Be it on Stackoverflow, a Facebook group, an old-fashioned forum, or anywhere else.

1. Ask specific and straight questions.

“Hi i just started learning *insert language or technology help*. Pls help!”

STOP for a moment there. Okay, you just started learning something, and you need help. Sure, cool. But help with what? Do you need help setting up the Facebook SDK for iOS? Where are you having problems exactly? If you need help setting up the Facebook SDK, have you read the documentation at all? Are you stuck, do you get an error message? What is preventing you from doing what you want to do?

Bad question:

“I cannot install the Facebook SDK. Please help.”

Good Question:

I cannot install the Facebook SDK to use with my Corona SDK app. I followed the official guide but when I get to step 8, I get an error saying that my Facebook tokens are invalid. I have created the tokens via my Facebook developer panel and copy and pasted them into the SDK. Can somebody help me with this?

Yes, the “Good Question” in this case is long. More often than not, you will not have to write something this long to ask for help, but the point still stands – The good question is specific. It’s saying exactly what’s wrong, what he has tried, and what he has tried to do. This is how all your programming questions should be.

2. We don’t care how old you are.

I see this a lot, specially in Facebook development pages and iOS development pages on Facebook.

Hi I am 12 years old and I’m learning how to make apps. Please help.

Many people seem to think that their age is an excuse to get exclusive, extremely aided help with their problems. This is not the case. Regardless of how old you are, if you ask programming questions, then ask good programming questions – If you are a 9 years old learning Assembler, we are expecting the same quality of questions someone “older” would be asking us. You should not be expected to receive exclusive help based on your age, gender, or nationality.

3. Before you ask, read the docs.

“How do I install the Facebook SDK?”

If you ask this one, you will get a thousand of responses, but none of them will be a walkthrough or step-by-step tutorial to install the SDK – All the answers will be people linking you to the docs of what you’re trying to learn (or tutorials, in case of a language), LMGTFY links, and people belittling you for being lazy and not reading the docs.

If you don’t like reading official documentation, then programming is not for you. So get into the habit of reading documentations, tutorials, and books before you ask programming questions

4. Google It.

This is exactly what I said in the previous point. Research before asking. Don’t waste our time. Don’t waste your time by wasting our time.

5. “What have you tried?”

There is nothing we hate the most than people asking for help by showing us no proof they have tried anything at all.

I can’t post to the user’s timeline using the Facebook SDK.

Yeah okay, cool. But what have you tried? Tell us what you have tried so we can tell you what you did wrong. You didn’t try anything? Sorry dude, here, have this link to the docs. Hope it helps.

Sometimes, it is perfectly fine to ask questions without trying, and that is exclusively if you have no idea of what to do next. But this should never happen. With the vast amount of tutorials, articles, and docs, it’s impossible to simply not know what to do. If you don’t understand something in the docs, then it is fine to ask questions without trying. But for most cases, there is no excuse to simply not know what to do.

6. We will not do your work for you.

“I want to get a user’s friendlist with the Facebook SDK. Pls gimme the codes”

I will do that for $us 1200.

“Soz i am a 14yo old programmer and I’m poor.”

Shucks. Have this link to the docs. Hope it helps.

7. “It doesn’t work”!

Naturally, when you ask programming questions, chances are something just doesn’t work. But what doesn’t work, exactly?

I want to send an inbox message to all the users in a friendlist using the Facebook SDK but it doesn’t work. Please help!

What errors are you getting exactly?
What happens and what is supposed to happen instead?

We are not mind readers and in software, there’s virtually thousands of things that could break other things to the point they just “don’t work”. But if you are not giving us error messages, a description of the unexpected behaviour, and optionally the code you have tried, there’s nothing we can do. All “doesn’t work” things have a cause. Is your app crashing? Do you get an error message? Does your computer turn into a sadistic robot and spanks your wife? If you don’t tell us why it doesn’t work, we cannot help you at all.

There are times when things really just “don’t work”, but we expect you to tell us that.

“I’m trying to get to send an inbox message to all the user’s friendlist using the Facebook SDK. I have read the documentation and read about the inbox/send_all method but it just doesn’t work. My message is not being sent and I do not receive any error message at all. Literally nothing happens. Can somebody help me? Here’s my code:

If you are just learning programming, let me tell you that when you start shipping products to the world, your users will message you saying your software just “doesn’t work”, and you will be frustrated if they do not give you any details at all. You will have to inquiry your users and ask them to describe step by step what causes their issues, and sometimes ask them for crashlogs. “Doesn’t work” is one of the things we programmers hate the most. We need to know what you’re doing to ruin everything.

8. Please do not ask us for personal help.

We are happy to help you with your problems – That is, as long as we find your programming questions in Stackoverflow or other places we frequent. But please do not bother programmers asking them for their emails or Skype handles so you can have an experienced programmer handy whenever you have problems. I’m telling you right now, we all hate that. We are not your mentors, and we simply are not willing to give you personalised help all the time (some may do it if you pay them). Instead of attempting to keep personal touch with programmers who helped you before, learn to ask questions appropriately so you can effectively ask them in Stackoverflow or other places so you can get help.

Bottomline

I have no intentions of discouraging you of asking programming questions, but I, and all other programmers who have been writing code for years, want you to ask questions in a way we can help you and in a way you don’t waste our and your time. This field requires you to read a lot and to be ready to do your own research. It’s fine to ask questions, but keep in mind other programmers are not willing to keep up with your problems all the time.

The post How To Ask Programming Questions. appeared first on Andy Ibanez.

]]>
https://www.andyibanez.com/ask-programming-questions/feed/ 0 350
“Your developer account needs to be updated.” https://www.andyibanez.com/developer-account-needs-updated-fix/ https://www.andyibanez.com/developer-account-needs-updated-fix/#comments Wed, 04 Jun 2014 22:43:01 +0000 http://andyibanez.com/?p=283 I have been dealing with this issue for a bit shorter than a year. Must have been 8 months since we created the Apple Developer account we were going to use for our company, and it was then when I started seeing this message whenever I tried to do many tasks on XCode. I’m sure […]

The post “Your developer account needs to be updated.” appeared first on Andy Ibanez.

]]>
I have been dealing with this issue for a bit shorter than a year. Must have been 8 months since we created the Apple Developer account we were going to use for our company, and it was then when I started seeing this message whenever I tried to do many tasks on XCode.

I’m sure I am not the only one. How many developers have seen this error message, when doing something in XCode, like adding devices to the member center, or enabling entitlements?:

Your developer account needs to be updated. Please visit the Member Center.
https://developer.apple.com/membercenter

Good news! I have a solution for this, and if I was able to fix it, I’m sure you can too.

What to check first.

First you should log into the Member Center and make sure you have accepted all agreements. Apple tends to update them after every major event (WWDC, Special Events), so you need to accept them. Once you do, this message should go away.

If that doesn’t work…

First, I need to state that I have my personal Apple Developer Account, and my company has another different account. In the company’s developer account, I added myself as a developer so I could build and run those apps using my own account. It looks like many people have this issue because their Apple account is linked to more than one Developer account. When I learned that, I tried to remove myself from the company’s account. I did, and it didn’t work as a solution for me (some people report this fixed their issue though – so you can try to fix it this way).

Second, you need to know that, if the above fix didn’t work, then it’s most likely this isn’t a problem with Apple’s servers, like the error seems to imply… Actually, it may be a problem on your side, which takes me to my third point:

Third, you need to know that I have more than one Apple account, and if you have more than one account, this is what may be causing the problem in your case as well. The Apple account I use to buy stuff from the App Store or iTunes is not the same account I use to publish my apps. And this is actually where my problem was. Since I have at least two Apple accounts, it looks like XCode was confused as heck when it saw both. If the solution in my first point didn’t solve it for you, try this now:

  1. Open XCode, and in the main menu go to XCode > Preferences.
  2. Click the “Accounts” Tab. You should see something similar to this:
    Accounts 1
    If you have more than one “Apple ID” there, then that may be the problem. It looks like this problem only happens if one of the Apple IDs there is not a developer. I cannot confirm this for sure, but the few tests I made seem to imply I am right.
  3. Highlight the account that is NOT a registered Apple developer, and click the “-” button at the bottom of the screen to remove it. You should now have one account only (or only accounts that are registered developers).
    Accounts 2

You should now be able to do your things in XCode without having to deal with that irritating warning. You don’t even need to restart XCode, or at least in my case, I was able to enable entitlements as soon as I removed my non-developer account.

I am not sure if the account was added to XCode automatically from the Settings Accounts page on my Mac, but if you remove your Apple account from XCode, it will not remove it from your Mac altogether (it will still be in Settings > Accounts).

I hope this helps you deal with this absurd error. You have two fixes in this post and I hope one of them works for you.

The post “Your developer account needs to be updated.” appeared first on Andy Ibanez.

]]>
https://www.andyibanez.com/developer-account-needs-updated-fix/feed/ 6 283
Quick Tip: Compile OpenSSL For Both ARM and ARM64 for iOS. https://www.andyibanez.com/quick-tip-compile-openssl-arm-arm64-ios/ https://www.andyibanez.com/quick-tip-compile-openssl-arm-arm64-ios/#comments Tue, 14 Jan 2014 07:32:58 +0000 http://andyibanez.com/?p=215 Learn hoiw to compile OpenSSL for both processor architectures for iOS. OpenSSL is needed by some cryptographic libraries.

The post Quick Tip: Compile OpenSSL For Both ARM and ARM64 for iOS. appeared first on Andy Ibanez.

]]>
OpenSSL

Recently I had to add In-App Purchases to an app I am developing as a personal hobby. Dealing with IAP alone can be a pain if you don’t know much about cryptography, but luckily there are many libraries that make this process simpler.

But here’s a small catch: Almost all of the IAP libraries (and many other libraries you will want to use) require OpenSSL. Particularly libraries that deal with cryptography may need it. With the release of the iPhone 5S and it’s 64-Bit processor, it is a little bit tricky to compile it and get it to work.

At first I found a pre-compiled version of OpenSSL and added it to my project. The problem was that I was only testing with an iPod Touch 5, and as such I didn’t see many potential problems with the different processor architecture of the 5S. I used that pre-compiled OpenSSL library for a while until I tested it on my iPhone 5S and oh boy. Whenever  I tried to compile for ARM64, it complained that all the cryptography-related symbols were not found.

Luckily, compiling OpenSSL to work with both ARM and ARM64 is really easy and fast.

Step by step:

  1. Download this shell script.
  2. Create a new directory and cd to it. It’s easier to see all the generated files this way (for the sake of simplicity, I created a “pls” directory in my Documents directory and cd to it).
  3. Run it on terminal:
    /Users/andyibanez/Downloads/gist5154962-d5874b176ff9793036d53aae0e12dbc5b708963a/openssl-build.sh

    This will do most of the hard work for you: It will download OpenSSL, compile it, and create OpenSSL libraries for both ARM, ARM64, and even for Mac!
    Please note that executing this script may take a few minutes. Not only does it have to download OpenSSL, but it also has to compile it and it is a middle-sized library. It shouldn’t take longer than 5 minutes in an i5 processor, but still patience is to be expected.

    The output should be something like this:

    Cleaning up
    Downloading openssl-1.0.1e.tar.gz
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 4355k  100 4355k    0     0   8618      0  0:08:37  0:08:37 --:--:--  5299
    Unpacking openssl
    Building openssl-1.0.1e for i386
    Building openssl-1.0.1e for x86_64
    Copying headers
    Building Mac libraries
    Building openssl-1.0.1e for iPhoneOS 7.0 armv7
    Building openssl-1.0.1e for iPhoneOS 7.0 armv7s
    Building openssl-1.0.1e for iPhoneOS 7.0 arm64
    Building openssl-1.0.1e for iPhoneSimulator 7.0 x86_64
    Building openssl-1.0.1e for iPhoneSimulator 7.0 i386
    Building iOS libraries
    Adding 64-bit libraries
    Cleaning up
    Done
  4. In the directory you created on step 2, you should now have two directories and one file: “include”, “lib”, and “openssl-VERSION_NUMBER.tar.gz”. Y0u can ignore the latter.
  5. Open “lib”. It should have a total of 4 files. This is intuitive but I will state it for the sake of completeness: For iOS, you’re only interested in “libcrypto_iOS.a” and “libssl_iOS.a”.
  6. In your XCode project, open its settings and go to the “Build Phases” tab. Extend “Link Binary with Libraries” and drag and drop both .a files from the step above there.
  7. Now go to the “Build Settings” tab, look for “Search Paths”,  and then “Header Search Paths”. Double click it until you see a menu like this:

    Screenshot 2014-01-14 03.26.43

  8. Like you can see in the screenshot, I just dragged the entire “include” directory there. This directory has an openssl directory, but you don’t need to concern yourself with it.

And that’s it! You should now be able to use OpenSSL with both ARM and ARM64 applications.

The post Quick Tip: Compile OpenSSL For Both ARM and ARM64 for iOS. appeared first on Andy Ibanez.

]]>
https://www.andyibanez.com/quick-tip-compile-openssl-arm-arm64-ios/feed/ 12 215
Are You Storing Sensitive Data in NSUserDefaults? Stop Doing That! https://www.andyibanez.com/nsuserdefaults-not-for-sensitive-data/ https://www.andyibanez.com/nsuserdefaults-not-for-sensitive-data/#comments Thu, 09 Jan 2014 21:13:14 +0000 http://andyibanez.com/?p=204 If you're storing sensitive data in NSUserDefaults you're exposing it to risks. Learn why you shouldn't store sensitive data in NSUserDefaults.

The post Are You Storing Sensitive Data in NSUserDefaults? Stop Doing That! appeared first on Andy Ibanez.

]]>
NSUserDefaults aren’t meant to store sensitive information.

If you have been developing for iOS for a while you know that NSUserDefaults is pretty much the “de-facto” way to store a lot of small data. It has its limitations, sure, but you can easily store preferences in them. From NSStrings to NSNumbers, NSUserDefaults can store almost anything related to preferences.

And here’s the thing – You should use NSUserDefaults to store preferences only – just preferences for your app’s functionality and nothing else. Anything else like user data or IAP data should be stored someplace else. Especially if said that is sensitive and you don’t want to risk your user’s data.

I was a little bit shocked when I was reading Apple’s StoreKit Guide (you know, their OFFICIAL guide for dealing with StoreKit). It is pretty informative and everything but things get dangerous when you scroll down the document to find the way to persist user purchases. If you need to persist purchases on iOS 7, that’s no problem, you can use the receipt. But if you need to persist purchases in earlier iOS versions… There’s where things get troublesome as you can’t use the receipt with them. Apple’s solution is a little bit… Well, dangerous. Let me quote the document right here:

After making the product available, your app needs to make a persistent record of the purchase. Your app uses that persistent record on launch to continue to make the product available. It also uses that record to restore purchases, as described in “Restoring Purchased Products” (page 38). Your app’s persistence strategy depends the type of products you sell and the versions of iOS.

  • For non-consumable products and auto-renewable subscriptions in iOS 7 and later, use the app receipt as your persistent record.
  • For non-consumable products and auto-renewable subscriptions in versions of iOS earlier than iOS 7, use the User Defaults system or iCloud to keep a persistent record.
  • For non-renewing subscriptions, use iCloud or your own server to keep a persistent record.

(Bolded part done by me).

They even bothered to use some source code as an example. Let me show you:

Storing the value:

#if USE_ICLOUD_STORAGE
NSUbiquitousKeyValueStore *storage = [NSUbiquitousKeyValueStore defaultStore];
#else
NSUserDefaults *storage = [NSUserDefaults standardUserDefaults];
#endif
[storage setBool:YES forKey:@"enable_rocket_car"];
[storage setObject:@15 forKey:@"highest_unlocked_level"];

[storage synchronize];

Unlocking purchases:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL rocketCarEnabled = [defaults boolForKey:@"enable_rocket_car"];

if (rocketCarEnabled) {
// Use the rocket car.
} else {
// Use the regular car.
}

Why storing sensitive data in NSUserDefaults is a big problem.

Okay, okay, so what’s the big deal, anyway? This is a big issue: NSUserDefaults are stored in plist in binary format, with no encryption, and is stored in your app’s directory. This means that any user, even the “noobiest” one, can tinker with your NSUserDefaults with 5 minutes of their time.

Any user can edit, see, share, move and whatever they please with it. Jailbreak users can simply install iFile, navigate to your app directory, play with the file, and move on with their day. A problem if you’re persisting things like purchases with NSUserDefaults, huh?

“Dammit, these jailbreak users always getting on the way of my business and making things more complicated!”

WRONG! Jailbreak users can use iFile to get the plist and modify it, yes, but even people who don’t have jailbreak can use other software to do it. iExplorer and iFunBox are two examples of software that allow you to explore iOS’ filesystem without having your phone jailbroken (try them out yourself – iFunBox is free). These programs exist for both Mac and Windows (there may or may not be alternatives for Linux, but that’s irrelevant for this post). Anyone has access to these plists if the filesystem is not encrypted. Jailbroken users and non-jailbroken users alike. If you want to add In-App Purchases to your apps and persist them on the device, or if you need to store sensitive information, you need to do things differently.

And to make things even worse for you, using iFunBox is pretty trivial. You have easy access to essential parts of the file system. This is what “User Applications” tab looks like:

Screenshot 2014-01-09 16.30.19

When you go inside an app, you will find the familiar App Directory structure you know by heart (Documents, Library, and tmp in this case – if you ever thought users couldn’t access these directories at all you’re really wrong).

Screenshot 2014-01-09 16.34.24

If you to Library > Preferences from here you will find the plist that stores NSUserDefaults. It’s name is your App identifier with .plist at the end. For example, for Colloquy, it’s name is “info.colloquy.mobile.plist”. This is the one file that has all your NSUserDefaults.

Screenshot 2014-01-09 16.46.33

You can then simply click “Copy to Mac”, and save it somewhere easy to access. I saved it on my desktop for the sake of making it easier to show why it’s dangerous to store sensitive info on it.

Now if you try to open it directly, you will see that file has gibberish. This is because the plist is in binary format, which is enough to deter some people from tinkering with it. But converting it to something readable by humans is pretty easy.

You can use an utility on the command line called plutil to convert this plist into XML and make it a piece of cake to read it and modify it. To convert Colloquy’s file:

cd Desktop
plutil -convert xml1 info.colloquy.mobile.plist

Then open it in any text editor (or in XCode, if you fancy being able to see the data easier). And be ready to see all the NSUserDefaults:

Screenshot 2014-01-09 16.53.14

I couldn’t see that Colloquy specifically was doing anything particularly dangerous. It’s storing my IRC username for Saurik’s IRC there, but nothing particularly dangerous.

If you later edit the plist and want to use it on your phone, save it and convert it back to binary:

plutil -convert binary1 info.colloquy.mobile.plist

Then you can put it back on your phone with iFunBox.

So you can clearly see that Apple hasn’t considered the ability to easily do this. Go back to the source code I quoted above. You can easily enable the “car rocket” by switching a BOOL in the plist. Not black much black magic here.

Go ahead and try it. Maybe many of the apps you use are storing sensitive info with NSUserDefaults. If you find anything like that, please kindly contact the developers of the app to let them know.

Okay so I can’t use NSUserDefaults for everything – What should I do instead?

This depends a lot on what kind of data you’re storing. The main thing that got me to write this article was Apple’s StoreKit documentation which tells developers to simply store purchases in plists in iOS versions earlier than 7. That’s a big no-no.

I have already said that NSUserDefaults is great for settings and small data. It wouldn’t be surprising if you wanted to store things like password hashes and API keys in them.

If you need to persist user purchases in iOS 7, persist the receipt (doing that is out of this tutorial but you will find the way to do it in the article I linked to above) instead of persisting the thing they just bought in NSUserDefaults. You have seen how easy it is to see them and modify them. The IAP Receipt itself is encrypted and signed by Apple, but you can easily get the contents without storing its contents someplace dangerous.

But what to do if you need to support iOS versions earlier than 7, or you just want to store any generic sensitive info in general? Use the iOS Keychain. Which yes, it’s a pain to learn by reading Apple’s docs, but some people have written small libraries to make it using the keychain easier and less of a pain in general. For example Secure-NSUserDefaults is an example of such a library. This way you can store sensitive data by interfacing directly with NSUserDefaults, without actually storing your data there.

Of course, I never said that NSUserDefaults should be ditched completely forever – It has it’s uses for app settings, but you should limit its use to that. Anything else should be stored somehow else.

The post Are You Storing Sensitive Data in NSUserDefaults? Stop Doing That! appeared first on Andy Ibanez.

]]>
https://www.andyibanez.com/nsuserdefaults-not-for-sensitive-data/feed/ 10 204
Quick Tip: Debian Control Files With Multiline Descriptions. https://www.andyibanez.com/quick-tip-debian-control-files-multiline-descriptions/ https://www.andyibanez.com/quick-tip-debian-control-files-multiline-descriptions/#comments Mon, 03 Jun 2013 22:00:05 +0000 http://andyibanez.com/?p=127 If you need a Theos project with a multiline description, this small guide should help you setting that up.

The post Quick Tip: Debian Control Files With Multiline Descriptions. appeared first on Andy Ibanez.

]]>
When I updated Cecrecy for the first time, I wanted to add a Changelog to the package description itself. I was having a hard time figuring it out as, other than the official documentation in Debian Control files, I couldn’t find more help on this.

I tried using “\n” characters to create newlines. When that didn’t work, I tried “<br />”, but that didn’t work either. In both cases, Cydia was interpreting the literal characters rather than their meanings.

Then I finally resorted to using actual line breaks. You know, literally press “Enter” and leave it there. At first, this didn’t work at all. I was scratching my head as, to my understanding after reading the DEBIAN Control files documentation, it was supposed to be THAT easy.

At that point, my control file looked like this (this is wrong):

Package: com.andyibanez.cecrecy
Name: Cecrecy
Depends: mobilesubstrate, applist(>=1.5.1), firmware(>=6.0), libhide
Version: 1.1.0
Architecture: iphoneos-arm
Description: Protect your privacy.
Rather than locking apps with a passcode, this tweak can hide them altogether. The tweak comes bundled with an SBSettings toggle that can be locked with a passcode to toggle the tweak on and off. Developers can write their own toggles for this tweak as well.

CHANGELOG

1.0.0
Initial Release
 
1.1.0
Fixed bug that caused misplaced icons after showing them again for some people.
Maintainer: Andy Ibanez
Author: Andy Ibanez
Section: Tweaks

But when I tried to build my package with that, it failed. It didn’t give me a reason. It just did this:

Making all in cecrecysettings...
Making all for bundle CecrecySettings...
 Copying resource directories into the bundle wrapper...
make[3]: Nothing to be done for `internal-bundle-compile'.
Making all for bundle Cecrecy...
 Copying resource directories into the bundle wrapper...
make[2]: Nothing to be done for `internal-bundle-compile'.
Making stage in cecrecysettings...
Making stage for bundle CecrecySettings...
Making stage for bundle Cecrecy...
make: *** [internal-package] Error 2
Andys-MacBook-Pro:Cecrecy Andy$

Yep. “Error 2”. Whatever that means. Then I tried running the

make package install messages=yes

command, based on a recommendation. It didn’t give me much info, but it told me enough about were I was screwing up.

The solution was simpler than I had expected. I just made all my lines start with a whitespace character. Literally, pressing the spacebar. And by that, I literally mean a ” ” character. After I made all the lines in the description field start with it, it worked fine. Note that to create paragraphs, every “empty” line needs to have its own ” ” character. Otherwise it will complain due to syntactical issues with the makefile.

My final makefile was this:

Package: com.andyibanez.cecrecy
Name: Cecrecy
Depends: mobilesubstrate, applist(>=1.5.1), firmware(>=6.0), libhide
Version: 1.1.0
Architecture: iphoneos-arm
Description: Protect your privacy.
 Rather than locking apps with a passcode, this tweak can hide them altogether. The tweak comes bundled with an SBSettings toggle that can be locked with a passcode to toggle the tweak on and off. Developers can write their own toggles for this tweak as well.
 
 CHANGELOG
 
 1.0.0
 Initial Release
 
 1.1.0
 Fixed bug that caused misplaced icons after showing them again for some people.
Maintainer: Andy Ibanez
Author: Andy Ibanez
Section: Tweaks

And with that, I was able to build a package with a control file that spawns more than one line.

I also noticed something a bit sweet: The text immediately following the “description: ” text, is the text that will show up in the Cydia cell of your project, whereas everything below it, will appear in the extended description you see once you tap that cell.

The post Quick Tip: Debian Control Files With Multiline Descriptions. appeared first on Andy Ibanez.

]]>
https://www.andyibanez.com/quick-tip-debian-control-files-multiline-descriptions/feed/ 1 127
Don’t Attempt to Write Cydia Tweaks if You Don’t Know How To Program. https://www.andyibanez.com/dont-attempt-write-cydia-tweaks-dont-know-program/ https://www.andyibanez.com/dont-attempt-write-cydia-tweaks-dont-know-program/#comments Sun, 12 Aug 2012 16:59:06 +0000 http://andyibanez.com/?p=111 So you want to write Cydia tweaks for iOS? Read This. This post is aimed at people who want to write Cydia tweaks, or anything really, but don’t know anything about programming at all. Everybody wants to write something for iOS. Some will opt to write apps, others prefer to do open development writing  tweaks, […]

The post Don’t Attempt to Write Cydia Tweaks if You Don’t Know How To Program. appeared first on Andy Ibanez.

]]>
So you want to write Cydia tweaks for iOS? Read This.

This post is aimed at people who want to write Cydia tweaks, or anything really, but don’t know anything about programming at all.

Everybody wants to write something for iOS. Some will opt to write apps, others prefer to do open development writing  tweaks, Siri enhancements, notification center widgets, and the like. Some of us can actually write both. It is undoubtedly that many people want to develop something for iOS, and they cannot be blamed. iOS is a wonderful mobile OS, it has many powerful features, and in the end, developers, whether they write “official apps” or tweaks, help make the platform better. So many tweaks have been so great, that Apple actually hired some people that wrote certain tweaks so they could officially extend the platform with them. Writing for iOS is something a lot of developers want to do, and many of them help make it better one of the best mobile OSes ever created.

All kinds of people have been attracted to the platform. Middle schoolers, high schoolers, college students, professionals who are not necessarily linked to the IT industry… Everyone seems to have a breathtaking idea of what to do for the platform. But here’s the thing; many of them have no idea of what to do. Out of all the people who have great ideas, many of them just hire a development company to bring their ideas to life. Others are willing to take the whole thing in their own hands. In this article, I want to focus in the latter people, particularly in those who have decided to go the jailbreak way.

I don’t want to discourage anyone from trying to bring their own ideas to life (although, it may look that way): In fact, it is the other way around. But the truth is that many people who attempt to write something for Cydia, have no idea of what to do. They don’t know where to begin, they don’t know how long it will take them or how long it should take them. In this article, I hope to clarify some doubts of that type that interested people may have.

The truth is that, ever since I started writing jailbreak tutorials, a lot of people have wanted to jump into the Tweaks bandwagon and have asked me questions. I don’t mind if people ask me questions; I love helping people and I love teaching, that’s why I write tutorials after all, but I always expect people who contact me to have a little bit of experience writing code for iOS (or at least a good amount of experience in any programming language). When I’m starting to help someone who sends me a tweet or comments on my blog, I always assume they will be able to understand my answer because they have enough technical knowledge to absorb it all and use it. But many times people who have never written any line of code in their lives ask me about Tweak development. This astonishes me, it really does, because you can’t have no experience with programming and expect to have a working tweak from night to morning. Jumping to tweak development as your first project is NOT a good idea. There’s many steps you have to go through before you try to do something like that. Of course, I don’t mind if people ask me, “hey, I’m completely new to programming but I want to write tweaks for Cydia. Can you tell me where should I begin”, I will happily give them pointers to start out, but just that, tips to start out. With the pointers I give to complete beginners they will not be able to, nor should they attempt to, write a full working piece of code in a very short time.

If you are a new programmer with limited experience, or if you are someone who has never written code in their life (note: CSS and HTML do not count as programming languages because there is no actual programming logic involved), then you need time. This is really, really important. You need a lot of time and dedication. I know, it sucks, you saw this guy writing a MobileSubstrate tutorial that is easy to follow and he creates a working example and you expected to make it work as the first code you write, but later you realise that you need to know many more things if you actually want to write tweaks; or, you are trying to run the examples, but you get errors you do not understand, so then you are disappointed you need to invest a lot of time learning many more things. I reiterate, even if your biggest dream is to get your tweak up and running on Cydia, you just cannot jump into it if you don’t know programming – many things can and will go wrong.

Programming is not for everyone. It really is not. I see people who love programming, and I see people who hate it, but I never see people in the middle of these two extremes. How can you tell if you like programming or not? You may be asking yourself that important question right now. The answer is really simple: You try to learn it and do it. If you are not enjoying it, then stop right now and find the right vocation for yourself that will make you live happily for the rest of your time. If you like it, then congratulations! You may be in the right path to code your dreams into reality. But how do you learn, you say? This is actually a complicated question. There are many ways you can learn programming. You can go to classes, either in college or otherwise, you can buy books and go the self-taught path, or you can try something more dynamic like http://www.codecademy.com. Personally, I am self taught (and this tutorial will go around my experience), and I can definitely tell you that you can teach yourself programming by buying books and practicing on your own. Actually, I am a slow learner; to the day I have problems memorising my times tables, but I love programming so much, I was able to learn it on my own without having a teacher on my back saying what I should do or what I shouldn’t! And trust me, if I could do it, then you certainly can do it too.

But nothing will come out good unless you are willing to do some sacrifices. Once on Quora.com, I saw someone asking how can a slow learner learn to program? and I wrote a lengthy answer, but that answer can be shortened into very few words: Get time, get interest, and get resources. First, you really need to invest a lot of time if you want to write code. You may have to sacrifice many things and hobbies if you really like it a lot; You will need to spend less time with your friends and more time with yourself. You will need to kill some time of your hobbies (in my case, anime and video games) to make more time room for your programming. If you think “5 minutes for programming a day” is enough to become “good” at it, then you don’t have the right mentality. You must be willing to spend hours learning programming a day, and actually programming when you get the hang of it. You must also have enough self-discipline to read books without getting distracted (if you are going the self taught way, of course), and you must be prepared to read technical books and resources, lots of them (it was hard for me, because I am a fantasy lover, but now I can read all kinds of books with no problems so learning to program paid off for more things than just programming). You will not reach your final goal of writing tweaks or apps people will use if you don’t make time for a decent of programming in your schedule a day. How you get your books is not a concern of mine, but most of the time you will need money to buy them, too (I will tell you about the books I used to learn later, first come the words of encouragement!)… If you are focused on your goal, some sacrifices are due.

Second, you need to love it. Like I said earlier, if you can’t sit still writing and reading then programming is not for you. If you don’t have enough interest in programming, then find something else you love doing. Programming, like many other vocations and even hobbies, is something you have to love in order to do it right. Even if you are “good” at programming “naturally”, if you are not enjoying it you will be as bad as someone who doesn’t know what HTML is. You have to find programming interesting. The good news is, even if you think it’s boring, you can find an use for it! Maybe you are a musician right now who wants to write a guitar app or a SpringBoard Tuner tweak, but you don’t think you find programming interesting enough. Programming can solve many needs. Programmers are usually multi-talented people (I’m not saying we are the wisest of men, but rather we do have knowledge in lots of things because we solve all sorts of problems via code). When we write code, we enhance our knowledge for things. A programmer can be asked to write a running algorithm and in the way he will learn about music; the musician wanting to learn programming will be able to learn programming not only for app or tweak, but to solve other problems that will arise in the future for him or her as well. If you think programming is not for you, think on the kind of problems you could solve when doing your other hobbies or works: It will certainly pay off very well!

Finally, get resources. You may be a Computer Science student who goes to programming classes. But why limit yourself to that when you can learn a lot more beyond the scope of your classes? Try to get your hands in books of programming topics that interest you, or at least browse the web for articles and tutorials. The internet actually has many nice tutorials and articles for any programming-related topic you may think of. If you are self taught, you should definitely go to your local library and browse the sections where programming books can be found. Maybe a nifty title will grab your attention and you may want to buy it. Libraries are beautiful places to look for resources. Where I live, we don’t have many libraries, but when I go the USA, I can spend hours and hours browsing the books in Barnes & Noble until I find something I like or reading the first chapter of a book that calls my attention. You should definitely do this too. It sounds boring, specially if you are a school teacher. But if you are really into programming and you find it fascinating, it should be as easy as pie as to browse books just like that. You learn a lot that way, even by just looking at book titles.

Are you still with me? If you are still reading this, I assume you recognise that you won’t write the next breathtaking tweak in one night, and that you are willing to spend a lot of time learning your way to success. If you are discouraged, I’m sorry, you may want to stop reading this now. But if you are with me, willing to invest time and do the needed sacrifices, then keep reading, this is where things get a little better.

Alright, so now you may actually want me to give you some resources, and tell you about how I got here. You see, like I said before, I am entirely self taught. I have taken programming classes in college because they were a requirement, but honestly I learned very little stuff that can be applied to my daily routine. The first code I was exposed to in my life was HTML. I learned HTML, CSS, and JavaScript. Then I wanted something more challenging, and wanted to learn PHP and C++. PHP is completely unrelated right now so I will tell you about my experience with C++. First I went to a website called http://www.cplusplus.net (great site, by the way) to look for my first C++ tutorials. Honestly, at first I tried to follow the tutorial, but I had no idea of what I was doing, nor did I understand what was going on, despite the fact that I read the same tutorials many, many times. My head could not absorb those concepts at all, so I was discouraged and I just said “meh, I will wait till college teaches me all this”. This was when I was 14. We went to the USA for vacation that year, and we walked into a Barnes & Noble store and I was fascinated by all the books I could see. I saw a C++ book that called my attention, in January like 3 days after new years. The book was called “C++ Without Fear”. The monster in the cover made me think that programming maybe is easier to understand than what I think, and I thought the monster in the cover made the book look like it was easy to understand. So I brushed off some 50$ and bought that book. It was the first programming book I had ever purchased. When we returned home with my family from the US, I started reading the book.

C++ Without Fear Cover.

And boy was I impressed! Things started to make sense, with the way that book explained things. I ate this book in a few books and I was much better at C++ (nowhere near an expert, and I still didn’t know half of the language, but it gave me the first foundations to study C++ a bit more). “C++ Without Fear” is a book I recommend to anyone who wants to learn programming. It may look ridiculous, it may look easy, but it does a very great job teaching the noob programmer how to do things right. The book is of course, incomplete; C++ is a huge language that is really hard to cover completely from top to bottom. I was also using a Windows Machine back then. The CD that comes with the book has Windows software and it can’t be used in a Mac. Regardless, I recommend this book to anyone who wants to learn programming because of its way of explaining things. C++ is a language, so the language itself, you can learn it on any machine running any OS. If you want to get this book, you can follow the examples by using Xcode on your Mac, without tinkering with the examples to make them work in OS X.

As a complementary book for C++, you can buy, and I recommend “Professional C++” by Solter and Kepler. This book, like its name may imply, focus on C++ at a much complex level, because it doesn’t teach you the basics anymore. It teaches you other languages features like templates and the such.

Professional C++ Book Cover

Why C++ when there are only Objetive-C and C frameworks in Cocoa/Cocoa Touch, you say? C++ is really powerful. C++ is not a hard language, but it certainly is one of the most complex languages out there. If you can pick C++ up with most of its features, learning other languages may be a bit easier. Also, a big advantage of C++ over C is that C++ offers the Object-Oriented programming paradigm; Objective-C is entirely an Object-Oriented language, so if you pick C++’s object oriented features, with a solid grasp of Object Oriented Programming (OOP), then you will have an easier time picking up Objective-C.

A book I have checked out that looks great is called “Learning C On The Mac”. This may, or may not be, a better book to learn programming on your Mac, It teaches you C and it explains things nicely, so if you want to pick C over C++ before going to Objective-C this book is not bad all. Only bad thing is that C itself has no OO capabilities so depending on the person, picking up Objective-C may be a tiny little bit harder to pick than someone who already picked it up with C++.

Learning C On The Mac Cover

Once you learn C or C++, you have to learn Objective-C. Objective-C is (like you may have been able to deduce) the main language used to create Mac and iOS applications. The de-facto book to learn Objective-C is Stephen Kochan’s “Programming In Objective-C 2.0”. This is the only Objective-C book I have ever read. It’s so complete I don’t think you need to learn anything else.

Programming Objective-C 2.0 Cover

Then you have to learn Cocoa Touch, the framework for iOS apps. There’s many books for this topic that I have read and all of them contributed to what I know about iOS development. The Big Nerd Ranch’s book iPhone Programming is a great book for iOS programming, praised by many people, and one of the most complete and well explained iOS books out there. Apress has published many iOS books. The ones I have read that I think are good are “Beginning iPhone Development: Exploring the iPhone SDK”, which teaches a little bit of Objective-C at first but later is fully iPhone-Oriented. I have read this book for iOS 4 and iOS 5 and it’s really neat. As additional books, Erica Sadun’s “The iOS Developers Cookbook” is a must have. Erica is a recognised developer and her books are neat, not to mention she hosts her examples on her Github so you can tinker with them.

The iOS 5 Developers Cookbook.

Now, why all the official development books even though this article is focused on tweaks, you say? Because it will be really hard to write your tweaks without knowing any of these material! If you want to write a tweak that shows an alert view, you will need to know how to create the alert view. The Cocoa frameworks, which you will learn about them with those “learning iOS dev” books I showed you above  is essential for you to do anything. Yes, you can mix C and C++ code, even manipulate C++ and C strings if you prefer to over Objective-C, but the Foundation’s framework NSString can make your life easier. Also all the UI elements for iPhone are written using Objective-C frameworks, so you must understand all the material in those earlier books.

An additional book, but a book I have skimmed over a few times and looks really good, is “Hacking and Securing iOS Applications” by Jonathan Zdziarski. This book is important for both tweak developers and official developers, because this book shows exploits, how to find security holes, and how to abuse them. It looks like a wonderful every iOS developer should read, and it can benefit everyone equally.

Hacking and Securing iOS Applications Cover

A final resource will always be Apple’s Developers website (developer.apple.com). You must learn to use this reference for the official frameworks.

Now to talk a bit more about Cydia tweaks and jailbreak apps, this is really a vast topic. Private frameworks change a lot in each iOS release. All the knowledge you will get up to this point will help you more doing tweaks. For iOS tweaks, you will browse private headers a lot. You will need to learn to get your hands in these private framework headers (some people share them, others dump their own). Dumping them on your own is not hard, but it takes a while to fix the headers yourself (because they are not always compile-ready). Then you will learn to “hook code” and a basic knowledge on the Objective-C’s runtime (which is something every developer should learn, not only jailbreak people) so you have a basic understanding of code hooking and how C really works with your C++ code. There are not many books dedicated to iPhone development (Jonathan Zdziarski has written one, but it hasn’t been updated since 2008 and it still focuses on iOS 2.0; iOS 6 is just around the corner now). Your patience will be tested, trust me. You will experiment a lot with code to learn what is it that you should hook and what you should leave alone. You may need to restore your device more than once in some cases. Open development can be really tough if you don’t know what you are doing; you can damage your device if you are not careful. This is why Tweaking shouldn’t be the first thing you try to do if you are new programming altogether. You will learn a lot of iPhone headers, and you will get used to research because like I said, the private frameworks change a lot in each iOS release, so  your iOS 5 tweak that works wonderfully, that took you months to develop, may break on iOS 6 and you will need to find the alternative way to hook your code.

Okay, okay, woah, woah! You probably want me to stop for a little while here. I think I can hear you asking “How long is all this going to take?”. This is a very, very complicated question. Despite the fact that I have been programming for 6 years, the first thing I ever released to the public was just a few months ago. Prior to that, I spent the previous years getting programming skills for other languages and technologies. When I learned to program, the iPhone wasn’t out yet, and I actually didn’t like Apple. My knowledge was limited to web technologies, C++, and C# along with Microsoft’s technologies. I must have studied C# and Windows Development for at least a year. But I never did anything with that knowledge.

So while in my case it may have taken me 6 years to get something out, in your case it may take you more or less. It really depends on how much time and effort you put into it. But even then, then expect to have a tweak out and working in just a few months. To really understand C, you will have to do it for a pretty long time. You will end up writing lots of console/terminal programs just to learn more. If you eat absolutely all the books I mentioned (recommended), then you may be attempting to write tweak in like 9 months or so. Just learning C, you will be a few months. An extra month or so for Objective-C, and yet more time with Cocoa Touch. When you get to actual tweak development you will be exploring and researching a lot on your own or asking question in Saurik’s IRC because there isn’t much content written about iOS development.

A very important word of advice is due here: DON’T THINK ON THE TIME. Just learn programming and ENJOY YOURSELF. If you don’t, like I said, it will be evident that programming is not for you. If you focus on learning and on enjoying it, you will see that, while your tweak will still be your main goal, you will develop more programming related-goals, hopes, and dreams. You will think on other projects you want to work on, and you will get a great satisfaction of learning things.

If you have read all this and are willing to go through everything, remember to ASK QUESTIONS. On StackOverflow, on IRC channels, anywhere. Like I said, I love helping people answering their questions as long as they are interested, so send me a tweet or something if you want my help with something. I’m not an expert, there’s many things I don’t know, but part of the reason I love teaching is because I end up learning a lot. Some questions people have asked me, drove me to do some research and learn more, getting more benefit. Don’t have doubts, ever.

After all, the glory you get of releasing something to the public that people like and talk about can never be replaced by anything else. You think your tweak is not worth it? Submit it anyway: When I submitted my first tweak to ModMyi’s repo on Cydia (called SiLight, which is just a simple Siri extension that allows you to turn on your flashlight with your voice), I firstly thought no one was going to be interested on it, and that only 10 people or so would download it. You have no idea of how wrong I was: In it’s first hour, it received 70 downloads, and by the end of the day, it had 700 downloads. A tweak I thought no one was going to care was getting downloaded. The next day, I decided to Google “SiLight Siri”, and I was received by a beautiful surprise: Many blogs in many different languages were talking about that crazy flashlight you could toggle with Siri. It received a lot of praise for being “An extension that goes beyond the software and toggles the hardware”, and it received a lot of exposure. On it’s first week it received around 5000 downloads, and at the time of this writing, it has over 13000. So yes, like you can see, the effort you will put into will pay off. Even if you think your tweak is going to be ignored by everyone, you may get a very pleasant surprise when you see people downloading it, thanking you for it, using it, and talking about it. So go on! If you have spent 20 minutes of your life reading all this, I’m sure you want to have some little glory for yourself. We all do. Just remember to work hard, and don’t expect things to work out the easy way.

CHANGELOG:


August 12, 2012 at 1:00 PM [America/La_Paz]: First version of this tutorial.

The post Don’t Attempt to Write Cydia Tweaks if You Don’t Know How To Program. appeared first on Andy Ibanez.

]]>
https://www.andyibanez.com/dont-attempt-write-cydia-tweaks-dont-know-program/feed/ 13 111