30 iOS projects with Swift in my next 100 days(next server months or years maybe)
Date: 2018-5-26
What I learned from this demo:
- Try to build iOS game with
SKView
,GameScene
inSpriteKit
- Use the simple physic system such as collision test in game
- Overload basic operators of
CGPoint
in Swift
Date: 2018-5-6
What I learned from this demo:
- Use
Keychian
source code for security in swift - New keywords in swift:
throws
,where
clause in extension,enum
in class,UserDefaults
andUIDevice
Resource: GenericKeychain
Date: 2018-4-27
What I learned from this demo:
- Try CocoaPods in AppCode, edit pod file and install the specified pod:
MBProgressHUD
- Use sleep method of
Thread
withDispatchQueue
to simulate long-time-process
PS: While I use CocoaPods
in AppCode, even though the pod is installed but I cannot use it, everything ends with this error: No such module 'MBProgressHUD'. At last I fix this problem after searching on website:
- Open project (the .xcworkspace file) in XCode
- Open menu: Product - Scheme - Manage Schemes, only check the Pods item and click Close button
- Click menu: Product - Build
- Return to AppCode, and this time even thought the error is still there but the code assistant works fine, leave it, just build and run, it works!
That's all, why it happens? I got no idea.
Date: 2018-2-15
What I learned from this demo:
- Work with
UITabBarController
, and the controllers embed withUINavigationController
- Implement the
UITextFieldDelegate
protocol to monitor the changes of text content - The basic map view in controller setup, set location in simulator, make annotation in view
Date: 2018-2-14
What I learned from this demo:
- Touch event handle in
UIResponder
with multiple pointers, and super view - Basic graphic in
UIView
, draw lines with path, stroke, width and color - Use
@IBInspectable
to make properties visible inStoryboard
settings panel - Clip the view and save to image file, show the hidden toolbar in navigation
Date: 2018-2-7
What I learned from this demo:
- Work with protocals:
UIPageViewControllerDelegate
andUIPageViewControllerDataSource
to buildUIPageViewController
- Use
NSLayoutConstraint
to do the animation of controls - Instantiate view controllers by
UIStoryboard
PS. This project supports one solution to the animation problems in the previous project: 10.Basic Animation by using the NSLayoutConstraint
in layout.
Date: 2018-1-26
What I learned from this demo:
- Deal with the errors in Swift with
enum
types andError
protocol - Solve the problem of wrong image place in
UIImageView
while reuse the cells in table view - Save image file to file system with
UIImageJPEGRepresentation
andFileManager
- Use
UIActivityIndicatorView
to preload images
Date: 2018-1-24
What I learned from this demo:
- Load
json
data from server and parse it to local data class - Work with
URLRequest
,URLQueryItem
andURLComponents
to fetch network data - Initialize data in
AppDelegate
through view controller
PS: For the reason of reusable of cells, the image will not be correctly presented in the expected UIImageView
, but I have solved this in my next app.
Date: 2018-1-20
What I learned from this demo:
- Create object with
NSObject
andNSCoding
protocol - Save encoded object to local file with
FileManager
andNSKeyedArchiver
- Understand the basic knowledge of the app's life circle
- Work with
Date
,DateFormatter
,tableView.deleteRows
, andeditButtonItem
Date: 2018-1-18
What I learned from this demo:
- Delete and get rid of the storyboard, just add code in
AppDelegate
to install views - Pure code for custom table view cell class, override the
init
function to do initialization - Add the simple
UILabel
to the content view of the table view cell - Code for the simplest constrains(I notice that, you should constrain the label to the
self.view
but not to the content view!)
Date: 2018-1-15
What I learned from this demo:
- Use the
UIScrollView
withImageView
to scale image - Simple usage of the
NumberFormatter
, and the lazy property definition - Add Tap Gesture Recogizer to the main view in Interface Builder to deal with keyboard dismiss
Date: 2017-12-30
What I learned from this demo:
- Load and display image from server by using
URLSession
- Deal with the response, data and error of the network connection result
- Switch from net thread to the main thread to control the UI elements through
DispatchQueue
I cannot load image from the non-https
URL, so add the property Allow Arbitrary Loads
under App Transport Security Settings
, set the value as YES
.
Date: 2017-12-22
What I learned from this demo:
- The basic animation with the controls in iOS
- Show or hide the navigation bar or bar items in code
- Use computed data or properties in swift
- Understand the method
viewWillAppear
andviewDidAppear
for controlling the animation logic
I found a problem that the position of controls in viewWillAppear
cannot move, even thought the value is changed! However if you put the code in viewDidAppear
then the controls will move, but, the animation looks wried!!! So, I have to hide(set alpha=0.0) and then move them in viewDidAppear
, why this happens(the auto layout is not the reason!)?
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
print(self.labelHeading.center.x) //result is 147.5, all right.
self.labelHeading.center.x -= self.view.bounds.width //no movement happens!
print(self.labelHeading.center.x) //is -227.5, OK, but no changes on the screen, why???
}
override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)
self.labelHeading.center.y -= self.view.bounds.height //the control moves here!
}
Date: 2017-12-19
What I learned from this demo:
- Change the edit mode in
UITableView
, use the methodsetEditing(_, animated:)
- Rearrange the table view cell items in edit mode
- Dynamicly change the title of the bar button item
- Add text filed to the alert, and deal with the text result
Date: 2017-10-21
What I learned from this demo:
- Work with collection view, within more than one columns
- Delete items in collection view through
UILongPressGestureRecognizer
andUIAlertController
andIndexPath
in collection view - Extension with
UICollectionViewDelegateFlowLayout
, override the important optional methods - Try to use circular images in code:
cell.imageTitle.layer.cornerRadius = cell.imageTitle.bounds.height * 0.5
cell.imageTitle.clipsToBounds = true
Date: 2017-10-14
What I learned from this demo:
- Add refresh control to achieve pull-to-refresh and reload data in table view
- Override
numberOfSections(in : UITableView)
function to change the default appearance of empty table view - Set title and add navigation bar items in swift code
Date: 2017-10-05
What I learned from this demo:
- Work with static cells in static table view
- Use container view (UIContainerView) to embed other view
- Specify user permissions in the Info.plist file
- Deal with the focus of UITextField, with
becomeFirstResponder()
and the implementation ofUITextFieldDelegate
protocol, returntrue
intextFieldShouldReturn(_ textField: UITextField) -> Bool
method - Try to use camera and photo library with image picker
Date: 2017-09-03
What I learned from this demo:
- Pass data from one view to another through segue
- Work with custom view controller and embed them in the navigation controller
- Customize the swipe action menus of table view cells
- Multiple lines for
UILabel
(set lins to 0 in storyboard), customize the navigation bar item (the code should be placed in mainViewController
, not the detail view controller), and remove the blanks between top bar and table view (uncheck the Adjust Scroll View Insets in view controller)
Date: 2017-09-02
What I learned from this demo:
- Basic table view and the simple custom cell
- Display local data, add or edit local data and refresh the table
- Use
UIAlertController
with text field and deal with the response of alert actions - Change the constrains of the table view in the view container by storyboard
Date: 2017-08-26
What I learned from this demo:
- Swift extensions, double to string format, computed values
- Multiple stack view to build more flexible layout
- Use the slider, and give it the value change response handler
- Add custom UIToolBar to the number keyboard, set clear button and keyboard type
- Deal with the focus of UITextField, and enable or disable the other elements
Date: 2017-08-20
What I learned from this demo:
- Swift property delegations: willSet/didSet
- Detect Tap and Long Press Gestures on buttons
- Multiple actions on one button:
addGestureRecognizer
Date: 2017-08-17
What I learned from this demo:
- Build a basic interface with Button/Label/NavigationBar/BarButtomItem
- AutoLayout basics: Stack View and Constrains
- The keywords: @IBOutlet/@IBAction/weak
- I now upload the projects to Github via git on my Macbook
What inspires me is the project: 100 Days of Swift