Showing posts with label iOS. Show all posts
Showing posts with label iOS. Show all posts
Thursday, October 16, 2014
Changed! - The App
Hi,
I prodly present Changed!.
Changed! looks for changes about texts you care.
I've been using it mostly for prices, but you can use it for almost everything.
The app is available for iOS and Android.
You can find more information at changedapp.com
Tuesday, August 19, 2014
Simple Database Migration-Class using sqlite and fmdb
Checkout the project at github https://github.com/flodev/DbMigration.
Then execute "git submodule init" and "git submodule update" to fetch fmdb.
The submodule is at tag 2.3 so it should be stable.
I'd like to present you how I will do database migrations on iOS devices.
The app is running an sqlite db containing a settings table with a db_version entry.
The migration class has defined updates for different database versions. They are presented in a dictionary with versions as keys and "blocks"/closures as values.
For example in the first version of the app normally the base scheme with tables which will be created.
In the second version the app needs an additional table. And in version 2.1 a column has changed and a new column will be inserted.
Then it goes like this.
first time the app starts, version 1.0 of the db scheme:
- db scheme will be created and queries for first version are executed
user is updating the app and starting it
- migration script is executing queries for version 2.0
and so on.
The script is working like that:
There is a Db class that has a version constant.
Now AppDelegate starts the DbMigration script. The script compares the constant of Db-Class with the version found in the settings-table in the database. But wait, first start, there is no database nor a settings table. Thus DbMigration script decides all queries needs to get executed. At the end it inserts the Db-class-constant into the settings table of the database.
After an update the Db-class-constant might have changed and differ from the version in the settings table. Then all the update statements in the migration script that have version greater than the db version will run.
Monday, August 18, 2014
Optional return values cannot have type
This'll crash if resultset is nil with "fatal error: unexpectedly found nil while unwrapping an Optional value":
Update 25.08:
They can have a type if the question sign is used:
var resultset: FMResultSet = db.executeQuery(
"SELECT * FROM settings WHERE id = ?",
withArgumentsInArray: [10]
)
While this will run without fatal:
var resultset = db.executeQuery(
"SELECT * FROM settings WHERE id = ?",
withArgumentsInArray: [10]
)
Update 25.08:
They can have a type if the question sign is used:
var resultset: FMResultSet? = db.executeQuery(
"SELECT * FROM settings WHERE id = ?",
withArgumentsInArray: [10]
)
Sunday, August 17, 2014
Javascript variable definition with Swift
Did you know that you can define variables in Swift the same way like in Javascript?
var currentVersion = self.db.version,
oldVersionString = version! as NSString,
oldVersion = oldVersionString.doubleValue
The similarity is impressive. Now I'm waiting for a swift to Javascript converter called Swiftscript or Coffeeswift.
Saturday, August 16, 2014
Local push notifications in iOS 8
Back to iOS-Developmenent. I'm currently working on a push notification implemenation.
iOS 8 provides new interaction possibilities to deal with push notifications.
I found this tutorial which explains how to use custom buttons in swift. Very helpful in my opinion.
This guy pointed me to the function which I need to use to catch the notification the user has clicked:
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler: () -> Void)
Haven't found any explanation in the official push notification guide by apple so I assume its a new function in iOS8. Its available for remote notifications as well.Tuesday, August 5, 2014
Xcode 6 beta 5
Hi,
I'm currently trying Xcode 6 beta 5.
For me one major issue occurred: I'm not able to use IBOutlets from storyboards anymore.
According to the release notes they have introduced strong connection binding but removing "weak" keyword doesn't resolve the issue. The outlets are always nil making the new beta version unusable for me.
Additionally they changed optional parameter checking:
This is not possible anymore. I need to refactor my code into:
Anyway, I need to stay at beta 4 because of the IBOutlet issue.
Ah almost forgot, the icons are looking more fancy now :)
Update
Don't think about using your app with two beta versions. After refactoring I got an error with beta 4 Type 'Model' does not conform to protocol 'Equatable'.
Update:
The IBOutlet bug is related to view controllers which are using xib-views and are not explicitly instantiated with the nibName.
I just had to do MyController(nibName: "MyController", bundle: nil) instead of MyController().
Found the answer on stackoverflow.
I'm currently trying Xcode 6 beta 5.
For me one major issue occurred: I'm not able to use IBOutlets from storyboards anymore.
According to the release notes they have introduced strong connection binding but removing "weak" keyword doesn't resolve the issue. The outlets are always nil making the new beta version unusable for me.
Additionally they changed optional parameter checking:
var test: String?
if test {
NSLog("test is set")
}
This is not possible anymore. I need to refactor my code into:
var test: String?
if test != nil {
NSLog("test is set")
}
Anyway, I need to stay at beta 4 because of the IBOutlet issue.
Ah almost forgot, the icons are looking more fancy now :)
Update
Don't think about using your app with two beta versions. After refactoring I got an error with beta 4 Type 'Model' does not conform to protocol 'Equatable'.
Update:
The IBOutlet bug is related to view controllers which are using xib-views and are not explicitly instantiated with the nibName.
I just had to do MyController(nibName: "MyController", bundle: nil) instead of MyController().
Found the answer on stackoverflow.
Monday, August 4, 2014
The unfortunate iOS Developer
Hi there,
last week I was struggeling with iOS development. I was so deep into learning and coding that I simply had no nerve to write something in the blog.
It started very well. It was just me, xcode beta and the new programming language swift all together following one target: Developing my app.
What costs me most of the time was layouting.
I was coming from android development where its standard to have the xml files and a visual dummy representation, where I can see what the view will look like. That in mind I thought its a good idea to have a visual representation in the iOS app as well.
First I got in touch with the storyboard which is created by default. It was working quit ok in the beginning. Then I wanted to use a third party library which was shipped with examples based on xib files. While storyboards containing usually more than one view(-controller) a xib file contains only one. So I learned to use xib files too (just for fun, haha).
After doing this excurse I returned to storyboards and wanted to get into serious development: The plan was to position my elements and then be happy. It shouldn't be.
Unfortunately iOS is using absolute positioning in the standard views only which makes it impossible (for me) to dynamically hide and show elements. Maybe this is one reason that iOS is running so smothly compared to Android. All elements do not care about any other than themselfes.
There is a way to use constraints for hiding and showing.
Unfortunately its to big effort to make all the constraints and results in confusing code.
I realized that static table layout could be a solution. I tried to define it in the storyboard.
Unfortunately xcode has a bug that prevented me from using custom cells in the storyboard so that wasn't a solution either.
Then I was trying some third party library call QuickDialog. I got the samples to run.
Unfortunatly I wasn't able to integrate the lib into my project. Also I realized that the lib is a little bit oversized for my project.
So I decided to use the only real way: doing it in code. No visual presentation, but who cares since I'm the only one who needs to do something in the project. Doing it programmatically allows me to render elements depending on certain conditions. I really can recommend to take a look into this autolayout example library.
last week I was struggeling with iOS development. I was so deep into learning and coding that I simply had no nerve to write something in the blog.
It started very well. It was just me, xcode beta and the new programming language swift all together following one target: Developing my app.
What costs me most of the time was layouting.
I was coming from android development where its standard to have the xml files and a visual dummy representation, where I can see what the view will look like. That in mind I thought its a good idea to have a visual representation in the iOS app as well.
First I got in touch with the storyboard which is created by default. It was working quit ok in the beginning. Then I wanted to use a third party library which was shipped with examples based on xib files. While storyboards containing usually more than one view(-controller) a xib file contains only one. So I learned to use xib files too (just for fun, haha).
After doing this excurse I returned to storyboards and wanted to get into serious development: The plan was to position my elements and then be happy. It shouldn't be.
Unfortunately iOS is using absolute positioning in the standard views only which makes it impossible (for me) to dynamically hide and show elements. Maybe this is one reason that iOS is running so smothly compared to Android. All elements do not care about any other than themselfes.
There is a way to use constraints for hiding and showing.
Unfortunately its to big effort to make all the constraints and results in confusing code.
I realized that static table layout could be a solution. I tried to define it in the storyboard.
Unfortunately xcode has a bug that prevented me from using custom cells in the storyboard so that wasn't a solution either.
Then I was trying some third party library call QuickDialog. I got the samples to run.
Unfortunatly I wasn't able to integrate the lib into my project. Also I realized that the lib is a little bit oversized for my project.
So I decided to use the only real way: doing it in code. No visual presentation, but who cares since I'm the only one who needs to do something in the project. Doing it programmatically allows me to render elements depending on certain conditions. I really can recommend to take a look into this autolayout example library.
Wednesday, July 23, 2014
Starting with iOS Development using Swift
Motivation
I'm currently developing an Android-App. I thought it would be nice if this app is also available for iOS. The Android App contains standard components which maybe easy to realise at iOS.
Xcode beta
After installing the Xcode beta I was able to use the new programming language Swift which Apple will officially introduce in Fall this year. Xcode contains a fancy playground for playing with the new Swift language. If you assign variables you can check the values on the right instantly while typing.
Overall I do like Xcode. Its similar to visual studio. It contains an interface builder where I could play with the available UI components.
Approaching development
Sometime I got bored with senseless clicking in Xcode and I felt ready for first tutorials. I started with a swift tutorial tutorial by Jameson Quave. It was interesting to see how the IB works in action. It is more than just placing components. You can actually do relations between the controller and code. Furthermore it is possible to chain multiple views.Objective-C together with Swift
There are tons of Objective-C libraries available as open source. It would be a bad move to skip backwards compatibility so apple decided to introduce bridge header for using Objective-C-Code in Swift. It is explained in the apple developer reference.
Using SVWebViewController with Swift
I've chosen the Objective-C library SVWebViewController available on github to use in my test project.
It is a library that mocks a browser window using the internal UIWebView component of iOS. Its creating an own view with the browser window, controls for navigation, page reloading, loading indicator and page title.
Just download a stable release, extract and drag the folder SVWebViewController/SVWebViewController into your project. Xcode may ask something but I left everything at default.
My project was created as an single page Application.
It is named "webview" so I can see a folder "webview" in the project navigator. I dragged the SVWebViewController directly under that folder.
Now I needed to create the bridge header file. Just right click in the Project Navigator -> New File -> iOS -> Source -> header file. I chose the name "bridge-header.h". Then insert the references of the objective-C header files into the the file:
It is a library that mocks a browser window using the internal UIWebView component of iOS. Its creating an own view with the browser window, controls for navigation, page reloading, loading indicator and page title.
Just download a stable release, extract and drag the folder SVWebViewController/SVWebViewController into your project. Xcode may ask something but I left everything at default.
My project was created as an single page Application.
It is named "webview" so I can see a folder "webview" in the project navigator. I dragged the SVWebViewController directly under that folder.
Now I needed to create the bridge header file. Just right click in the Project Navigator -> New File -> iOS -> Source -> header file. I chose the name "bridge-header.h". Then insert the references of the objective-C header files into the the file:
#import "SVWebViewController.h"
#import "SVModalWebViewController.h"
The bridge header file must refer to the projects build settings. In the Project navigator click at the root and click on build settings in the center view. Scroll down to Swift Compiler - Code Generation (or hit command+f to search for it). Click into Objectvie-C Bridging Header and insert the relative path to your bridge header file there. In my case its "webview/bridge-header.h" (<project-name>/<header-filename>.h).
The easiest way to use SVWebViewController is to add code for initialising into the application function of the AppDelegate.swift.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame:UIScreen.mainScreen().bounds)
self.window!.backgroundColor = UIColor.whiteColor()
self.window!.rootViewController = SVModalWebViewController(address: "http://google.de")
self.window!.makeKeyAndVisible()
return true
}
Subscribe to:
Posts (Atom)