Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Last active September 2, 2016 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odrobnik/417af9fbd8c54d3f722f9dd29841f34a to your computer and use it in GitHub Desktop.
Save odrobnik/417af9fbd8c54d3f722f9dd29841f34a to your computer and use it in GitHub Desktop.
/// The current element attributes state
internal struct TagAttributes
{
var tagName: String!
var URL: NSURL?
var imageURL: NSURL?
var isUnderlined: Bool = false
var isStriken: Bool = false
var color: UIColor?
var fontAttributes: TagFontAttributes!
var textAlignment: NSTextAlignment = .Natural
}
/// A stack of the element attributes
internal var tagAttributesStack = [TagAttributes]()
if var tagAttributes = self.tagAttributesStack.last, let tagName = tagAttributes.tagName where tagName == "img"
{
tagAttributes.imageURL = NSURL(string: string)
// replace the value type with the modified version
self.tagAttributesStack[self.tagAttributesStack.count-1] = tagAttributes
}
@lucianboboc
Copy link

lucianboboc commented Sep 2, 2016

You can have the changed variable inside a box class and it will work:

struct MyStruct {
    var val:String = "initial"
    var boxURL:Box = Box()
}

class Box {
    var url:NSURL = NSURL(string: "http://initial.com")!
}

var a = MyStruct()
var b = a

a.val                 // "initial"
a.boxURL.url   // "http://initial.com"

b.boxURL.url = NSURL(string: "http://changed.com")!

a.val                    // "initial"
a.boxURL.url     // "http://changed.com"

b.val                   // "initial"
b.boxURL.url    // "http://changed.com"

@sanekgusev
Copy link

Wouldn't something like this work?

if let tagAttributes = self.tagAttributesStack.last, let tagName = tagAttributes.tagName where tagName == "img"
{
    self.tagAttributesStack.last?.imageURL = NSURL(string: string)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment