Skip to content

Commit

Permalink
Version 1.2 updates for Swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohsan Khan committed Oct 16, 2018
1 parent 1d813bf commit fa6d7a9
Show file tree
Hide file tree
Showing 23 changed files with 243 additions and 342 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2016/2017 Mohsan Khan
Copyright 2016/2017/2018 Mohsan Khan

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
File renamed without changes.
31 changes: 0 additions & 31 deletions MessageBox.podspec

This file was deleted.

11 changes: 10 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
// swift-tools-version:4.0

import PackageDescription

let package = Package(
name: "MessageBox"
name:"MessageBox",
products:[
.library(name:"MessageBox", targets:["MessageBox"])
],
targets:[
.target(name:"MessageBox", dependencies:[])
],
swiftLanguageVersions:[4]
)

64 changes: 34 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,74 @@
[![MadeInSweden](https://img.shields.io/badge/Made_In-Stockholm_Sweden-blue.svg)](https://en.wikipedia.org/wiki/Stockholm)
[![Status](https://img.shields.io/badge/Status-Active_in_development-blue.svg)](https://github.com/MKGitHub/MessageBox-Concept)
[![Status](https://img.shields.io/badge/Status-Active_and_in_development-blue.svg)](https://github.com/MKGitHub/MessageBox)

[![Version](https://img.shields.io/badge/Version-1.1.1-blue.svg)](https://github.com/MKGitHub/MessageBox-Concept)
[![Carthage](https://img.shields.io/badge/carthage-1.1.1-blue.svg)](https://github.com/MKGitHub/MessageBox-Concept)
[![SPM](https://img.shields.io/badge/SPM-1.1.1-blue.svg)](https://github.com/MKGitHub/MessageBox-Concept)
[![Pod](https://img.shields.io/badge/pod-1.1.1-blue.svg)](https://github.com/MKGitHub/MessageBox-Concept)
[![Version](https://img.shields.io/badge/Version-1.2-blue.svg)](https://github.com/MKGitHub/MessageBox-Concept)
[![Carthage](https://img.shields.io/badge/carthage-1.2-blue.svg)](https://github.com/MKGitHub/MessageBox-Concept)
[![SPM](https://img.shields.io/badge/SPM-1.2-blue.svg)](https://github.com/MKGitHub/MessageBox-Concept)
[![CocoaPods](https://img.shields.io/badge/CocoaPods-🤬-blue.svg)](https://github.com/MKGitHub/MessageBox)

[![Platform](https://img.shields.io/badge/Platforms-macOS_iOS_tvOS-blue.svg)](https://github.com/MKGitHub/MessageBox-Concept)
[![Swift](https://img.shields.io/badge/Swift_Version-3.0.1/3.1/4-blue.svg)](https://github.com/MKGitHub/MessageBox-Concept)
[![Swift](https://img.shields.io/badge/Swift_Version-4.2-blue.svg)](https://github.com/MKGitHub/MessageBox)


★ Give this repo a star and help its development grow! ★
🌟 Give this repo a star and help its development grow! 🌟

<br/>


MessageBox Concept
------
MessageBox is a simple concept for decoupling entities. Think of it as notifications but the opposite.

* For example entity A can place a message that entity B can read whenever suitable – not at once like notifications.
* A view controller would like to talk to another view controller, but you don't want to create a strong or weak relationship.
* For example a view controller would like to talk to another view controller, but you don't want to create a strong or weak relationship between them.
* This concept is highly flexible as it allows you to change which entity should put & get a message, without having to refactor your code & architecture.

![Image of MessageBox-Concept](https://github.com/MKGitHub/MessageBox-Concept/blob/master/MessageBox.png)

<br/>


Simple Example Usage
------
```swift
let messageBox:MessageBox = MessageBox()
let messageBox = MessageBox()

// set
messageBox.setObject("TestObject1", forKey:"TestKey1")

// get
// but don't remove it, keep it stored, so that it can still be retrieved later
let someObject:String = messageBox.getObject(forKey:"TestKey1", removeIfFound:false)
let someObject = messageBox.getObject(forKey:"TestKey1", removeIfFound:false)

// get
// and remove it
let someObject:String = messageBox.getObject(forKey:"TestKey1", removeIfFound:true)
let someObject = messageBox.getObject(forKey:"TestKey1", removeIfFound:true)
```

<br/>


What’s New?
------
* Version 1.2 updates for Swift 4.2.
* Version 1.1.1 adds documentation.


Requirements
------
* Swift Version 3.0.1 / 3.1 / 4
* ARC
* macOS 10.11 and later
* iOS 9.0 and later
* tvOS 9.0 and later
* Swift Version 4.2
* Xcode 10


How to Install
------
There is no framework/library distibution, I recommend that you add the MessageBox-Concept/Sources to your project. As this will allow you to easily find & read the MessageBox API, it will also allow MessageBox to compile using your apps build settings.
* Git: run `git clone https://github.com/MKGitHub/MessageBox-Concept.git` then `Drag & Drop the MessageBox-Concept/Sources into your Xcode project.`
* Manual: `Drag & Drop the MessageBox-Concept/Sources into your Xcode project.`
* Carthage: In your Cartfile add `github "MKGitHub/MessageBox-Concept" ~> 1.1.1` then `carthage update --no-build` then `Drag & Drop the MessageBox-Concept/Sources into your Xcode project.`
* Swift Package Manager (still quite meaningless): run `swift build` or `swift package generate-xcodeproj`
* CocoaPods (not recommended!): `pod 'MessageBox', '~> 1.1.1'`
There is no framework/library distibution, I recommend that you simply add the `MessageBox.swift` to your project. As this will allow you to easily find & read the MessageBox API, and it will also allow MessageBox to compile using your apps build settings.

* Using Git: `git clone https://github.com/MKGitHub/MessageBox.git` then add `MessageBox.swift` to your Xcode project.
* Manual Way: Add `MessageBox.swift` to your Xcode project.
* Using Carthage: In your Cartfile add `github "MKGitHub/MessageBox" ~> 1.2` then `carthage update --no-build` then add `MessageBox.swift` to your Xcode project.
* Using Swift Package Manager: swift-tools-version:4.0
* CocoaPods support has been removed! 🙌🙏🎉 Never use CocoaPods! 💀


Documentation
Expand All @@ -72,20 +78,18 @@ Go to the documentation [index page](http://htmlpreview.github.io/?https://raw.g

Used In Apps
------
MessageBox is used in production in the following apps/games (known to me), these apps are together used by many millions of users every day. Please let me know if you use MessageBox.
MessageBox is used in production in the following apps/games (that I'm aware of), these apps are together used by millions of users. Please let me know if you use MessageBox.

* McDonald's: Sweden, Switzerland and more
* McDonald's apps


Notes
------
https://github.com/MKGitHub/MessageBox-Concept

http://www.xybernic.com
https://github.com/MKGitHub/MessageBox-Concept

http://www.khanofsweden.com
http://www.xybernic.com

Copyright 2016/2017 Mohsan Khan
Copyright 2016/2017/2018 Mohsan Khan

Licensed under the Apache License, Version 2.0.
Licensed under the Apache License, Version 2.0.

95 changes: 44 additions & 51 deletions Sources/MessageBox.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
//
// MessageBox
// Copyright © 2016/2017 Mohsan Khan. All rights reserved.
// Copyright © 2016/2017/2018 Mohsan Khan. All rights reserved.
//

//
// https://github.com/MKGitHub/MessageBox-Concept
// http://www.xybernic.com
// http://www.khanofsweden.com
//

//
// Copyright 2016/2017 Mohsan Khan
// Copyright 2016/2017/2018 Mohsan Khan
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -29,55 +28,55 @@ import Foundation


/**
Simple Example Usage:
Example Usage:
```swift
let messageBox:MessageBox = MessageBox()
let messageBox = MessageBox()
// set
messageBox.setObject("TestObject1", forKey:"TestKey1")
// get
// but don't remove it, keep it stored, so that it can still be retrieved later
let someObject:String = messageBox.getObject(forKey:"TestKey1", removeIfFound:false)
let someObject = messageBox.getObject(forKey:"TestKey1", removeIfFound:false)
// get
// and remove it
let someObject:String = messageBox.getObject(forKey:"TestKey1", removeIfFound:true)
let someObject = messageBox.getObject(forKey:"TestKey1", removeIfFound:true)
```
*/
final class MessageBox
{
// MARK: Private Member
fileprivate var mMessageDictionary:Dictionary<String, Any> = Dictionary<String, Any>()
private var mMessageDictionary:Dictionary<String, Any> = Dictionary<String, Any>()


// MARK:- Public Methods


///
/// Set the object for the key.
///
/// - Parameters:
/// - object: An object.
/// - key: A key name.
///
/**
Set an object for a key.
- Parameters:
- object: An object.
- key: A key name.
*/
func setObject(_ object:Any, forKey key:String)
{
mMessageDictionary[key] = object
}


///
/// Get the object for the key.
///
/// - Parameters:
/// - key: A key name.
/// - removeIfFound: If the object is found then remove it upon retrieval. Otherwise let it remain.
/// - Returns: The found object, or `nil` if the object does not exist.
///
func getObject(forKey key:String, removeIfFound:Bool)
-> Any?
/**
Get an object for a key.
- Parameters:
- key: A key name.
- removeIfFound: If the object is found then remove it upon retrieval, otherwise let it remain.
- Returns: The found object, or `nil` if the object does not exist.
*/
func getObject(forKey key:String, removeIfFound:Bool) -> Any?
{
let obj:Any? = mMessageDictionary[key]

Expand All @@ -89,14 +88,14 @@ final class MessageBox
}


///
/// Check if an object exists for a key.
///
/// - Parameter key: A key name.
/// - Returns: `true` or `false`
///
func containsObject(forKey key:String)
-> Bool
/**
Check if an object exists for a key.
- Parameter key: A key name.
- Returns: `true` or `false`.
*/
func containsObject(forKey key:String) -> Bool
{
if (mMessageDictionary[key] != nil) {
return true
Expand All @@ -106,34 +105,28 @@ final class MessageBox
}


///
/// The number of messages in the box.
///
/// - Returns: The number of messages in the box.
///
func count()
-> Int
/**
- Returns: The number of messages in the box.
*/
func count() -> Int
{
return mMessageDictionary.count
}


///
/// Remove all messages in the box.
///
/**
Remove all messages in the box.
*/
func removeAll()
{
mMessageDictionary.removeAll()
}


///
/// Returns the underlaying dictionary.
///
/// - Returns: Returns the underlaying dictionary.
///
func dictionary()
-> Dictionary<String, Any>
/**
- Returns: Returns the underlaying dictionary.
*/
func dictionary() -> Dictionary<String, Any>
{
return mMessageDictionary
}
Expand Down
Loading

0 comments on commit fa6d7a9

Please sign in to comment.