ManiaPlanet style Swift parser

Moderators: Xymph, NADEO

Post Reply
User avatar
toffe
Posts: 671
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

ManiaPlanet style Swift parser

Post by toffe » 03 Mar 2015, 13:49

Image Image

Hello,
I started a Swift Maniaplanet style formatter. Inputs a string, returns a NSAttributedString for style usage on labels and more.
I will use the framework myself in the Maniaplanet Toolkit in later versions for faster parsing of styles. Currently it's using the NSAttributedString HTML parser that is very slow (because it uses webviews on the background, and because of that it isn't threadable, needs to be on main/ui thread).

Code: Select all

let nickname = "$F80$i$S$oToffe$z$06FSmurf $z$n$l[http://goo.gl/y4M9VK][App]$l"
let styledNickname = MPFormatter().parse(nickname).getAttributedString()
Will result in Image

Install and usage instructions are in the github readme.md.
Cocoapods definition:

Code: Select all

pod 'MPFormatter', '~> 1.2.0'
Github: https://github.com/tomvlk/MPFormatter_swift

Announcement: Version 1.x.x freezed, from now 1.x.x will only get bugfixes.

Toffe
Last edited by toffe on 14 Feb 2017, 19:35, edited 5 times in total.

User avatar
toffe
Posts: 671
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe » 08 Mar 2015, 11:20

The library is now updated, can now strip styles,links and colors on the parse() return.
See github for examples.

Toffe

User avatar
toffe
Posts: 671
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe » 23 Mar 2015, 12:38

New version released on github. Has a fix for $h links.

Toffe

User avatar
toffe
Posts: 671
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe » 09 Apr 2015, 21:17

The github master is updated to Swift 1.2 for the new XCode (and Swift) support.
(Build is still failing at travis because of the lack of support for the new xcode at travis).

Toffe

novationx
Posts: 2718
Joined: 10 Aug 2013, 22:33

Re: ManiaPlanet style Swift parser

Post by novationx » 09 Apr 2015, 22:05

great work mate!
Can i ask for what this is used?

Is it to display maniaplanet-nicknames correctly on ios devices?
NADEO y u do diz? :oops: #MP4

User avatar
toffe
Posts: 671
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe » 09 Apr 2015, 22:08

Its used in the ManiaPlanet toolkit app for iOS. To display the server names and the nicknames of the players. Also used for making links, and colors in news items.
And working great. :)

Toffe

User avatar
toffe
Posts: 671
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe » 18 Sep 2015, 10:28

Just updated to Swift 2.0!

Toffe

User avatar
toffe
Posts: 671
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe » 07 Nov 2015, 18:01

Now also supports tvOS.
And added Cocoapods support:



Make sure you got the Podfile header for using Swift code:

Code: Select all

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
Then add the pod

Code: Select all

pod 'MPFormatter', '~> 1.1.1'

User avatar
toffe
Posts: 671
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe » 14 Feb 2017, 19:31

Lib has been converted and updated to support Swift 3!.

1.x.x will only get bugfixes from now.

Post Reply

Return to “General Tools”

Who is online

Users browsing this forum: No registered users and 1 guest